Skip to content

Commit

Permalink
Merge pull request #27 from inloco/feat-feedback-remove-deprecated-fi…
Browse files Browse the repository at this point in the history
…elds

feat!: remove timestamp from register_feedback
  • Loading branch information
ottony authored Nov 12, 2024
2 parents 9d4b3cb + 0d16c5f commit b529743
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 73 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## [Unreleased]

## [1.3.0] - 2024-10-30
## [2.0.0] - 2024-11-12

- Remove support for instance usage of Incognia::Api
- Remove invalid feedback types
- Remove support for sending feedback timestamp

## [1.3.0] - 2024-11-12

- Add support for general configuration and use Incognia::Api as a static class

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
incognia_api (1.3.0)
incognia_api (2.0.0)
faraday (~> 1.10)
faraday_middleware (~> 1.2)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ assessment = Incognia::Api.register_payment(

This method registers a feedback event for the given identifiers (optional arguments), returning true when success.

The `timestamp` argument should be a _Time_, _DateTime_ or an _Integer_ being the timestamp in milliseconds.
The `occurred_at` argument should be a _Time_, _DateTime_ or an date in **RFC 3339** format.

The `expires_at` argument should be a _Time_, _DateTime_ or an date in **RFC 3339** format.

Expand Down
9 changes: 2 additions & 7 deletions lib/incognia_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ def register_login(account_id:, request_token: nil, **opts)
LoginAssessment.from_hash(response.body) if response.success?
end

def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil, **ids)
if !timestamp.nil?
warn("Deprecation warning: use occurred_at instead of timestamp")
end

timestamp = timestamp.strftime('%s%L') if timestamp.respond_to? :strftime
def register_feedback(event:, occurred_at: nil, expires_at: nil, **ids)
occurred_at = occurred_at.to_datetime.rfc3339 if occurred_at.respond_to? :to_datetime
expires_at = expires_at.to_datetime.rfc3339 if expires_at.respond_to? :to_datetime

params = { event: event, timestamp: timestamp&.to_i, occurred_at: occurred_at, expires_at: expires_at }.compact
params = { event: event, occurred_at: occurred_at, expires_at: expires_at }.compact
params.merge!(ids)

response = connection.request(
Expand Down
2 changes: 1 addition & 1 deletion lib/incognia_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Incognia
VERSION = "1.3.0"
VERSION = "2.0.0"
end
82 changes: 20 additions & 62 deletions spec/incognia_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ module Incognia

describe ".register_feedback" do
let(:event) { Incognia::Constants::FeedbackEvent.constants.sample.to_s }
let(:timestamp) { 1655749693000 }
let(:expires_at) { '2024-03-13T10:12:01Z' }
let(:occurred_at) { '2024-03-13T10:12:01Z' }
let(:expires_at) { '2024-03-13T10:12:02Z' }

before do
allow(described_class).to receive(:warn)
Expand All @@ -383,86 +383,46 @@ module Incognia
it "when successful returns true" do
stub_register_feedback_request

feedback_registered = described_class.register_feedback(event: event, timestamp: timestamp)
feedback_registered = described_class.register_feedback(event: event)
expect(feedback_registered).to be(true)
end

it "warns about the deprecation of timestamp" do
stub_register_feedback_request

expect(described_class).to receive(:warn).with("Deprecation warning: use occurred_at instead of timestamp")

described_class.register_feedback(event: event, timestamp: timestamp)
end

context "HTTP request" do
it "hits the endpoint with event, timestamp and expires_at" do
it "hits the endpoint with event, occurred_at and expires_at" do
stub = stub_register_feedback_request
stub.with(
body: { event: event, timestamp: timestamp, expires_at: expires_at },
body: { event: event, occurred_at: occurred_at, expires_at: expires_at },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

described_class.register_feedback(event: event, timestamp: timestamp, expires_at: expires_at)
described_class.register_feedback(event: event, occurred_at: occurred_at, expires_at: expires_at)

expect(stub).to have_been_made.once
end

context "when receiving timestamp as a Time" do
let(:timestamp) { Time.now }

it "hits the endpoint with timestamp in milliseconds" do
stub = stub_register_feedback_request.with(
body: { event: event, timestamp: timestamp.strftime('%s%L').to_i },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

described_class.register_feedback(event: event, timestamp: timestamp)

expect(stub).to have_been_made.once
end
end

context "when receiving timestamp as a DateTime" do
let(:timestamp) { DateTime.now }

it "hits the endpoint with timestamp in milliseconds" do
stub = stub_register_feedback_request.with(
body: { event: event, timestamp: timestamp.strftime('%s%L').to_i },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

described_class.register_feedback(event: event, timestamp: timestamp)

expect(stub).to have_been_made.once
end
end
context "when receiving occurred_at as a Time" do
let(:occurred_at) { Time.now }

context "when not receiving timestamp" do
it "hits the endpoint without timestamp" do
it "hits the endpoint with expires_at in RFC3339" do
stub = stub_register_feedback_request.with(
body: { event: event },
body: { event: event, occurred_at: occurred_at.to_datetime.rfc3339 },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

described_class.register_feedback(event: event)
described_class.register_feedback(event: event, occurred_at: occurred_at)

expect(stub).to have_been_made.once
end
end

context "when receiving occurred_at as a Time" do
let(:occurred_at) { Time.now }
context "when receiving occurred_at as a DateTime" do
let(:occurred_at) { DateTime.now }

it "hits the endpoint with expires_at in RFC3339" do
it "hits the endpoint with occurred_at in RFC3339" do
stub = stub_register_feedback_request.with(
body: { event: event, occurred_at: occurred_at.to_datetime.rfc3339 },
headers: {
Expand All @@ -476,18 +436,16 @@ module Incognia
end
end

context "when receiving occurred_at as a DateTime" do
let(:occurred_at) { DateTime.now }

it "hits the endpoint with occurred_at in RFC3339" do
context "when not receiving occurred_at" do
it "hits the endpoint without occurred_at" do
stub = stub_register_feedback_request.with(
body: { event: event, occurred_at: occurred_at.to_datetime.rfc3339 },
body: { event: event },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

described_class.register_feedback(event: event, occurred_at: occurred_at)
described_class.register_feedback(event: event)

expect(stub).to have_been_made.once
end
Expand Down Expand Up @@ -548,13 +506,13 @@ module Incognia

it "hits the endpoint with #{id_name}" do
stub = stub_register_feedback_request.with(
body: { event: event, timestamp: timestamp, expires_at: expires_at, id_name => id },
body: { event: event, occurred_at: occurred_at, expires_at: expires_at, id_name => id },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

described_class.register_feedback(event: event, timestamp: timestamp, expires_at: expires_at, id_name => id)
described_class.register_feedback(event: event, occurred_at: occurred_at, expires_at: expires_at, id_name => id)

expect(stub).to have_been_made.once
end
Expand Down

0 comments on commit b529743

Please sign in to comment.