unirole 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/unirole.rb +18 -39
- data/lib/unirole/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84f7185a3048418685b8eac37dcd44acd1ed10ad
|
4
|
+
data.tar.gz: ea4e7d830a0b8e5687e5d57724fd7ba537ee9282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d74ca6789800dd281fdc1606560062827564880550d16ec1cf6f78a72cf69470f104e227ca03ad2e0f2033944d4da5a3db3b275d08da323e728f2a18f07f5a60
|
7
|
+
data.tar.gz: debbb734d27ab8d32e19bdddaefd13e5902fb69b320b7f27ee552a292810bbc241c9b39a39ec51457feb9132f7f7ed0180faa0a9b19de233f3b8d9d939205743
|
data/lib/unirole.rb
CHANGED
@@ -11,16 +11,17 @@ require 'rest-client'
|
|
11
11
|
module Unirole
|
12
12
|
|
13
13
|
class API
|
14
|
-
attr_accessor :api_key, :api_secret, :username, :nonce_v
|
14
|
+
attr_accessor :api_key, :api_secret, :username, :nonce_v, :site_url
|
15
15
|
|
16
|
-
def initialize(username, api_key, api_secret)
|
16
|
+
def initialize(username, api_key, api_secret, site_url="https://account.bitmain.com")
|
17
17
|
self.username = username
|
18
18
|
self.api_key = api_key
|
19
19
|
self.api_secret = api_secret
|
20
|
+
self.site_url = site_url
|
20
21
|
end
|
21
22
|
|
22
23
|
def api_call(method, param = {}, priv = false, action = '', method_type='post', is_json = true)
|
23
|
-
url = "
|
24
|
+
url = "#{self.site_url}/api/v1/#{ method }/#{ action }"
|
24
25
|
if priv
|
25
26
|
self.nonce
|
26
27
|
param.merge!(:access_key => self.api_key, :signature => self.signature.to_s, :nonce => self.nonce_v)
|
@@ -37,40 +38,20 @@ module Unirole
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
self.api_call
|
41
|
+
def google_auth sso_id, code
|
42
|
+
self.api_call 'two_auths', {sso_id: sso_id, code: code}, true, 'google'
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
-
self.api_call 'two_auths', {
|
45
|
+
def check? sso_id
|
46
|
+
self.api_call 'two_auths', {sso_id: sso_id}, true, "check"
|
46
47
|
end
|
47
48
|
|
48
|
-
def
|
49
|
-
self.api_call
|
49
|
+
def send_sms_code sso_id
|
50
|
+
self.api_call('two_auths', {sso_id: sso_id}, true, "send_sms")
|
50
51
|
end
|
51
52
|
|
52
|
-
def
|
53
|
-
self.api_call 'two_auths', {}, true,
|
54
|
-
end
|
55
|
-
|
56
|
-
def send_sms_code user_id
|
57
|
-
self.api_call('accounts', {}, true, "#{user_id}/send_sms_code")
|
58
|
-
end
|
59
|
-
|
60
|
-
def sms_auth user_id, code
|
61
|
-
self.api_call 'two_auths', {id: user_id, code: code}, true, 'sms'
|
62
|
-
end
|
63
|
-
|
64
|
-
def trade_password? user_id
|
65
|
-
self.api_call 'accounts', {}, true, "#{user_id}/check_trade_pin_setting"
|
66
|
-
end
|
67
|
-
|
68
|
-
def post_trade_hash user_id, trade_hash
|
69
|
-
self.api_call 'accounts', {trade_hash: trade_hash}, true, "#{user_id}/trade_hash"
|
70
|
-
end
|
71
|
-
|
72
|
-
def trade_pin_validation user_id, password
|
73
|
-
self.api_call 'accounts', {password: password}, true, "#{user_id}/trade_pin_validation"
|
53
|
+
def sms_auth sso_id, code
|
54
|
+
self.api_call 'two_auths', {sso_id: sso_id, code: code}, true, 'sms'
|
74
55
|
end
|
75
56
|
|
76
57
|
def nonce
|
@@ -79,7 +60,7 @@ module Unirole
|
|
79
60
|
|
80
61
|
def signature
|
81
62
|
str = self.nonce_v + self.username + self.api_key
|
82
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest
|
63
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), self.api_secret, str)
|
83
64
|
end
|
84
65
|
|
85
66
|
def get url, param
|
@@ -87,13 +68,11 @@ module Unirole
|
|
87
68
|
end
|
88
69
|
|
89
70
|
def post(url, param)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# https.post(uri.path, params.query).body
|
96
|
-
RestClient.post(url, param)
|
71
|
+
begin
|
72
|
+
RestClient.post(url, param)
|
73
|
+
rescue Exception => e
|
74
|
+
{code: 500, mgs: e.to_s}.to_json
|
75
|
+
end
|
97
76
|
end
|
98
77
|
end
|
99
78
|
end
|
data/lib/unirole/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unirole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- charls
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.4.6
|
165
165
|
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: bitmian account api library
|