pactas_itero 0.3.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +36 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +89 -42
- data/README.md +3 -1
- data/Rakefile +4 -4
- data/bin/setup +7 -0
- data/lib/pactas_itero/api/contracts.rb +5 -0
- data/lib/pactas_itero/api/invoices.rb +6 -2
- data/lib/pactas_itero/api/oauth.rb +2 -3
- data/lib/pactas_itero/api/rated_items.rb +1 -1
- data/lib/pactas_itero/api.rb +7 -7
- data/lib/pactas_itero/client.rb +26 -22
- data/lib/pactas_itero/configurable.rb +5 -6
- data/lib/pactas_itero/default.rb +12 -15
- data/lib/pactas_itero/error.rb +12 -15
- data/lib/pactas_itero/ext/hash/camelize_keys.rb +7 -8
- data/lib/pactas_itero/response/raise_error.rb +3 -7
- data/lib/pactas_itero/version.rb +1 -1
- data/lib/pactas_itero.rb +2 -2
- data/pactas_itero.gemspec +37 -0
- data/spec/fixtures/contract_changes.json +22 -0
- data/spec/fixtures/invoice_download.pdf +0 -0
- data/spec/pactas_itero/api/contracts_spec.rb +85 -57
- data/spec/pactas_itero/api/customers_spec.rb +101 -99
- data/spec/pactas_itero/api/invoices_spec.rb +65 -49
- data/spec/pactas_itero/api/orders_spec.rb +42 -42
- data/spec/pactas_itero/api/rated_items_spec.rb +42 -42
- data/spec/pactas_itero/client_spec.rb +48 -52
- data/spec/pactas_itero_spec.rb +1 -3
- data/spec/spec_helper.rb +12 -12
- data/yarn-error.log +43 -0
- metadata +54 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c640237f33f075e2b01065f84283d9a8c68a95badd3816ee0aaa908401037b8
|
4
|
+
data.tar.gz: b373eb25ecad679c10529e6072b15757a39c4bd33337784cba586b4ad1ae163d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b1565b63af992bbc298f3113d0abc997a6fc0e475181edd03be4d1043273da6cdaa9b5b5a825be245ab836ce3ba2ba24badae369436c941b5b0a3c651844a0
|
7
|
+
data.tar.gz: f425d601137f812f8468de3484c9fc4754901db3bedba5b342a755b2924dae92b6dd19263e90e6ba25ec17f527055d3cea799836028a3e619a04a14795bace36
|
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,41 @@
|
|
11
11
|
|
12
12
|
### Security
|
13
13
|
|
14
|
+
## [0.7.0] - 2022-02-22
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- get contract_changes
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
|
22
|
+
- Set required ruby version to >= 2.6
|
23
|
+
- Replace Travis CI with CircleCI
|
24
|
+
- `rubocop` version is specified to be `~> 1.8.1`
|
25
|
+
- `performance` version is specified to be `~> 1.7.0`
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
|
29
|
+
- Drop support for Ruby <= 2.5
|
30
|
+
- Drop support for JRuby
|
31
|
+
|
32
|
+
## [0.6.0] - 2021-03-03
|
33
|
+
### Changed
|
34
|
+
- `faraday_middleware` version is specified to be `>= 1.0.0`
|
35
|
+
|
36
|
+
## [0.5.0] - 2019-06-11
|
37
|
+
### Changed
|
38
|
+
- Updates gem dependencies to latest versions (#65):
|
39
|
+
- replaces rash with rash_alt
|
40
|
+
- removes specific faraday_middleware version dependency
|
41
|
+
|
42
|
+
## [0.4.0] - 2019-04-30
|
43
|
+
### Added
|
44
|
+
* download Invoices as PDF (#60)
|
45
|
+
|
46
|
+
### Changed
|
47
|
+
* new prodcution endpoint (#45)
|
48
|
+
|
14
49
|
## [0.3.0] - 2017-09-04
|
15
50
|
### Added
|
16
51
|
- get a self service token for a given contract
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,65 +1,112 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pactas_itero (0.
|
5
|
-
faraday_middleware (>=
|
6
|
-
|
4
|
+
pactas_itero (0.7.0)
|
5
|
+
faraday_middleware (>= 1.0)
|
6
|
+
rash_alt
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
12
|
-
public_suffix (
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
crack (0.4.5)
|
15
|
+
rexml
|
16
|
+
diff-lcs (1.5.0)
|
17
|
+
docile (1.4.0)
|
18
|
+
faraday (1.10.0)
|
19
|
+
faraday-em_http (~> 1.0)
|
20
|
+
faraday-em_synchrony (~> 1.0)
|
21
|
+
faraday-excon (~> 1.1)
|
22
|
+
faraday-httpclient (~> 1.0)
|
23
|
+
faraday-multipart (~> 1.0)
|
24
|
+
faraday-net_http (~> 1.0)
|
25
|
+
faraday-net_http_persistent (~> 1.0)
|
26
|
+
faraday-patron (~> 1.0)
|
27
|
+
faraday-rack (~> 1.0)
|
28
|
+
faraday-retry (~> 1.0)
|
29
|
+
ruby2_keywords (>= 0.0.4)
|
30
|
+
faraday-em_http (1.0.0)
|
31
|
+
faraday-em_synchrony (1.0.0)
|
32
|
+
faraday-excon (1.1.0)
|
33
|
+
faraday-httpclient (1.0.1)
|
34
|
+
faraday-multipart (1.0.3)
|
18
35
|
multipart-post (>= 1.2, < 3)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
faraday-net_http (1.0.1)
|
37
|
+
faraday-net_http_persistent (1.2.0)
|
38
|
+
faraday-patron (1.0.0)
|
39
|
+
faraday-rack (1.0.0)
|
40
|
+
faraday-retry (1.0.3)
|
41
|
+
faraday_middleware (1.2.0)
|
42
|
+
faraday (~> 1.0)
|
43
|
+
hashdiff (1.0.1)
|
44
|
+
hashie (4.1.0)
|
45
|
+
json (2.6.1)
|
46
|
+
multipart-post (2.1.1)
|
47
|
+
parallel (1.21.0)
|
48
|
+
parser (3.1.0.0)
|
49
|
+
ast (~> 2.4.1)
|
50
|
+
public_suffix (4.0.6)
|
51
|
+
rainbow (3.1.1)
|
52
|
+
rake (13.0.6)
|
53
|
+
rash_alt (0.4.9)
|
54
|
+
hashie (~> 4.1)
|
55
|
+
regexp_parser (2.2.1)
|
56
|
+
rexml (3.2.5)
|
57
|
+
rspec (3.11.0)
|
58
|
+
rspec-core (~> 3.11.0)
|
59
|
+
rspec-expectations (~> 3.11.0)
|
60
|
+
rspec-mocks (~> 3.11.0)
|
61
|
+
rspec-core (3.11.0)
|
62
|
+
rspec-support (~> 3.11.0)
|
63
|
+
rspec-expectations (3.11.0)
|
36
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-mocks (3.
|
65
|
+
rspec-support (~> 3.11.0)
|
66
|
+
rspec-mocks (3.11.0)
|
39
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-support (3.
|
42
|
-
|
43
|
-
|
44
|
-
|
68
|
+
rspec-support (~> 3.11.0)
|
69
|
+
rspec-support (3.11.0)
|
70
|
+
rubocop (1.25.1)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 3.1.0.0)
|
73
|
+
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
regexp_parser (>= 1.8, < 3.0)
|
75
|
+
rexml
|
76
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
77
|
+
ruby-progressbar (~> 1.7)
|
78
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
79
|
+
rubocop-ast (1.15.2)
|
80
|
+
parser (>= 3.0.1.1)
|
81
|
+
rubocop-performance (1.13.2)
|
82
|
+
rubocop (>= 1.7.0, < 2.0)
|
83
|
+
rubocop-ast (>= 0.4.0)
|
84
|
+
ruby-progressbar (1.11.0)
|
85
|
+
ruby2_keywords (0.0.5)
|
86
|
+
simplecov (0.16.1)
|
87
|
+
docile (~> 1.1)
|
45
88
|
json (>= 1.8, < 3)
|
46
89
|
simplecov-html (~> 0.10.0)
|
47
|
-
simplecov-html (0.10.
|
48
|
-
|
49
|
-
|
90
|
+
simplecov-html (0.10.2)
|
91
|
+
unicode-display_width (2.1.0)
|
92
|
+
webmock (3.14.0)
|
93
|
+
addressable (>= 2.8.0)
|
50
94
|
crack (>= 0.3.2)
|
51
|
-
hashdiff
|
95
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
52
96
|
|
53
97
|
PLATFORMS
|
98
|
+
arm64-darwin-21
|
54
99
|
ruby
|
55
100
|
|
56
101
|
DEPENDENCIES
|
57
102
|
bundler
|
58
103
|
pactas_itero!
|
59
104
|
rake
|
60
|
-
rspec (~> 3.
|
61
|
-
|
62
|
-
|
105
|
+
rspec (~> 3.11.0)
|
106
|
+
rubocop (~> 1.25.1)
|
107
|
+
rubocop-performance (~> 1.13.2)
|
108
|
+
simplecov (~> 0.16.1)
|
109
|
+
webmock (~> 3.3)
|
63
110
|
|
64
111
|
BUNDLED WITH
|
65
|
-
|
112
|
+
2.3.7
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
[![
|
1
|
+
[![CircleCI](https://circleci.com/gh/shipcloud/billwerk/tree/master.svg?style=svg)](https://circleci.com/gh/shipcloud/billwerk/tree/master)
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/cfbdd07da1f178c7fa9a/maintainability)](https://codeclimate.com/github/shipcloud/billwerk/maintainability)
|
3
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/cfbdd07da1f178c7fa9a/test_coverage)](https://codeclimate.com/github/shipcloud/billwerk/test_coverage)
|
2
4
|
|
3
5
|
# PactasItero
|
4
6
|
|
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
5
|
-
spec.pattern = FileList[
|
5
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
6
6
|
end
|
7
7
|
|
8
8
|
task :console do
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
9
|
+
require "irb"
|
10
|
+
require "irb/completion"
|
11
|
+
require "pactas_itero"
|
12
12
|
ARGV.clear
|
13
13
|
IRB.start
|
14
14
|
end
|
data/bin/setup
ADDED
@@ -6,6 +6,11 @@ module PactasItero
|
|
6
6
|
get "api/v1/customers/#{customer_id}/contracts", options
|
7
7
|
end
|
8
8
|
|
9
|
+
def contract_changes(contract_id, options = {})
|
10
|
+
options = options.camelize_keys
|
11
|
+
get "api/v1/contractChanges", options.merge(contractId: contract_id)
|
12
|
+
end
|
13
|
+
|
9
14
|
def contracts(options = {})
|
10
15
|
options = options.camelize_keys
|
11
16
|
get "api/v1/contracts", options
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module PactasItero
|
2
2
|
module Api
|
3
3
|
module Invoices
|
4
|
-
|
5
4
|
def invoices(options = {})
|
6
5
|
options = options.camelize_keys
|
7
6
|
get "api/v1/invoices", options
|
8
7
|
end
|
9
8
|
|
10
|
-
def invoices_from(from_id=nil, options = {})
|
9
|
+
def invoices_from(from_id = nil, options = {})
|
11
10
|
if from_id
|
12
11
|
options = options.camelize_keys
|
13
12
|
get "api/v1/invoices?from=#{from_id}", options
|
@@ -20,6 +19,11 @@ module PactasItero
|
|
20
19
|
options = options.camelize_keys
|
21
20
|
get "api/v1/invoices/#{invoice_id}", options
|
22
21
|
end
|
22
|
+
|
23
|
+
def invoice_download(invoice_id, options = {})
|
24
|
+
options = options.camelize_keys
|
25
|
+
get "api/v1/invoices/#{invoice_id}/download", options
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
1
|
module PactasItero
|
3
2
|
module Api
|
4
3
|
module OAuth
|
5
4
|
def token(options = {})
|
6
5
|
options[:bearer_token_request] = true
|
7
|
-
options[:grant_type] ||=
|
8
|
-
post
|
6
|
+
options[:grant_type] ||= "client_credentials"
|
7
|
+
post "/oauth/token", options
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -6,7 +6,7 @@ module PactasItero
|
|
6
6
|
quantity: quantity,
|
7
7
|
description: description,
|
8
8
|
price_per_unit: price_per_unit,
|
9
|
-
tax_policy_id: tax_policy_id
|
9
|
+
tax_policy_id: tax_policy_id,
|
10
10
|
)
|
11
11
|
options = options.camelize_keys
|
12
12
|
post "api/v1/contracts/#{contract_id}/ratedItems", options
|
data/lib/pactas_itero/api.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require "pactas_itero/ext/hash/camelize_keys"
|
2
|
+
require "pactas_itero/api/oauth"
|
3
|
+
require "pactas_itero/api/rated_items"
|
4
|
+
require "pactas_itero/api/customers"
|
5
|
+
require "pactas_itero/api/contracts"
|
6
|
+
require "pactas_itero/api/orders"
|
7
|
+
require "pactas_itero/api/invoices"
|
8
8
|
require "pactas_itero/api/payment_transactions"
|
9
9
|
|
10
10
|
module PactasItero
|
data/lib/pactas_itero/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "base64"
|
2
|
+
require "rash"
|
3
|
+
require "pactas_itero/configurable"
|
4
|
+
require "pactas_itero/api"
|
5
5
|
|
6
6
|
module PactasItero
|
7
7
|
class Client
|
@@ -12,7 +12,10 @@ module PactasItero
|
|
12
12
|
|
13
13
|
def initialize(options = {})
|
14
14
|
PactasItero::Configurable.keys.each do |key|
|
15
|
-
instance_variable_set(
|
15
|
+
instance_variable_set(
|
16
|
+
:"@#{key}",
|
17
|
+
options[key] || PactasItero.instance_variable_get(:"@#{key}"),
|
18
|
+
)
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
@@ -59,29 +62,29 @@ module PactasItero
|
|
59
62
|
bearer_token_request = params.delete(:bearer_token_request)
|
60
63
|
|
61
64
|
if bearer_token_request
|
62
|
-
headers[:accept] =
|
65
|
+
headers[:accept] = "*/*"
|
63
66
|
headers[:authorization] = bearer_token_credentials_auth_header
|
64
|
-
headers[:content_type] =
|
67
|
+
headers[:content_type] = "application/x-www-form-urlencoded; charset=UTF-8"
|
65
68
|
else
|
66
69
|
headers[:authorization] = auth_header
|
67
70
|
end
|
68
71
|
|
69
|
-
response = connection.send(method.to_sym, path, params)
|
70
|
-
|
71
|
-
|
72
|
+
response = connection.send(method.to_sym, path, params) do |request|
|
73
|
+
request.headers.update(headers)
|
74
|
+
end.env
|
72
75
|
response.body
|
73
76
|
end
|
74
77
|
|
75
78
|
def connection_options
|
76
79
|
@connection_options ||= {
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
80
|
+
builder: middleware,
|
81
|
+
headers: {
|
82
|
+
accept: default_media_type,
|
83
|
+
user_agent: user_agent,
|
81
84
|
},
|
82
|
-
:
|
83
|
-
:
|
84
|
-
:
|
85
|
+
request: {
|
86
|
+
open_timeout: 10,
|
87
|
+
timeout: 30,
|
85
88
|
},
|
86
89
|
}
|
87
90
|
end
|
@@ -92,11 +95,12 @@ module PactasItero
|
|
92
95
|
end
|
93
96
|
|
94
97
|
def bearer_auth_header
|
95
|
-
token =
|
96
|
-
bearer_token.access_token
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
token =
|
99
|
+
if bearer_token.respond_to?(:access_token)
|
100
|
+
bearer_token.access_token
|
101
|
+
else
|
102
|
+
bearer_token
|
103
|
+
end
|
100
104
|
"Bearer #{token}"
|
101
105
|
end
|
102
106
|
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module PactasItero
|
2
|
-
|
3
2
|
module Configurable
|
4
3
|
attr_accessor :bearer_token, :client_id, :client_secret, :user_agent,
|
5
4
|
:default_media_type, :middleware, :production
|
6
5
|
attr_writer :api_endpoint
|
7
|
-
class << self
|
8
6
|
|
7
|
+
class << self
|
9
8
|
# List of configurable keys for PactasItero::Client
|
10
9
|
def keys
|
11
10
|
@keys ||= [
|
@@ -16,7 +15,7 @@ module PactasItero
|
|
16
15
|
:user_agent,
|
17
16
|
:default_media_type,
|
18
17
|
:middleware,
|
19
|
-
:production
|
18
|
+
:production,
|
20
19
|
]
|
21
20
|
end
|
22
21
|
end
|
@@ -37,8 +36,8 @@ module PactasItero
|
|
37
36
|
|
38
37
|
def api_endpoint
|
39
38
|
endpoint = @api_endpoint ||
|
40
|
-
|
41
|
-
|
39
|
+
production && production_api_endpoint ||
|
40
|
+
sandbox_api_endpoint
|
42
41
|
File.join(endpoint, "")
|
43
42
|
end
|
44
43
|
|
@@ -53,7 +52,7 @@ module PactasItero
|
|
53
52
|
private
|
54
53
|
|
55
54
|
def options
|
56
|
-
Hash[PactasItero::Configurable.keys.map{|key| [key, send(:"#{key}")]}]
|
55
|
+
Hash[PactasItero::Configurable.keys.map { |key| [key, send(:"#{key}")] }]
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
data/lib/pactas_itero/default.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "pactas_itero/response/raise_error"
|
2
|
+
require "pactas_itero/version"
|
3
|
+
require "faraday_middleware"
|
4
4
|
|
5
5
|
module PactasItero
|
6
|
-
|
7
6
|
# Default configuration options for {Client}
|
8
7
|
module Default
|
9
|
-
|
10
8
|
SANDBOX_API_ENDPOINT = "https://sandbox.billwerk.com".freeze
|
11
9
|
|
12
|
-
PRODUCTION_API_ENDPOINT = "https://
|
10
|
+
PRODUCTION_API_ENDPOINT = "https://app.billwerk.com".freeze
|
13
11
|
|
14
12
|
PRODUCTION = false
|
15
13
|
|
@@ -22,19 +20,18 @@ module PactasItero
|
|
22
20
|
builder.use PactasItero::Response::RaiseError
|
23
21
|
builder.response :rashify
|
24
22
|
builder.request :url_encoded
|
25
|
-
builder.response :json, :
|
23
|
+
builder.response :json, content_type: /\bjson$/
|
26
24
|
|
27
25
|
builder.adapter Faraday.default_adapter
|
28
26
|
end
|
29
27
|
|
30
28
|
class << self
|
31
|
-
|
32
29
|
def options
|
33
|
-
Hash[PactasItero::Configurable.keys.map{|key| [key, send(key)]}]
|
30
|
+
Hash[PactasItero::Configurable.keys.map { |key| [key, send(key)] }]
|
34
31
|
end
|
35
32
|
|
36
33
|
def api_endpoint
|
37
|
-
ENV[
|
34
|
+
ENV["PACTAS_ITERO_ENDPOINT"]
|
38
35
|
end
|
39
36
|
|
40
37
|
def sandbox_api_endpoint
|
@@ -50,19 +47,19 @@ module PactasItero
|
|
50
47
|
end
|
51
48
|
|
52
49
|
def client_id
|
53
|
-
ENV[
|
50
|
+
ENV["PACTAS_ITERO_CLIENT_ID"]
|
54
51
|
end
|
55
52
|
|
56
53
|
def client_secret
|
57
|
-
ENV[
|
54
|
+
ENV["PACTAS_ITERO_CLIENT_SECRET"]
|
58
55
|
end
|
59
56
|
|
60
57
|
def bearer_token
|
61
|
-
ENV[
|
58
|
+
ENV["PACTAS_ITERO_BEARER_TOKEN"]
|
62
59
|
end
|
63
60
|
|
64
61
|
def default_media_type
|
65
|
-
ENV[
|
62
|
+
ENV["PACTAS_ITERO_CLIENT_DEFAULT_MEDIA_TYPE"] || MEDIA_TYPE
|
66
63
|
end
|
67
64
|
|
68
65
|
def middleware
|
@@ -70,7 +67,7 @@ module PactasItero
|
|
70
67
|
end
|
71
68
|
|
72
69
|
def user_agent
|
73
|
-
ENV[
|
70
|
+
ENV["PACTAS_ITERO_USER_AGENT"] || USER_AGENT
|
74
71
|
end
|
75
72
|
end
|
76
73
|
end
|
data/lib/pactas_itero/error.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module PactasItero
|
2
2
|
# Custom error class for rescuing from all Pactas errors
|
3
3
|
class Error < StandardError
|
4
|
-
|
5
4
|
# Returns the appropriate PactasItero::Error sublcass based
|
6
5
|
# on status and response message
|
7
6
|
#
|
@@ -32,7 +31,7 @@ module PactasItero
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
def initialize(response=nil)
|
34
|
+
def initialize(response = nil)
|
36
35
|
@response = response
|
37
36
|
super(build_error_message)
|
38
37
|
end
|
@@ -50,9 +49,9 @@ module PactasItero
|
|
50
49
|
# Returns most appropriate error for 403 HTTP status code
|
51
50
|
# @private
|
52
51
|
def self.error_for_403(body)
|
53
|
-
if
|
52
|
+
if /rate limit exceeded/i.match?(body)
|
54
53
|
PactasItero::TooManyRequests
|
55
|
-
elsif
|
54
|
+
elsif /login attempts exceeded/i.match?(body)
|
56
55
|
PactasItero::TooManyLoginAttempts
|
57
56
|
else
|
58
57
|
PactasItero::Forbidden
|
@@ -75,15 +74,13 @@ module PactasItero
|
|
75
74
|
@data ||=
|
76
75
|
if (body = @response[:body]) && !body.empty?
|
77
76
|
if body.is_a?(String) &&
|
78
|
-
|
79
|
-
|
77
|
+
@response[:response_headers] &&
|
78
|
+
@response[:response_headers][:content_type] =~ /json/
|
80
79
|
|
81
80
|
Sawyer::Agent.serializer.decode(body)
|
82
81
|
else
|
83
82
|
body
|
84
83
|
end
|
85
|
-
else
|
86
|
-
nil
|
87
84
|
end
|
88
85
|
end
|
89
86
|
|
@@ -105,7 +102,7 @@ module PactasItero
|
|
105
102
|
|
106
103
|
summary = "\nError summary:\n"
|
107
104
|
summary << data[:errors].map do |hash|
|
108
|
-
hash.map { |k,v| " #{k}: #{v}" }
|
105
|
+
hash.map { |k, v| " #{k}: #{v}" }
|
109
106
|
end.join("\n")
|
110
107
|
|
111
108
|
summary
|
@@ -117,9 +114,9 @@ module PactasItero
|
|
117
114
|
message = "#{@response[:method].to_s.upcase} "
|
118
115
|
message << redact_url(@response[:url].to_s) + ": "
|
119
116
|
message << "#{@response[:status]} - "
|
120
|
-
message <<
|
121
|
-
message <<
|
122
|
-
message <<
|
117
|
+
message << response_message.to_s unless response_message.nil?
|
118
|
+
message << response_error.to_s unless response_error.nil?
|
119
|
+
message << response_error_summary.to_s unless response_error_summary.nil?
|
123
120
|
message
|
124
121
|
end
|
125
122
|
|
@@ -143,12 +140,12 @@ module PactasItero
|
|
143
140
|
# Raised when Pactas returns a 401 HTTP status code
|
144
141
|
# and headers include "X-Pactas-OTP"
|
145
142
|
class OneTimePasswordRequired < ClientError
|
146
|
-
|
143
|
+
# @private
|
147
144
|
OTP_DELIVERY_PATTERN = /required; (\w+)/i
|
148
145
|
|
149
|
-
|
146
|
+
# @private
|
150
147
|
def self.required_header(headers)
|
151
|
-
OTP_DELIVERY_PATTERN.match headers[
|
148
|
+
OTP_DELIVERY_PATTERN.match headers["X-Pactas-OTP"].to_s
|
152
149
|
end
|
153
150
|
|
154
151
|
# Delivery method for the user's OTP
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class Hash
|
2
|
-
|
3
2
|
def camelize_keys(value = self)
|
4
3
|
case value
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
when Array
|
5
|
+
value.map { |v| camelize_keys(v) }
|
6
|
+
when Hash
|
7
|
+
Hash[value.map { |k, v| [camelize_key(k), camelize_keys(v)] }]
|
8
|
+
else
|
9
|
+
value
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
@@ -27,6 +26,6 @@ class Hash
|
|
27
26
|
def camelize(term)
|
28
27
|
string = term.to_s
|
29
28
|
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
30
|
-
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub(
|
29
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
31
30
|
end
|
32
31
|
end
|