bitopro 1.0.3 → 1.0.4

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: ddd7f48092821353323e10f01efa13708704480d1f3b2e5cadf8552c9821dcc7
4
- data.tar.gz: e1857340c2333eddb86a90ee5d2d6f6ba5712bc5c3897c0fef7e06fcb47695e7
3
+ metadata.gz: 1e5c53c96852494993e32b2148fe51924f5ab735724cc397a22ec6167b31bb07
4
+ data.tar.gz: befe9c38587c12d2704471ca03d731c2d5e54bd931edd47a1eff7ed05ccf3e82
5
5
  SHA512:
6
- metadata.gz: 06e7ddd7b8b215c7ecc95325fa81c40867ae475874deb736be37a8b2f826068d3fa62af5b2e69251260b0c28e19947be927468ab94e6370bfce57a2c9ded4c48
7
- data.tar.gz: 687fd5425ab1601c28b3a7d31fc8a9ec7dcc4b1e56324560d770f8200fd505f91f48196bc345946a700ca8c2fd4df21ab79486476318ed3d5f72bacb6ab46eca
6
+ metadata.gz: da5bf8178cefc5ad31ce79cfc4d8081121df3e4273908ace9823e6618b9319cf010a352aa10c438be019894b82f730f68e7f5644f911dd0bb81933a5b472af10
7
+ data.tar.gz: d3d93dbddbc92db71d5e6ad68bc7b7d82c8e394eff030acc506ef00d73e82910d7e1263b6ea9df61c27eda5fc7900f4101de592828ce2aa76c652239f46b261d
@@ -1,5 +1,7 @@
1
1
  module Bitopro
2
2
  module Account
3
+ class Error < StandardError; end
4
+
3
5
  def account_balance
4
6
  authenticated_get("/accounts/balance")
5
7
  end
@@ -9,7 +11,9 @@ module Bitopro
9
11
  end
10
12
 
11
13
  def order_list(pair: "", page: 1, active: false)
12
- authenticated_get("/orders/#{currency_pair}", params: { page: page, active: active })
14
+ raise Error, "pair is required" unless pair
15
+
16
+ authenticated_get("/orders/#{pair}", params: { page: page, active: active })
13
17
  end
14
18
  end
15
19
  end
@@ -6,6 +6,7 @@ module Bitopro
6
6
  class Client
7
7
  class SetupError < StandardError; end
8
8
 
9
+ AUTH_HTTP_ACTION = %w(get post delete)
9
10
  BASE_URL = "https://api.bitopro.com/v2".freeze
10
11
 
11
12
  include Bitopro::Public
@@ -18,71 +19,33 @@ module Bitopro
18
19
 
19
20
  private
20
21
 
21
- def build_url(url)
22
+ def complete_url(url)
22
23
  "#{BASE_URL}#{url}"
23
24
  end
24
25
 
25
- def authenticated_get(url, params = {})
26
- raise SetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
26
+ AUTH_HTTP_ACTION.each do |action|
27
+ define_method "authenticated_#{action}" do |url, params = {}|
28
+ raise SetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
27
29
 
28
- complete_url = build_url(url)
30
+ json_body = build_json_body(params: params, action: action)
31
+ payload = build_payload(json_body)
32
+ headers = build_headers(payload)
29
33
 
30
- json_body = { identity: @config.email, nonce: timestamp }.to_json
31
- payload = build_payload(json_body)
32
- headers = build_headers(payload)
34
+ response = RestClient::Request.execute(method: action,
35
+ url: complete_url(url),
36
+ headers: headers,
37
+ payload: params,
38
+ timeout: 10)
33
39
 
34
- response = RestClient::Request.execute(method: :get,
35
- url: complete_url,
36
- headers: headers,
37
- payload: params,
38
- timeout: 10)
39
-
40
- JSON.parse(response.body)
41
- end
42
-
43
- def authenticated_post(url, params = {})
44
- raise SetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
45
-
46
- complete_url = build_url(url)
47
-
48
- json_body = params[:body].to_json
49
- payload = build_payload(json_body)
50
- headers = build_headers(payload)
51
-
52
- response = RestClient::Request.execute(method: :post,
53
- url: complete_url,
54
- headers: headers,
55
- payload: json_body,
56
- timeout: 10)
57
-
58
- JSON.parse(response.body)
59
- end
60
-
61
- def authenticated_delete(url, params = {})
62
- raise BitoproSetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
63
-
64
- complete_url = build_url(url)
65
-
66
- json_body = { identity: @config.email, nonce: timestamp }.to_json
67
- payload = build_payload(json_body)
68
- headers = build_headers(payload)
69
-
70
- response = RestClient::Request.execute(method: :delete,
71
- url: complete_url,
72
- headers: headers,
73
- payload: params,
74
- timeout: 10)
75
-
76
- JSON.parse(response.body)
40
+ JSON.parse(response.body)
41
+ end
77
42
  end
78
43
 
79
44
  def get(url, params = {})
80
- complete_url = build_url(url)
81
- headers = { "X-BITOPRO-API": "ruby" }
82
45
  response = RestClient::Request.execute(method: :get,
83
- url: complete_url,
46
+ url: complete_url(url),
84
47
  payload: params,
85
- headers: headers,
48
+ headers: tracking_header,
86
49
  timeout: 10)
87
50
 
88
51
  JSON.parse(response.body)
@@ -92,6 +55,11 @@ module Bitopro
92
55
  Base64.strict_encode64(json_body)
93
56
  end
94
57
 
58
+ def build_json_body(params:, action:)
59
+ body = action == "post" ? params[:body] : { identity: @config.email, nonce: timestamp }
60
+ body.to_json
61
+ end
62
+
95
63
  def timestamp
96
64
  (Time.now.to_f * 1000).floor
97
65
  end
@@ -100,13 +68,16 @@ module Bitopro
100
68
  OpenSSL::HMAC.hexdigest("SHA384", @config.secret, payload)
101
69
  end
102
70
 
71
+ def tracking_header
72
+ { "X-BITOPRO-API": "ruby" }
73
+ end
74
+
103
75
  def build_headers(payload)
104
76
  {
105
- "X-BITOPRO-API": "ruby",
106
77
  "X-BITOPRO-APIKEY": @config.key,
107
78
  "X-BITOPRO-PAYLOAD": payload,
108
79
  "X-BITOPRO-SIGNATURE": signature(payload)
109
- }
80
+ }.merge!(tracking_header)
110
81
  end
111
82
  end
112
83
  end
@@ -1,3 +1,3 @@
1
1
  module Bitopro
2
- VERSION = "1.0.3".freeze
2
+ VERSION = "1.0.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitopro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - niclin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-08 00:00:00.000000000 Z
11
+ date: 2019-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,7 +141,7 @@ rubyforge_project:
141
141
  rubygems_version: 2.7.8
142
142
  signing_key:
143
143
  specification_version: 4
144
- summary: bitopro-1.0.3
144
+ summary: bitopro-1.0.4
145
145
  test_files:
146
146
  - spec/spec_helper.rb
147
147
  - spec/bitopro/config_spec.rb