volabit 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/volabit/api.rb +13 -3
- data/lib/volabit/auth.rb +20 -0
- data/lib/volabit/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: 3a051bef9491dd7c9dd9e355908101508ecee078
|
4
|
+
data.tar.gz: 4fe851e275af21008e9366687ed9ae2e4d5dfc76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b54d6f318b4bc0bb1988c8cf8042e2e94443734564dfe587fc65837a1c79a4211ed1b796bd8d53c8940cc55499efc9ff7aed915e08297822820d75ee442ac9e4
|
7
|
+
data.tar.gz: 09a5e247a2ac8ca02790d418a769376492d00124a519d8eed2cfb47d8e3e8cb10d4e7e1852e022776a41572af19814ff7e1bd33a035d9512b478e57f9ceeb413
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/volabit.svg)](http://badge.fury.io/rb/volabit)
|
2
|
+
|
1
3
|
# Volabit
|
2
4
|
|
3
|
-
Volabit's API library. Integrate the Volabit services in your apps with ease.
|
5
|
+
Volabit's API Ruby library. Integrate the Volabit services in your apps with ease.
|
4
6
|
|
5
7
|
You can see the available methods on the [project wiki][wiki]. Details of the API use can be found on the [official page][api-docs].
|
6
8
|
|
@@ -36,7 +38,7 @@ callback = 'The registered callback URL for your APP'
|
|
36
38
|
volabit_client = Volabit::Client.new(app_id, secret, callback)
|
37
39
|
```
|
38
40
|
|
39
|
-
Note that
|
41
|
+
Note that by default the Volabit client uses the **production** environment. If you want to use the **test** environment, set the sandbox flag to `true` before requesting the authorization code.
|
40
42
|
|
41
43
|
```ruby
|
42
44
|
volabit_client.sandbox true
|
@@ -54,11 +56,16 @@ auth_url = volabit_client.authorize
|
|
54
56
|
volabit_client.get_token 'The given authorization code.'
|
55
57
|
```
|
56
58
|
|
57
|
-
4)
|
59
|
+
4) If you already have a `token` and a `refresh_token` you can use:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
volabit_client.use_token 'token', 'refresh_token'
|
63
|
+
```
|
64
|
+
|
65
|
+
5) You're ready to use our API. Just call any method listed [here][wiki].
|
58
66
|
|
59
67
|
```ruby
|
60
|
-
|
61
|
-
response.body
|
68
|
+
tickers = volabit_client.tickers
|
62
69
|
# => {
|
63
70
|
# "btc_usd_buy":"226.06",
|
64
71
|
# "btc_usd_sell":"226.56",
|
data/lib/volabit/api.rb
CHANGED
@@ -10,18 +10,28 @@ module Volabit
|
|
10
10
|
|
11
11
|
# Request a resource using the GET method.
|
12
12
|
def get_resource(resource, params = nil)
|
13
|
+
raise no_token_error unless @token
|
13
14
|
@token.refresh if @token.expired?
|
14
|
-
@token.get(resource, params: params)
|
15
|
+
response = @token.get(resource, params: params)
|
16
|
+
JSON.parse response.body, :symbolize_names => true
|
15
17
|
end
|
16
18
|
|
17
19
|
def post_to_resource(resource, params)
|
20
|
+
raise no_token_error unless @token
|
18
21
|
@token.refresh if @token.expired?
|
19
|
-
@token.post(resource, params: params)
|
22
|
+
response = @token.post(resource, params: params)
|
23
|
+
JSON.parse response.body, :symbolize_names => true
|
20
24
|
end
|
21
25
|
|
22
26
|
def delete_resource(resource)
|
27
|
+
raise no_token_error unless @token
|
23
28
|
@token.refresh if @token.expired?
|
24
|
-
@token.delete(resource)
|
29
|
+
response = @token.delete(resource)
|
30
|
+
JSON.parse response.body, :symbolize_names => true
|
31
|
+
end
|
32
|
+
|
33
|
+
def no_token_error
|
34
|
+
'Error: you have to run get_token or set_token before use this method.'
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
data/lib/volabit/auth.rb
CHANGED
@@ -27,6 +27,26 @@ module Volabit
|
|
27
27
|
# access the API and the methods to renew itself.
|
28
28
|
def get_token(auth_code)
|
29
29
|
@token = @oauth_client.auth_code.get_token auth_code, redirect_uri: @url
|
30
|
+
{
|
31
|
+
:token => @token.token,
|
32
|
+
:refresh_token => @token.refresh_token,
|
33
|
+
:expires_in => @token.expires_in,
|
34
|
+
:expires_at => @token.expires_at,
|
35
|
+
:options => @token.options
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def use_token(token, refresh_token)
|
40
|
+
token = OAuth2::AccessToken.new @oauth_client, token, { :refresh_token => refresh_token }
|
41
|
+
token_info = JSON.parse token.get('/oauth/token/info').body
|
42
|
+
expires_in = token_info['expires_in_seconds']
|
43
|
+
@token = OAuth2::AccessToken.new @oauth_client, token, {
|
44
|
+
:refresh_token => refresh_token,
|
45
|
+
:expires_in => expires_in,
|
46
|
+
:mode => :header,
|
47
|
+
:header_format => 'Bearer %s',
|
48
|
+
:param_name => 'access_token'
|
49
|
+
}
|
30
50
|
end
|
31
51
|
|
32
52
|
# Toggles the test environment with a boolean value.
|
data/lib/volabit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volabit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Volabit Team & Contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.2.2
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Library for the Volabit API.
|