unirole 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/unirole.rb +18 -39
  3. data/lib/unirole/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7e939c9b9394ddf0ae8a67063c4e2c9032d6cdc
4
- data.tar.gz: d34ba274fee701e9583709bf9340c33ff60d64b3
3
+ metadata.gz: 84f7185a3048418685b8eac37dcd44acd1ed10ad
4
+ data.tar.gz: ea4e7d830a0b8e5687e5d57724fd7ba537ee9282
5
5
  SHA512:
6
- metadata.gz: c2cccbc6b2c941c3e45f73795d8d7a0cd7468a617ed902f382a6fe2e8bf888fedc885881e61b108037594797dfc4453a65cc7e104bcfbc94b98f3f63da9bc99a
7
- data.tar.gz: a6e429b6ac2501d7b98648604f5ac6cf7ec0e2d514dab2e5bf4647f635297ed21576e15ecc38556069214ac75b50017217da6fa2cb8bb75dc13c3c91760a69ff
6
+ metadata.gz: d74ca6789800dd281fdc1606560062827564880550d16ec1cf6f78a72cf69470f104e227ca03ad2e0f2033944d4da5a3db3b275d08da323e728f2a18f07f5a60
7
+ data.tar.gz: debbb734d27ab8d32e19bdddaefd13e5902fb69b320b7f27ee552a292810bbc241c9b39a39ec51457feb9132f7f7ed0180faa0a9b19de233f3b8d9d939205743
@@ -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 = "https://account.bitmain.com/api/v1/#{ method }/#{ action }"
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 photo_url user_id
41
- self.api_call('accounts', {}, true, "#{user_id}/photo")
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 google_auth user_id, code
45
- self.api_call 'two_auths', {id: user_id, google_code: code}, true, 'google'
45
+ def check? sso_id
46
+ self.api_call 'two_auths', {sso_id: sso_id}, true, "check"
46
47
  end
47
48
 
48
- def google_activated user_id
49
- self.api_call 'two_auths', {}, true, "check/google/#{user_id}"
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 sms_activated user_id
53
- self.api_call 'two_auths', {}, true, "check/sms/#{user_id}"
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::Digest.new('sha256'), self.api_secret, str)
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
- # uri = URI.parse(url)
91
- # https = Net::HTTP.new(uri.host, uri.port)
92
- # https.use_ssl = true
93
- # params = Addressable::URI.new
94
- # params.query_values = param
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
@@ -1,3 +1,3 @@
1
1
  module Unirole
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
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.0
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: 2014-11-20 00:00:00.000000000 Z
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.2.2
164
+ rubygems_version: 2.4.6
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: bitmian account api library