Skip to content

Commit

Permalink
Merge pull request #20 from inloco/feat/add-ttl-param-to-register-fee…
Browse files Browse the repository at this point in the history
…dback

Feat: Add expires_at param to register feedback
  • Loading branch information
lucaswilliamgomes authored Mar 19, 2024
2 parents 8b46cbd + 6481dda commit f793e5d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [0.5.4] - 2024-03-19

- Allow registering feedback with expires_at parameter

## [0.5.1] - 2023-07-13

- Allow registering payments
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ assessment = 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 `timestamp` argument should be a _Time_, _DateTime_ or an _Integer_ being the timestamp in milliseconds.

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


```ruby
account_id = "cdb2cfbb-8ad8-4668-b276-5fff9bbfdc96"
Expand Down
21 changes: 11 additions & 10 deletions lib/incognia_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(client_id:, client_secret:)
host: "https://api.incognia.com/api")
end

def register_signup(installation_id:, address: nil, **opts)
def register_signup(installation_id:, address: nil, **opts)
params = { installation_id: installation_id }
params.merge!(opts)
params.merge!(address&.to_hash) if address
Expand All @@ -38,13 +38,13 @@ def get_signup_assessment(signup_id:)
SignupAssessment.from_hash(response.body) if response.success?
end

def register_login(installation_id:, account_id:, **opts)
params = {
type: :login,
installation_id: installation_id,
account_id: account_id,
}
params.merge!(opts)
def register_login(installation_id:, account_id:, **opts)
params = {
type: :login,
installation_id: installation_id,
account_id: account_id,
}
params.merge!(opts)

response = connection.request(
:post,
Expand All @@ -55,10 +55,11 @@ def register_login(installation_id:, account_id:, **opts)
LoginAssessment.from_hash(response.body) if response.success?
end

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

params = { event: event, timestamp: timestamp&.to_i }.compact
params = { event: event, timestamp: timestamp&.to_i, 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 = "0.5.3"
VERSION = "0.5.4"
end
61 changes: 56 additions & 5 deletions spec/incognia_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ 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' }

before { stub_token_request }

Expand All @@ -368,16 +369,16 @@ module Incognia
end

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

api.register_feedback(event: event, timestamp: timestamp)
api.register_feedback(event: event, timestamp: timestamp, expires_at: expires_at)

expect(stub).to have_been_made.once
end
Expand Down Expand Up @@ -431,19 +432,68 @@ module Incognia
end
end

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

it "hits the endpoint with expires_at in RFC3339" do
stub = stub_register_feedback_request.with(
body: { event: event, expires_at: expires_at.strftime('%FT%TZ') },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

api.register_feedback(event: event, expires_at: expires_at)

expect(stub).to have_been_made.once
end
end

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

it "hits the endpoint with expires_at in RFC3339" do
stub = stub_register_feedback_request.with(
body: { event: event, expires_at: expires_at.strftime('%FT%TZ') },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

api.register_feedback(event: event, expires_at: expires_at)

expect(stub).to have_been_made.once
end
end

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

api.register_feedback(event: event)

expect(stub).to have_been_made.once
end
end

context "when receiving ids" do
shared_examples_for "receiving ids" do |id_name|
let(:id) { SecureRandom.uuid }

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

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

expect(stub).to have_been_made.once
end
Expand All @@ -455,6 +505,7 @@ module Incognia
it_behaves_like 'receiving ids', :signup_id
it_behaves_like 'receiving ids', :login_id
it_behaves_like 'receiving ids', :payment_id
it_behaves_like 'receiving ids', :session_token
end
end
end
Expand Down

0 comments on commit f793e5d

Please sign in to comment.