Skip to content

Commit da15137

Browse files
authored
Add update_action_state method (#30)
* Add update_action_state method and tests * minor version bump
1 parent 6fa5b4a commit da15137

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
authsignal-ruby (4.0.0)
4+
authsignal-ruby (4.1.0)
55
faraday (>= 2)
66
faraday-retry (~> 2.2)
77

lib/authsignal.rb

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def get_action(user_id:, action:, idempotency_key:)
4949
handle_response(response)
5050
end
5151

52+
def update_action_state(user_id:, action:, idempotency_key:, state:)
53+
# NOTE: Rely on API to respond when given invalid state
54+
response = Client.new.update_action_state(user_id: user_id, action: action, idempotency_key: idempotency_key, state: state)
55+
56+
handle_response(response)
57+
end
58+
5259
def enroll_verified_authenticator(user_id:, authenticator:)
5360
response = Client.new.enroll_verified_authenticator(user_id, authenticator)
5461

lib/authsignal/client.rb

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def get_action(user_id, action, idempotency_key)
7474
make_request(:get, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}")
7575
end
7676

77+
def update_action_state(user_id:, action:, idempotency_key:, state:)
78+
body = { state: state }
79+
make_request(:patch, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}", body: body)
80+
end
81+
7782
##
7883
# TODO: delete identify?
7984
def identify(user_id, user_payload)

lib/authsignal/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Authsignal
4-
VERSION = "4.0.0"
4+
VERSION = "4.1.0"
55
end

spec/authsignal/authsignal_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,34 @@
221221
end
222222
end
223223

224+
describe ".update_action_state" do
225+
let(:user_id) { "100" }
226+
let(:action) { "testAction" }
227+
let(:idempotency_key) { "15cac140-f639-48c5-92db-835ec8d3d144" }
228+
let(:state) { "ALLOW" }
229+
230+
it "succeeds" do
231+
stub_request(:patch, "#{base_uri}/users/#{user_id}/actions/#{action}/#{idempotency_key}")
232+
.with(
233+
basic_auth: ['secret', ''],
234+
headers: { 'Content-Type'=>'application/json' })
235+
.to_return(body: {state: state, ruleIds: [], stateUpdatedAt: "2024-11-01T03:19:00.316Z", createdAt: "2024-11-01T03:19:00.316Z"}.to_json,
236+
status: 200,
237+
headers: {'Content-Type' => 'application/json'})
238+
239+
response = described_class.update_action_state(
240+
user_id: user_id,
241+
action: action,
242+
idempotency_key: idempotency_key,
243+
state: state
244+
)
245+
246+
expect(response[:state]).to eq(state)
247+
expect(response[:state_updated_at]).to eq("2024-11-01T03:19:00.316Z")
248+
expect(response[:success?]).to be true
249+
end
250+
end
251+
224252
describe ".validate_challenge" do
225253
it "Checks that the isValid is true when userId correct" do
226254
stub_request(:post, "#{base_uri}/validate")

0 commit comments

Comments
 (0)