pactas_itero 0.6.0 → 0.8.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 +4 -4
- data/.codeclimate.yml +15 -0
- data/.rubocop.yml +765 -0
- data/CHANGELOG.md +34 -1
- data/Gemfile +3 -1
- data/README.md +3 -1
- data/Rakefile +7 -4
- data/lib/pactas_itero/api/contracts.rb +12 -0
- data/lib/pactas_itero/api/customers.rb +2 -0
- data/lib/pactas_itero/api/invoices.rb +3 -2
- data/lib/pactas_itero/api/oauth.rb +3 -2
- data/lib/pactas_itero/api/orders.rb +2 -0
- data/lib/pactas_itero/api/rated_items.rb +10 -1
- data/lib/pactas_itero/api.rb +9 -7
- data/lib/pactas_itero/client.rb +32 -26
- data/lib/pactas_itero/configurable.rb +9 -8
- data/lib/pactas_itero/default.rb +17 -18
- data/lib/pactas_itero/error.rb +45 -44
- data/lib/pactas_itero/ext/hash/camelize_keys.rb +12 -10
- data/lib/pactas_itero/response/raise_error.rb +5 -5
- data/lib/pactas_itero/version.rb +3 -1
- data/lib/pactas_itero.rb +5 -3
- metadata +16 -83
- data/Gemfile.lock +0 -92
- data/pactas_itero.gemspec +0 -37
- data/spec/fixtures/bearer_token.json +0 -5
- data/spec/fixtures/commit_order_response.json +0 -50
- data/spec/fixtures/contract.json +0 -46
- data/spec/fixtures/contract_cancellation_preview_response.json +0 -73
- data/spec/fixtures/contract_termination_response.json +0 -79
- data/spec/fixtures/contracts.json +0 -48
- data/spec/fixtures/create_order_response.json +0 -17
- data/spec/fixtures/create_rated_item.json +0 -8
- data/spec/fixtures/customer.json +0 -23
- data/spec/fixtures/customers.json +0 -40
- data/spec/fixtures/invoice.json +0 -22
- data/spec/fixtures/invoice_download.pdf +0 -0
- data/spec/fixtures/invoices.json +0 -46
- data/spec/fixtures/order.json +0 -15
- data/spec/fixtures/payment_transaction.json +0 -37
- data/spec/fixtures/rated_items.json +0 -12
- data/spec/fixtures/self_service_token.json +0 -6
- data/spec/pactas_itero/api/contracts_spec.rb +0 -165
- data/spec/pactas_itero/api/customers_spec.rb +0 -229
- data/spec/pactas_itero/api/invoices_spec.rb +0 -103
- data/spec/pactas_itero/api/oauth_spec.rb +0 -44
- data/spec/pactas_itero/api/orders_spec.rb +0 -102
- data/spec/pactas_itero/api/payment_transactions_spec.rb +0 -66
- data/spec/pactas_itero/api/rated_items_spec.rb +0 -113
- data/spec/pactas_itero/client_spec.rb +0 -316
- data/spec/pactas_itero_spec.rb +0 -39
- data/spec/spec_helper.rb +0 -100
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## [UNRELEASED]
|
2
|
-
### Added
|
3
2
|
|
3
|
+
### Added
|
4
4
|
### Changed
|
5
5
|
|
6
6
|
### Deprecated
|
@@ -11,6 +11,39 @@
|
|
11
11
|
|
12
12
|
### Security
|
13
13
|
|
14
|
+
## [0.8.0] - 2022-02-22
|
15
|
+
|
16
|
+
# What's Changed
|
17
|
+
|
18
|
+
## Added
|
19
|
+
|
20
|
+
- Add Metered Usage call by @3wille in https://github.com/shipcloud/billwerk/pull/146
|
21
|
+
|
22
|
+
## Changed
|
23
|
+
|
24
|
+
- Fix current Rubocop Issues by @mortik in https://github.com/shipcloud/billwerk/pull/111
|
25
|
+
- update ruby and introduce standardrb by @3wille in https://github.com/shipcloud/billwerk/pull/147
|
26
|
+
|
27
|
+
**Diff**: https://github.com/shipcloud/billwerk/compare/v0.7.0...v0.8.0
|
28
|
+
|
29
|
+
## [0.7.0] - 2022-02-22
|
30
|
+
|
31
|
+
### Added
|
32
|
+
|
33
|
+
- get contract_changes
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
|
37
|
+
- Set required ruby version to >= 2.6
|
38
|
+
- Replace Travis CI with CircleCI
|
39
|
+
- `rubocop` version is specified to be `~> 1.8.1`
|
40
|
+
- `performance` version is specified to be `~> 1.7.0`
|
41
|
+
|
42
|
+
### Removed
|
43
|
+
|
44
|
+
- Drop support for Ruby <= 2.5
|
45
|
+
- Drop support for JRuby
|
46
|
+
|
14
47
|
## [0.6.0] - 2021-03-03
|
15
48
|
### Changed
|
16
49
|
- `faraday_middleware` version is specified to be `>= 1.0.0`
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
[](https://circleci.com/gh/shipcloud/billwerk/tree/master)
|
2
|
+
[](https://codeclimate.com/github/shipcloud/billwerk/maintainability)
|
3
|
+
[](https://codeclimate.com/github/shipcloud/billwerk/test_coverage)
|
2
4
|
|
3
5
|
# PactasItero
|
4
6
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rspec/core/rake_task"
|
3
5
|
|
4
6
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
5
|
-
spec.pattern = FileList[
|
7
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
6
8
|
end
|
7
9
|
|
10
|
+
desc "start an irb console with pactas_itero required"
|
8
11
|
task :console do
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
+
require "irb"
|
13
|
+
require "irb/completion"
|
14
|
+
require "pactas_itero"
|
12
15
|
ARGV.clear
|
13
16
|
IRB.start
|
14
17
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PactasItero
|
2
4
|
module Api
|
3
5
|
module Contracts
|
@@ -6,6 +8,11 @@ module PactasItero
|
|
6
8
|
get "api/v1/customers/#{customer_id}/contracts", options
|
7
9
|
end
|
8
10
|
|
11
|
+
def contract_changes(contract_id, options = {})
|
12
|
+
options = options.camelize_keys
|
13
|
+
get "api/v1/contractChanges", options.merge(contractId: contract_id)
|
14
|
+
end
|
15
|
+
|
9
16
|
def contracts(options = {})
|
10
17
|
options = options.camelize_keys
|
11
18
|
get "api/v1/contracts", options
|
@@ -35,6 +42,11 @@ module PactasItero
|
|
35
42
|
options = options.camelize_keys
|
36
43
|
post "api/v1/contracts/#{contract_id}/end", options
|
37
44
|
end
|
45
|
+
|
46
|
+
def contract_metered_usage(contract_id, options = {})
|
47
|
+
options = options.camelize_keys
|
48
|
+
post "api/v1/contracts/#{contract_id}/usage", options
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
40
52
|
end
|
@@ -1,13 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PactasItero
|
2
4
|
module Api
|
3
5
|
module Invoices
|
4
|
-
|
5
6
|
def invoices(options = {})
|
6
7
|
options = options.camelize_keys
|
7
8
|
get "api/v1/invoices", options
|
8
9
|
end
|
9
10
|
|
10
|
-
def invoices_from(from_id=nil, options = {})
|
11
|
+
def invoices_from(from_id = nil, options = {})
|
11
12
|
if from_id
|
12
13
|
options = options.camelize_keys
|
13
14
|
get "api/v1/invoices?from=#{from_id}", options
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module PactasItero
|
3
4
|
module Api
|
4
5
|
module OAuth
|
5
6
|
def token(options = {})
|
6
7
|
options[:bearer_token_request] = true
|
7
|
-
options[:grant_type] ||=
|
8
|
-
post
|
8
|
+
options[:grant_type] ||= "client_credentials"
|
9
|
+
post "/oauth/token", options
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -1,7 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PactasItero
|
2
4
|
module Api
|
3
5
|
module RatedItems
|
4
|
-
def create_rated_item(
|
6
|
+
def create_rated_item(
|
7
|
+
contract_id,
|
8
|
+
quantity,
|
9
|
+
description,
|
10
|
+
price_per_unit,
|
11
|
+
tax_policy_id,
|
12
|
+
options = {}
|
13
|
+
)
|
5
14
|
options.merge!(
|
6
15
|
quantity: quantity,
|
7
16
|
description: description,
|
data/lib/pactas_itero/api.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pactas_itero/ext/hash/camelize_keys"
|
4
|
+
require "pactas_itero/api/oauth"
|
5
|
+
require "pactas_itero/api/rated_items"
|
6
|
+
require "pactas_itero/api/customers"
|
7
|
+
require "pactas_itero/api/contracts"
|
8
|
+
require "pactas_itero/api/orders"
|
9
|
+
require "pactas_itero/api/invoices"
|
8
10
|
require "pactas_itero/api/payment_transactions"
|
9
11
|
|
10
12
|
module PactasItero
|
data/lib/pactas_itero/client.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
require "rash"
|
5
|
+
require "pactas_itero/configurable"
|
6
|
+
require "pactas_itero/api"
|
5
7
|
|
6
8
|
module PactasItero
|
7
9
|
class Client
|
@@ -12,7 +14,10 @@ module PactasItero
|
|
12
14
|
|
13
15
|
def initialize(options = {})
|
14
16
|
PactasItero::Configurable.keys.each do |key|
|
15
|
-
instance_variable_set(
|
17
|
+
instance_variable_set(
|
18
|
+
:"@#{key}",
|
19
|
+
options[key] || PactasItero.instance_variable_get(:"@#{key}")
|
20
|
+
)
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
@@ -47,42 +52,42 @@ module PactasItero
|
|
47
52
|
private
|
48
53
|
|
49
54
|
def connection
|
50
|
-
@
|
55
|
+
@_connection ||= Faraday.new(api_endpoint, connection_options)
|
51
56
|
end
|
52
57
|
|
53
58
|
def request(method, path, params = {})
|
54
59
|
headers = params.delete(:headers) || {}
|
55
|
-
if accept = params.delete(:accept)
|
60
|
+
if (accept = params.delete(:accept))
|
56
61
|
headers[:accept] = accept
|
57
62
|
end
|
58
63
|
|
59
64
|
bearer_token_request = params.delete(:bearer_token_request)
|
60
65
|
|
61
66
|
if bearer_token_request
|
62
|
-
headers[:accept]
|
67
|
+
headers[:accept] = "*/*"
|
63
68
|
headers[:authorization] = bearer_token_credentials_auth_header
|
64
|
-
headers[:content_type]
|
69
|
+
headers[:content_type] = "application/x-www-form-urlencoded; charset=UTF-8"
|
65
70
|
else
|
66
71
|
headers[:authorization] = auth_header
|
67
72
|
end
|
68
73
|
|
69
|
-
response = connection.send(method.to_sym, path, params)
|
70
|
-
|
71
|
-
|
74
|
+
response = connection.send(method.to_sym, path, params) do |request|
|
75
|
+
request.headers.update(headers)
|
76
|
+
end.env
|
72
77
|
response.body
|
73
78
|
end
|
74
79
|
|
75
80
|
def connection_options
|
76
|
-
@
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
},
|
82
|
-
:request => {
|
83
|
-
:open_timeout => 10,
|
84
|
-
:timeout => 30,
|
81
|
+
@_connection_options ||= {
|
82
|
+
builder: middleware,
|
83
|
+
headers: {
|
84
|
+
accept: default_media_type,
|
85
|
+
user_agent: user_agent
|
85
86
|
},
|
87
|
+
request: {
|
88
|
+
open_timeout: 10,
|
89
|
+
timeout: 30
|
90
|
+
}
|
86
91
|
}
|
87
92
|
end
|
88
93
|
|
@@ -92,11 +97,12 @@ module PactasItero
|
|
92
97
|
end
|
93
98
|
|
94
99
|
def bearer_auth_header
|
95
|
-
token =
|
96
|
-
bearer_token.access_token
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
+
token =
|
101
|
+
if bearer_token.respond_to?(:access_token)
|
102
|
+
bearer_token.access_token
|
103
|
+
else
|
104
|
+
bearer_token
|
105
|
+
end
|
100
106
|
"Bearer #{token}"
|
101
107
|
end
|
102
108
|
|
@@ -1,14 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module PactasItero
|
3
4
|
module Configurable
|
4
5
|
attr_accessor :bearer_token, :client_id, :client_secret, :user_agent,
|
5
|
-
|
6
|
+
:default_media_type, :middleware, :production
|
6
7
|
attr_writer :api_endpoint
|
7
|
-
class << self
|
8
8
|
|
9
|
+
class << self
|
9
10
|
# List of configurable keys for PactasItero::Client
|
10
11
|
def keys
|
11
|
-
@
|
12
|
+
@_keys ||= [
|
12
13
|
:bearer_token,
|
13
14
|
:api_endpoint,
|
14
15
|
:client_id,
|
@@ -33,12 +34,12 @@ module PactasItero
|
|
33
34
|
end
|
34
35
|
self
|
35
36
|
end
|
36
|
-
|
37
|
+
alias_method :setup, :reset!
|
37
38
|
|
38
39
|
def api_endpoint
|
39
40
|
endpoint = @api_endpoint ||
|
40
|
-
|
41
|
-
|
41
|
+
(production && production_api_endpoint) ||
|
42
|
+
sandbox_api_endpoint
|
42
43
|
File.join(endpoint, "")
|
43
44
|
end
|
44
45
|
|
@@ -53,7 +54,7 @@ module PactasItero
|
|
53
54
|
private
|
54
55
|
|
55
56
|
def options
|
56
|
-
|
57
|
+
PactasItero::Configurable.keys.to_h { |key| [key, send(:"#{key}")] }
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
data/lib/pactas_itero/default.rb
CHANGED
@@ -1,40 +1,39 @@
|
|
1
|
-
|
2
|
-
require 'pactas_itero/version'
|
3
|
-
require 'faraday_middleware'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
require "pactas_itero/response/raise_error"
|
4
|
+
require "pactas_itero/version"
|
5
|
+
require "faraday_middleware"
|
6
6
|
|
7
|
+
module PactasItero
|
7
8
|
# Default configuration options for {Client}
|
8
9
|
module Default
|
10
|
+
SANDBOX_API_ENDPOINT = "https://sandbox.billwerk.com"
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
PRODUCTION_API_ENDPOINT = "https://app.billwerk.com".freeze
|
12
|
+
PRODUCTION_API_ENDPOINT = "https://app.billwerk.com"
|
13
13
|
|
14
14
|
PRODUCTION = false
|
15
15
|
|
16
|
-
USER_AGENT
|
16
|
+
USER_AGENT = "Pactas.Itero Ruby Gem #{PactasItero::VERSION}"
|
17
17
|
|
18
|
-
MEDIA_TYPE
|
18
|
+
MEDIA_TYPE = "application/json"
|
19
19
|
|
20
20
|
MIDDLEWARE = Faraday::RackBuilder.new do |builder|
|
21
21
|
builder.request :json
|
22
22
|
builder.use PactasItero::Response::RaiseError
|
23
23
|
builder.response :rashify
|
24
24
|
builder.request :url_encoded
|
25
|
-
builder.response :json, :
|
25
|
+
builder.response :json, content_type: /\bjson$/
|
26
26
|
|
27
27
|
builder.adapter Faraday.default_adapter
|
28
28
|
end
|
29
29
|
|
30
30
|
class << self
|
31
|
-
|
32
31
|
def options
|
33
|
-
|
32
|
+
PactasItero::Configurable.keys.to_h { |key| [key, send(key)] }
|
34
33
|
end
|
35
34
|
|
36
35
|
def api_endpoint
|
37
|
-
ENV[
|
36
|
+
ENV["PACTAS_ITERO_ENDPOINT"]
|
38
37
|
end
|
39
38
|
|
40
39
|
def sandbox_api_endpoint
|
@@ -50,19 +49,19 @@ module PactasItero
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def client_id
|
53
|
-
ENV[
|
52
|
+
ENV["PACTAS_ITERO_CLIENT_ID"]
|
54
53
|
end
|
55
54
|
|
56
55
|
def client_secret
|
57
|
-
ENV[
|
56
|
+
ENV["PACTAS_ITERO_CLIENT_SECRET"]
|
58
57
|
end
|
59
58
|
|
60
59
|
def bearer_token
|
61
|
-
ENV[
|
60
|
+
ENV["PACTAS_ITERO_BEARER_TOKEN"]
|
62
61
|
end
|
63
62
|
|
64
63
|
def default_media_type
|
65
|
-
ENV[
|
64
|
+
ENV["PACTAS_ITERO_CLIENT_DEFAULT_MEDIA_TYPE"] || MEDIA_TYPE
|
66
65
|
end
|
67
66
|
|
68
67
|
def middleware
|
@@ -70,7 +69,7 @@ module PactasItero
|
|
70
69
|
end
|
71
70
|
|
72
71
|
def user_agent
|
73
|
-
ENV[
|
72
|
+
ENV["PACTAS_ITERO_USER_AGENT"] || USER_AGENT
|
74
73
|
end
|
75
74
|
end
|
76
75
|
end
|
data/lib/pactas_itero/error.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PactasItero
|
2
4
|
# Custom error class for rescuing from all Pactas errors
|
3
5
|
class Error < StandardError
|
4
|
-
|
5
6
|
# Returns the appropriate PactasItero::Error sublcass based
|
6
7
|
# on status and response message
|
7
8
|
#
|
8
9
|
# @param [Hash] response HTTP response
|
9
10
|
# @return [PactasItero::Error]
|
10
11
|
def self.from_response(response)
|
11
|
-
status
|
12
|
-
body
|
12
|
+
status = response[:status].to_i
|
13
|
+
body = response[:body].to_s
|
13
14
|
headers = response[:response_headers]
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
klass.new(response)
|
16
|
+
klass = case status
|
17
|
+
when 400 then PactasItero::BadRequest
|
18
|
+
when 401 then error_for401(headers)
|
19
|
+
when 403 then error_for403(body)
|
20
|
+
when 404 then PactasItero::NotFound
|
21
|
+
when 406 then PactasItero::NotAcceptable
|
22
|
+
when 409 then PactasItero::Conflict
|
23
|
+
when 415 then PactasItero::UnsupportedMediaType
|
24
|
+
when 422 then PactasItero::UnprocessableEntity
|
25
|
+
when 400..499 then PactasItero::ClientError
|
26
|
+
when 500 then PactasItero::InternalServerError
|
27
|
+
when 501 then PactasItero::NotImplemented
|
28
|
+
when 502 then PactasItero::BadGateway
|
29
|
+
when 503 then PactasItero::ServiceUnavailable
|
30
|
+
when 500..599 then PactasItero::ServerError
|
32
31
|
end
|
32
|
+
klass&.new(response)
|
33
33
|
end
|
34
34
|
|
35
|
-
def initialize(response=nil)
|
35
|
+
def initialize(response = nil)
|
36
36
|
@response = response
|
37
37
|
super(build_error_message)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns most appropriate error for 401 HTTP status code
|
41
41
|
# @private
|
42
|
-
def self.
|
42
|
+
def self.error_for401(headers)
|
43
43
|
if PactasItero::OneTimePasswordRequired.required_header(headers)
|
44
44
|
PactasItero::OneTimePasswordRequired
|
45
45
|
else
|
@@ -49,10 +49,11 @@ module PactasItero
|
|
49
49
|
|
50
50
|
# Returns most appropriate error for 403 HTTP status code
|
51
51
|
# @private
|
52
|
-
def self.
|
53
|
-
|
52
|
+
def self.error_for403(body)
|
53
|
+
case body
|
54
|
+
when /rate limit exceeded/i
|
54
55
|
PactasItero::TooManyRequests
|
55
|
-
|
56
|
+
when /login attempts exceeded/i
|
56
57
|
PactasItero::TooManyLoginAttempts
|
57
58
|
else
|
58
59
|
PactasItero::Forbidden
|
@@ -62,7 +63,7 @@ module PactasItero
|
|
62
63
|
# Array of validation errors
|
63
64
|
# @return [Array<Hash>] Error info
|
64
65
|
def errors
|
65
|
-
if data
|
66
|
+
if data.is_a?(Hash)
|
66
67
|
data[:errors] || []
|
67
68
|
else
|
68
69
|
[]
|
@@ -72,18 +73,16 @@ module PactasItero
|
|
72
73
|
private
|
73
74
|
|
74
75
|
def data
|
75
|
-
@
|
76
|
+
@_data ||=
|
76
77
|
if (body = @response[:body]) && !body.empty?
|
77
78
|
if body.is_a?(String) &&
|
78
|
-
|
79
|
-
|
79
|
+
@response[:response_headers] &&
|
80
|
+
@response[:response_headers][:content_type].include?("json")
|
80
81
|
|
81
82
|
Sawyer::Agent.serializer.decode(body)
|
82
83
|
else
|
83
84
|
body
|
84
85
|
end
|
85
|
-
else
|
86
|
-
nil
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
@@ -105,7 +104,7 @@ module PactasItero
|
|
105
104
|
|
106
105
|
summary = "\nError summary:\n"
|
107
106
|
summary << data[:errors].map do |hash|
|
108
|
-
hash.map { |k,v| " #{k}: #{v}" }
|
107
|
+
hash.map { |k, v| " #{k}: #{v}" }
|
109
108
|
end.join("\n")
|
110
109
|
|
111
110
|
summary
|
@@ -114,19 +113,21 @@ module PactasItero
|
|
114
113
|
def build_error_message
|
115
114
|
return nil if @response.nil?
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
116
|
+
[
|
117
|
+
"#{@response[:method].to_s.upcase} ",
|
118
|
+
"#{redact_url(@response[:url].to_s)}: ",
|
119
|
+
"#{@response[:status]} - ",
|
120
|
+
(response_message.to_s unless response_message.nil?),
|
121
|
+
(response_error.to_s unless response_error.nil?),
|
122
|
+
(response_error_summary.to_s unless response_error_summary.nil?)
|
123
|
+
].compact.join
|
124
124
|
end
|
125
125
|
|
126
126
|
def redact_url(url_string)
|
127
127
|
%w[client_secret access_token].each do |token|
|
128
128
|
url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include? token
|
129
129
|
end
|
130
|
+
|
130
131
|
url_string
|
131
132
|
end
|
132
133
|
end
|
@@ -143,25 +144,25 @@ module PactasItero
|
|
143
144
|
# Raised when Pactas returns a 401 HTTP status code
|
144
145
|
# and headers include "X-Pactas-OTP"
|
145
146
|
class OneTimePasswordRequired < ClientError
|
146
|
-
|
147
|
+
# @private
|
147
148
|
OTP_DELIVERY_PATTERN = /required; (\w+)/i
|
148
149
|
|
149
|
-
|
150
|
+
# @private
|
150
151
|
def self.required_header(headers)
|
151
|
-
OTP_DELIVERY_PATTERN.match headers[
|
152
|
+
OTP_DELIVERY_PATTERN.match headers["X-Pactas-OTP"].to_s
|
152
153
|
end
|
153
154
|
|
154
155
|
# Delivery method for the user's OTP
|
155
156
|
#
|
156
157
|
# @return [String]
|
157
158
|
def password_delivery
|
158
|
-
@
|
159
|
+
@_password_delivery ||= delivery_method_from_header
|
159
160
|
end
|
160
161
|
|
161
162
|
private
|
162
163
|
|
163
164
|
def delivery_method_from_header
|
164
|
-
if match = self.class.required_header(@response[:response_headers])
|
165
|
+
if (match = self.class.required_header(@response[:response_headers]))
|
165
166
|
match[1]
|
166
167
|
end
|
167
168
|
end
|
@@ -1,22 +1,24 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
class Hash
|
3
4
|
def camelize_keys(value = self)
|
4
5
|
case value
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
when Array
|
7
|
+
value.map { |v| camelize_keys(v) }
|
8
|
+
when Hash
|
9
|
+
value.to_h { |k, v| [camelize_key(k), camelize_keys(v)] }
|
10
|
+
else
|
11
|
+
value
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
15
16
|
|
16
17
|
def camelize_key(key)
|
17
|
-
|
18
|
+
case key
|
19
|
+
when Symbol
|
18
20
|
camelize(key.to_s).to_sym
|
19
|
-
|
21
|
+
when String
|
20
22
|
camelize(key)
|
21
23
|
else
|
22
24
|
key
|
@@ -27,6 +29,6 @@ class Hash
|
|
27
29
|
def camelize(term)
|
28
30
|
string = term.to_s
|
29
31
|
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
30
|
-
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub(
|
32
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
31
33
|
end
|
32
34
|
end
|