modulr-api 0.0.44 → 0.0.46

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: 985e67e8a7284607d6d6ab83c5961c56d7ab92a8ef4fe24713908730afe063b6
4
- data.tar.gz: 57c5b585f5039a0c69942f0311017d1f13e0505fb2f8c9900d501948a3d448a9
3
+ metadata.gz: 45f16a01e7450ae71621e53a850720a9679124c4bc22db243da24916eee09229
4
+ data.tar.gz: 1b67cded77fa55969e1024dfc676f06b5cd77cfd35153a801b9492c980f4e334
5
5
  SHA512:
6
- metadata.gz: 198a8ece89370a7f720622874bf1d0f6dce08862eede48664f3405b8db19a0aa2c63cdc162f2d8e04ff846809baf64d8bb3e85a60368de9e663b10505b52c491
7
- data.tar.gz: 7b97f877c66a30566c2fa484664ee0433fb84650b31bd4109312ece4cbee41f77d02c052f68bb5b74979011c157a4ede681354b2697699636c9ea1055dd6eb05
6
+ metadata.gz: a859137b06dd2fce7562b8e1f044991e9a53c0f529cb1390e182e5dab67eb30b68d3adec9f55b38d371458438287f64ed81c1b9b7522ee2412981b3e8c35d571
7
+ data.tar.gz: 3b4fe0303298bebe102ea330c4b183f937304bac3ed548e0b0743c704fd92dbf495747c8463dec193d4ae7adb64cf4d7739fb2d62c491962412d4855e1bc23f7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- modulr-api (0.0.44)
4
+ modulr-api (0.0.46)
5
5
  faraday (~> 1.0)
6
6
  faraday_middleware (~> 1.0)
7
7
 
@@ -9,12 +9,6 @@ module Modulr
9
9
  @client = client
10
10
  end
11
11
 
12
- def idempotency_headers(options)
13
- headers = {}
14
- headers[:idempotency_key] = options[:idempotency_key] if options[:idempotency_key]
15
- headers
16
- end
17
-
18
12
  def format_datetime(datetime)
19
13
  datetime.strftime("%Y-%m-%dT%H:%M:%S%z")
20
14
  end
data/lib/modulr/client.rb CHANGED
@@ -80,28 +80,30 @@ module Modulr
80
80
 
81
81
  def request_options(method, _path, data, options)
82
82
  default_options.tap do |defaults|
83
+ add_idempotency_headers!(defaults[:headers], method, options)
83
84
  add_auth_options!(defaults)
84
- add_idempotency_headers!(defaults[:headers], method, options) if options
85
+
85
86
  defaults[:body] = JSON.dump(data) if data
86
87
  end
87
88
  end
88
89
 
89
90
  def add_auth_options!(options)
90
- return sandbox_auth_options(options) if @base_url.eql?(SANDBOX_URL)
91
+ return sandbox_auth_options(options[:headers]) if @base_url.eql?(SANDBOX_URL)
91
92
 
92
- auth_options(options)
93
+ auth_options(options[:headers])
93
94
  end
94
95
 
95
96
  def sandbox_auth_options(options)
96
- options[:headers][:authorization] = @apikey
97
+ options[:authorization] = @apikey
97
98
  end
98
99
 
99
100
  def auth_options(options)
100
- signature = Auth::Signature.calculate(apikey: @apikey, apisecret: @apisecret)
101
+ nonce = options["x-mod-nonce"]
102
+ signature = Auth::Signature.calculate(apikey: @apikey, apisecret: @apisecret, nonce: nonce)
101
103
 
102
- options[:headers][:authorization] = signature.authorization
103
- options[:headers][:date] = signature.timestamp
104
- options[:headers][:"x-mod-nonce"] ||= signature.nonce
104
+ options[:authorization] = signature.authorization
105
+ options[:date] = signature.timestamp
106
+ options["x-mod-nonce"] = signature.nonce
105
107
  end
106
108
 
107
109
  private def add_idempotency_headers!(headers, method, options)
@@ -111,8 +113,8 @@ module Modulr
111
113
  return unless idempotency_key
112
114
 
113
115
  nonce = self.class.idempotency_nonce(idempotency_key)
114
- headers[:"x-mod-nonce"] = nonce
115
- headers[:"x-mod-retry"] = "true" if nonce && !nonce.empty?
116
+ headers["x-mod-nonce"] = nonce
117
+ headers["x-mod-retry"] = "true"
116
118
  end
117
119
 
118
120
  private def merge_query_params(request, method, options)
@@ -126,6 +128,8 @@ module Modulr
126
128
  case error
127
129
  when Faraday::ClientError
128
130
  raise ClientError, error
131
+ when Faraday::TimeoutError
132
+ raise TimeoutError, error
129
133
  when Faraday::ServerError
130
134
  raise ServerError, error
131
135
  else
data/lib/modulr/error.rb CHANGED
@@ -35,4 +35,7 @@ module Modulr
35
35
 
36
36
  class ServerError < Error
37
37
  end
38
+
39
+ class TimeoutError < Error
40
+ end
38
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modulr
4
- VERSION = "0.0.44"
4
+ VERSION = "0.0.46"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulr-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aitor García Rey