mercado_bitcoin 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9341f93059a854f69dc3aa52bc8e4a71ce3760a4
4
- data.tar.gz: 426ea0f2d98143737c274cbb1ff131de80813cca
3
+ metadata.gz: 6025df04b0aa23fac07d2558151eca505e1b1846
4
+ data.tar.gz: 5ef2021541f98e82b7e03a922bb953ac10b95ee1
5
5
  SHA512:
6
- metadata.gz: f4e36e2c72f15c771ad2d5106a27be748b1811573128d268ff27e82b67fbc6f35b4aa0c8929e908047c53bf39837e772df7cb75a43ae4b38f5a2911855117e05
7
- data.tar.gz: 314a300b365ad98d79cd5070aded27106be504bb38391bd4d4b09d3e635e4cfa8299a35cc836a43517d24a5c257ac30e7d5f3b831219b26614b1a1fece0e8555
6
+ metadata.gz: 18bbaee0f9571f402291a71508145fd367d1c9b0e1ebfcd71ccfeef529fdb80fb61c983750b2ec0115c7f2153488c6a4c32ca8cdc7694862a2ddfb95b43e53db
7
+ data.tar.gz: 84329dddeb56770a65daa444234b62fa365184be0573cfb3767fb3460ea5768e2f8b083b6c55dbd16600c3f7a7c1e5544ad7598f25759ec86052041dfc114473
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --require spec_helper
1
2
  --format progress
2
3
  --color
File without changes
@@ -3,4 +3,5 @@ module MercadoBitcoin
3
3
  class ParserError < Error; end
4
4
  class CoinTypeError < Error; end
5
5
  class TonceDesyncError < Error; end
6
+ class TonceAlreadyUsed < Error; end
6
7
  end
@@ -13,6 +13,7 @@ module MercadoBitcoin
13
13
  @key = key
14
14
  @code = code
15
15
  @debug = debug
16
+ @retries = 0
16
17
  end
17
18
 
18
19
  def get_account_info
@@ -97,8 +98,18 @@ module MercadoBitcoin
97
98
  post(params)
98
99
  end
99
100
 
101
+ attr_writer :last_tapi_nonce
102
+
103
+ def last_tapi_nonce
104
+ @last_tapi_nonce ||= (Time.new.to_f * 10).to_i
105
+ end
106
+
107
+ def tapi_nonce
108
+ self.last_tapi_nonce += 1
109
+ end
110
+
100
111
  def post(params)
101
- params[:tapi_nonce] = (Time.new.to_f * 10).to_i
112
+ params[:tapi_nonce] = tapi_nonce
102
113
  signature = sign(params)
103
114
  puts params.to_query_string if debug?
104
115
  result = JSON.parse(
@@ -108,6 +119,43 @@ module MercadoBitcoin
108
119
  header(signature)
109
120
  )
110
121
  )
122
+ deal_with_errors(result)
123
+ rescue MercadoBitcoin::TonceAlreadyUsed
124
+ retry
125
+ end
126
+
127
+ def deal_with_errors(result)
128
+ if result['status_code'] == 100
129
+ @retries = 0
130
+ return result
131
+ end
132
+
133
+ @retries += 1
134
+ if @retries >= 6
135
+ @retries = 0
136
+ result[:_mb_gem] = { code: 1, retries: @retries, error: 'maximum retries reached' }
137
+ return result
138
+ end
139
+
140
+ return deal_with_tapi_nonce(result) if result['status_code'] == 203
141
+
142
+ deal_with_errors_not_treated(result)
143
+ end
144
+
145
+ def deal_with_tapi_nonce(result)
146
+ if result['error_message'] =~ /utilizado: (\d+)/
147
+ self.last_tapi_nonce = $1.to_i
148
+ raise MercadoBitcoin::TonceAlreadyUsed.new
149
+ else
150
+ result[:_mb_gem] = { code: 2, retries: @retries, error: 'last tapi_nonce not found.' }
151
+ result
152
+ end
153
+ end
154
+
155
+ def deal_with_errors_not_treated(result)
156
+ result[:_mb_gem] = { code: 0, retries: @retries, error: 'not treated' }
157
+ @retries = 0
158
+ result
111
159
  end
112
160
 
113
161
  def base_path
@@ -1,3 +1,3 @@
1
1
  module MercadoBitcoin
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.10"
24
24
  spec.add_development_dependency "pry", "~> 0.10"
25
25
  spec.add_development_dependency "byebug", "~> 9.0"
26
- spec.add_development_dependency "rake", "~> 11.2"
26
+ spec.add_development_dependency "rake", "~> 12.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.4"
28
+ spec.add_development_dependency 'webmock', '~> 3.0'
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercado_bitcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Carvalho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-04 00:00:00.000000000 Z
11
+ date: 2017-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '11.2'
103
+ version: '12.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '11.2'
110
+ version: '12.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
125
139
  description: 'Thin layer over public price api of MercadoBitcoin.com.br for more information
126
140
  about the API see https://www.mercadobitcoin.com.br/api '
127
141
  email:
@@ -139,7 +153,7 @@ files:
139
153
  - LICENSE.txt
140
154
  - README.md
141
155
  - Rakefile
142
- - bin/mb_console.rb
156
+ - bin/mb_console
143
157
  - docker-compose.yml
144
158
  - lib/mercado_bitcoin.rb
145
159
  - lib/mercado_bitcoin/api.rb
@@ -180,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
194
  version: '0'
181
195
  requirements: []
182
196
  rubyforge_project:
183
- rubygems_version: 2.6.6
197
+ rubygems_version: 2.6.8
184
198
  signing_key:
185
199
  specification_version: 4
186
200
  summary: Thin layer over public price api of MercadoBitcoin.com.br