authsignal-ruby 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '05993f5ac8d8569efae1a1c17692b90216c135675c922a4ef727124ba4774b5c'
4
- data.tar.gz: 7f1816f80f7bf7517fda22b2f5d2cc0ad9895431031b06e0dfdf52dc4065c355
3
+ metadata.gz: 75bf7679eabfb897458c92a7b284ff2cdd1ea7eb833275e14c1c01c47de3ea89
4
+ data.tar.gz: 4a94529da1d514caa69e4498f68d19006a3fd09be8d094be463aa33b9bc5e4d9
5
5
  SHA512:
6
- metadata.gz: eb669c48e8fcb98f9241b0cde59c9aba13b4f1991f83f2e6ca0b127338af6d31c123cac2d3a9dec0cafc19142fb0fe9c5a212f792fb2c5655f22d13757f1dee6
7
- data.tar.gz: 1e2622b946b9979010eb0f34a7de0b76eda3197242d441807b1bde5a038fe6cbd6a70a9e94ef54cdad4c23d1298f5d49f3f3a6ec2a11bd47a594775467c48342
6
+ metadata.gz: c12dd82892ca7c69bf2ec0e981a1ff5276e5f0fca37e6ae173ef385af63649a322b8cdc96d3e39b7d13eea7494bba97c15c234251838e092f816aed7ecaefd20
7
+ data.tar.gz: e263f4d2eaa242a23e3aafce95ea7b1db01011d33c51b45b9c655b5e184b39ddf51a4e29d2a8b5b0e6684bd2f2e8b87e110d3848819fc89dc09076bf8e4e2147
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authsignal-ruby (4.0.0)
4
+ authsignal-ruby (5.0.0)
5
5
  faraday (>= 2)
6
6
  faraday-retry (~> 2.2)
7
7
 
data/README.md CHANGED
@@ -32,22 +32,22 @@ end
32
32
 
33
33
  You can find your `api_secret_key` in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api).
34
34
 
35
- You must specify the correct `baseUrl` for your tenant's region.
35
+ You must specify the correct `api_url` for your tenant's region.
36
36
 
37
- | Region | Base URL |
37
+ | Region | API URL |
38
38
  | ----------- | ----------------------------------- |
39
39
  | US (Oregon) | https://signal.authsignal.com/v1 |
40
40
  | AU (Sydney) | https://au.signal.authsignal.com/v1 |
41
41
  | EU (Dublin) | https://eu.signal.authsignal.com/v1 |
42
42
 
43
- For example, to set the base URL to use our AU region:
43
+ For example, to set the API URL to use our AU region:
44
44
 
45
45
  ```
46
46
  require 'authsignal'
47
47
 
48
48
  Authsignal.setup do |config|
49
49
  config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
50
- config.base_uri = "https://au.signal.authsignal.com/v1"
50
+ config.api_url = "https://au.signal.authsignal.com/v1"
51
51
 
52
52
  # If you would like the Authsignal client to retry requests due to network issues
53
53
  config.retry = true # default value: false
@@ -92,8 +92,8 @@ Authsignal.enroll_verified_authenticator user_id: 'AS_001',
92
92
  # returns:
93
93
  # {
94
94
  # success?: false,
95
- # status: 400,
96
- # error: 'invalid_request',
95
+ # status_code: 400,
96
+ # error_code: 'invalid_request',
97
97
  # error_description: '/body/oobChannel must be equal to one of the allowed values'
98
98
  # }
99
99
  ```
@@ -109,7 +109,7 @@ Authsignal.enroll_verified_authenticator! user_id: 'AS_001',
109
109
  }
110
110
 
111
111
  # raise:
112
- # <Authsignal::ApiError: invalid_request status: 400, error: invalid_request, description: /body/oobChannel must be equal to one o...
112
+ # <Authsignal::ApiError: AuthsignalError: 400 - /body/oobChannel must be equal to one of the allowed values. status_code: 401, error_code: invalid_request, error_description: /body/oobChannel must be equal to one of the allowed values.
113
113
  ```
114
114
 
115
115
  ## Development
@@ -2,18 +2,30 @@
2
2
 
3
3
  module Authsignal
4
4
  class ApiError < StandardError
5
- attr_reader :status, :error, :description
5
+ attr_reader :status_code, :error_code, :error_description
6
6
 
7
- def initialize(message = "An unexpected API error occurred", status, error, description)
8
- @status = status || 500
9
- @error = error
10
- @description = description
7
+ def initialize(status_code, error_code, error_description = nil)
8
+ message = format_message(status_code, error_code, error_description)
11
9
 
12
10
  super(message)
11
+
12
+ @status_code = status_code
13
+ @error_code = error_code
14
+ @error_description = error_description
13
15
  end
14
16
 
15
17
  def to_s
16
- "#{super} status: #{status}, error: #{error}, description: #{description}"
18
+ "#{super} status_code: #{status_code}, error_code: #{error_code}, error_description: #{error_description}"
19
+ end
20
+
21
+ private
22
+
23
+ def format_message(status_code, error_code, error_description)
24
+ "AuthsignalError: #{status_code} - #{format_description(error_code, error_description)}"
25
+ end
26
+
27
+ def format_description(error_code, error_description)
28
+ error_description && error_description.length > 0 ? error_description : error_code
17
29
  end
18
30
  end
19
31
  end
@@ -17,7 +17,7 @@ module Authsignal
17
17
  @api_key = require_api_key
18
18
 
19
19
  @client = Faraday.new do |builder|
20
- builder.url_prefix = Authsignal.configuration.base_uri
20
+ builder.url_prefix = Authsignal.configuration.api_url
21
21
  builder.adapter :net_http
22
22
  builder.request :authorization, :basic, @api_key, nil
23
23
 
@@ -36,58 +36,58 @@ module Authsignal
36
36
  end
37
37
  end
38
38
 
39
- def track(event)
40
- user_id = url_encode(event[:user_id])
41
- action = event[:action]
39
+ def get_user(user_id:)
40
+ path = "users/#{url_encode(user_id)}"
41
+ make_request(:get, path)
42
+ end
42
43
 
43
- path = "users/#{user_id}/actions/#{action}"
44
- body = event.except(:user_id)
44
+ def update_user(user_id:, attributes:)
45
+ make_request(:post, "users/#{url_encode(user_id)}", body: attributes)
46
+ end
45
47
 
46
- make_request(:post, path, body: body)
48
+ def delete_user(user_id:)
49
+ make_request(:delete, "users/#{url_encode(user_id)}")
47
50
  end
48
51
 
49
- def get_user(user_id:, redirect_url: nil)
50
- if(redirect_url)
51
- path = "users/#{url_encode(user_id)}?redirectUrl=#{redirect_url}"
52
- else
53
- path = "users/#{url_encode(user_id)}"
54
- end
55
- make_request(:get, path)
52
+ def get_authenticators(user_id:)
53
+ make_request(:get, "users/#{url_encode(user_id)}/authenticators")
56
54
  end
57
55
 
58
- def update_user(user_id:, user:)
59
- make_request(:post, "users/#{url_encode(user_id)}", body: user)
56
+ def enroll_verified_authenticator(user_id:, attributes:)
57
+ make_request(:post, "users/#{url_encode(user_id)}/authenticators", body: attributes)
60
58
  end
61
59
 
62
- def delete_user(user_id:)
63
- make_request(:delete, "users/#{url_encode(user_id)}")
60
+ def delete_authenticator(user_id:, user_authenticator_id:)
61
+ make_request(:delete, "users/#{url_encode(user_id)}/authenticators/#{url_encode(user_authenticator_id)}")
64
62
  end
65
63
 
66
- def validate_challenge(user_id: nil, token:, action: nil)
64
+ def track(user_id:, action:, attributes:)
65
+ path = "users/#{user_id}/actions/#{action}"
66
+
67
+ make_request(:post, path, body: attributes)
68
+ end
69
+
70
+ def validate_challenge(token:, user_id: nil, action: nil)
67
71
  path = "validate"
68
72
  body = { user_id: user_id, token: token, action: action }
69
73
 
70
74
  make_request(:post, path, body: body)
71
75
  end
72
76
 
73
- def get_action(user_id, action, idempotency_key)
77
+ def get_action(user_id:, action:, idempotency_key:)
74
78
  make_request(:get, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}")
75
79
  end
76
80
 
81
+ def update_action(user_id:, action:, idempotency_key:, attributes:)
82
+ make_request(:patch, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}", body: attributes)
83
+ end
84
+
77
85
  ##
78
86
  # TODO: delete identify?
79
87
  def identify(user_id, user_payload)
80
88
  make_request(:post , "users/#{url_encode(user_id)}", body: user_payload)
81
89
  end
82
90
 
83
- def enroll_verified_authenticator(user_id, authenticator)
84
- make_request(:post, "users/#{url_encode(user_id)}/authenticators", body: authenticator)
85
- end
86
-
87
- def delete_authenticator(user_id:, user_authenticator_id:)
88
- make_request(:delete, "users/#{url_encode(user_id)}/authenticators/#{url_encode(user_authenticator_id)}")
89
- end
90
-
91
91
  private
92
92
 
93
93
  def url_encode(s)
@@ -13,7 +13,7 @@ module Authsignal
13
13
  end
14
14
 
15
15
  config_option :api_secret_key
16
- config_option :base_uri
16
+ config_option :api_url
17
17
  config_option :debug
18
18
  config_option :retry
19
19
 
@@ -22,7 +22,7 @@ module Authsignal
22
22
 
23
23
  # set default attribute values
24
24
  @defaults = OpenStruct.new({
25
- base_uri: 'https://signal.authsignal.com/v1/',
25
+ api_url: 'https://signal.authsignal.com/v1/',
26
26
  retry: false,
27
27
  debug: false
28
28
  })
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authsignal
4
- VERSION = "4.0.0"
4
+ VERSION = "5.0.0"
5
5
  end
data/lib/authsignal.rb CHANGED
@@ -25,14 +25,14 @@ module Authsignal
25
25
  configuration.defaults
26
26
  end
27
27
 
28
- def get_user(user_id:, redirect_url: nil)
29
- response = Client.new.get_user(user_id: user_id, redirect_url: redirect_url)
28
+ def get_user(user_id:)
29
+ response = Client.new.get_user(user_id: user_id)
30
30
 
31
31
  handle_response(response)
32
32
  end
33
33
 
34
- def update_user(user_id:, user:)
35
- response = Client.new.update_user(user_id: user_id, user: user)
34
+ def update_user(user_id:, attributes:)
35
+ response = Client.new.update_user(user_id: user_id, attributes: attributes)
36
36
 
37
37
  handle_response(response)
38
38
  end
@@ -43,38 +43,47 @@ module Authsignal
43
43
  handle_response(response)
44
44
  end
45
45
 
46
- def get_action(user_id:, action:, idempotency_key:)
47
- response = Client.new.get_action(user_id, action, idempotency_key)
46
+ def get_authenticators(user_id:)
47
+ response = Client.new.get_authenticators(user_id: user_id)
48
48
 
49
49
  handle_response(response)
50
50
  end
51
51
 
52
- def enroll_verified_authenticator(user_id:, authenticator:)
53
- response = Client.new.enroll_verified_authenticator(user_id, authenticator)
52
+ def enroll_verified_authenticator(user_id:, attributes:)
53
+ response = Client.new.enroll_verified_authenticator(user_id: user_id, attributes: attributes)
54
54
 
55
55
  handle_response(response)
56
56
  end
57
57
 
58
- def delete_authenticator(user_id:, user_authenticator_id: )
58
+ def delete_authenticator(user_id:, user_authenticator_id:)
59
59
  response = Client.new.delete_authenticator(user_id: user_id, user_authenticator_id: user_authenticator_id)
60
60
 
61
61
  handle_response(response)
62
62
  end
63
63
 
64
- def track(event, options={})
65
- raise ArgumentError, "Action Code is required" unless event[:action].to_s.length > 0
66
- raise ArgumentError, "User ID value" unless event[:user_id].to_s.length > 0
67
-
68
- response = Client.new.track(event)
64
+ def track(user_id:, action:, attributes:)
65
+ response = Client.new.track(user_id: user_id, action: action, attributes: attributes)
69
66
  handle_response(response)
70
67
  end
71
68
 
72
69
  def validate_challenge(token:, user_id: nil, action: nil)
73
- response = Client.new.validate_challenge(user_id: user_id, token: token, action: action)
70
+ response = Client.new.validate_challenge(token: token,user_id: user_id, action: action)
74
71
 
75
72
  handle_response(response)
76
73
  end
77
74
 
75
+ def get_action(user_id:, action:, idempotency_key:)
76
+ response = Client.new.get_action(user_id: user_id, action: action, idempotency_key: idempotency_key)
77
+
78
+ handle_response(response)
79
+ end
80
+
81
+ def update_action(user_id:, action:, idempotency_key:, attributes:)
82
+ response = Client.new.update_action(user_id: user_id, action: action, idempotency_key: idempotency_key, attributes: attributes)
83
+
84
+ handle_response(response)
85
+ end
86
+
78
87
  private
79
88
 
80
89
  def handle_response(response)
@@ -86,15 +95,19 @@ module Authsignal
86
95
  end
87
96
 
88
97
  def handle_success_response(response)
89
- response.body.merge(success?: true)
98
+ if response.body.is_a?(Array)
99
+ { success?: true, data: response.body }
100
+ else
101
+ response.body.merge(success?: true)
102
+ end
90
103
  end
91
104
 
92
105
  def handle_error_response(response)
93
106
  case response.body
94
107
  when Hash
95
- response.body.merge(status: response.status, success?: false)
108
+ { status_code: response.status, success?: false, error_code: response.body[:error], error_description: response.body[:error_description] }
96
109
  else
97
- { status: response&.status || 500, success?: false }
110
+ { status_code: response&.status || 500, success?: false }
98
111
  end
99
112
  end
100
113
  end
@@ -103,11 +116,11 @@ module Authsignal
103
116
  (methods - NON_API_METHODS).each do |method|
104
117
  define_singleton_method("#{method}!") do |*args, **kwargs|
105
118
  send(method, *args, **kwargs).tap do |response|
106
- status = response[:status]
107
- err = response[:error]
108
- desc = response[:error_description]
119
+ status_code = response[:status_code]
120
+ error_code = response[:error_code]
121
+ error_description = response[:error_description]
109
122
 
110
- raise ApiError.new(err, status, err, desc) unless response[:success?]
123
+ raise ApiError.new(status_code, error_code, error_description) unless response[:success?]
111
124
  end
112
125
  end
113
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authsignal-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - justinsoong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-25 00:00:00.000000000 Z
11
+ date: 2024-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
130
- rubygems_version: 3.5.16
130
+ rubygems_version: 3.5.22
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: The Authsignal ruby server side signal API.