peatio_client 0.0.5 → 0.0.7
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 +4 -4
- data/README.markdown +12 -3
- data/lib/peatio_api/client.rb +36 -11
- data/lib/peatio_api/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c7870dd981ae09fa76adc319fed3c4b53a81fb
|
4
|
+
data.tar.gz: 525e1f70390a331183bbea7158ddddf0b7b72aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcf7ae4613ed0a12d68047caf35cf82780af214d84b2c31d214a1aa4c80c556adcc5762cbb0c381ad82fb6ddc3a238b0d5aa3317ae479f4666b6cfc7f5dafb5f
|
7
|
+
data.tar.gz: bf74ea2bb5e9d67a2f49c772c372801a24b7e9b0bad9b7daec5ac6797cd5ee9681f61142abb1284ee2780c38e449681a273fa326e0d32b8d8e5991c4ec293096
|
data/README.markdown
CHANGED
@@ -27,11 +27,20 @@ Use `#get` or `#post` to access API after you created a `PeatioAPI::Client`:
|
|
27
27
|
```ruby
|
28
28
|
require 'peatio_client'
|
29
29
|
|
30
|
-
#
|
31
|
-
|
30
|
+
# Client can be initialized not providing key and sercet, but this client can only access public APIs
|
31
|
+
client_public = PeatioAPI::Client.new endpoint: 'https://peatio.com'
|
32
32
|
|
33
33
|
# GET public api /api/v2/markets
|
34
|
-
|
34
|
+
client_public.get_public '/api/v2/markets'
|
35
|
+
|
36
|
+
# To build a full functional client which can access both public/private api, access_key/secret_key
|
37
|
+
# are required.
|
38
|
+
#
|
39
|
+
# `endpoint` can be ignored or set to any Peatio powered exchange.
|
40
|
+
#
|
41
|
+
# If there's no data received in `timeout` seconds, Net::OpenTimeout will be raised. Default to 60.
|
42
|
+
#
|
43
|
+
client = PeatioAPI::Client.new access_key: 'your_access_key', secret_key: 'your_secret_key', endpoint: 'https://peatio.com', timeout: 60
|
35
44
|
|
36
45
|
# GET private api /api/v2/orders with 'market=btccny'
|
37
46
|
client.get '/api/v2/orders', market: 'btccny'
|
data/lib/peatio_api/client.rb
CHANGED
@@ -10,31 +10,53 @@ module PeatioAPI
|
|
10
10
|
def initialize(options={})
|
11
11
|
options.symbolize_keys!
|
12
12
|
setup_auth_keys options
|
13
|
-
@endpoint = options[:endpoint] || 'https://
|
13
|
+
@endpoint = options[:endpoint] || 'https://yunbi.com'
|
14
|
+
@timeout = options[:timeout] || 60
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
+
def get_public(path, params={})
|
17
18
|
uri = URI("#{@endpoint}#{path}")
|
19
|
+
uri.query = URI.encode_www_form params
|
20
|
+
|
21
|
+
request(:get, path, nil, params) do |http, _|
|
22
|
+
http.request_get(uri.request_uri)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(path, params={})
|
27
|
+
check_auth!
|
18
28
|
|
19
|
-
|
20
|
-
signed_params = @auth.signed_params 'GET', path, params
|
21
|
-
uri.query = URI.encode_www_form signed_params
|
29
|
+
uri = URI("#{@endpoint}#{path}")
|
22
30
|
|
23
|
-
|
31
|
+
request(:get, path, @auth, params) do |http, signed_params|
|
32
|
+
uri.query = URI.encode_www_form signed_params
|
33
|
+
http.request_get(uri.request_uri)
|
34
|
+
end
|
24
35
|
end
|
25
36
|
|
26
37
|
def post(path, params={})
|
38
|
+
check_auth!
|
39
|
+
|
40
|
+
request(:post, path, @auth, params) do |http, signed_params|
|
41
|
+
http.request_post(path, signed_params.to_query)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def request(action, path, auth, params={})
|
27
48
|
uri = URI("#{@endpoint}#{path}")
|
49
|
+
params = auth.signed_params action.to_s.upcase, path, params if auth
|
50
|
+
|
28
51
|
http = Net::HTTP.new(uri.hostname, uri.port)
|
52
|
+
http.open_timeout = @timeout
|
29
53
|
http.use_ssl = true if @endpoint.start_with?('https://')
|
54
|
+
|
30
55
|
http.start do |http|
|
31
|
-
|
32
|
-
parse http.request_post(path, params.to_query)
|
56
|
+
parse yield(http, params)
|
33
57
|
end
|
34
58
|
end
|
35
59
|
|
36
|
-
private
|
37
|
-
|
38
60
|
def parse(response)
|
39
61
|
JSON.parse response.body
|
40
62
|
rescue JSON::ParserError
|
@@ -47,9 +69,12 @@ module PeatioAPI
|
|
47
69
|
@secret_key = options[:secret_key]
|
48
70
|
@auth = Auth.new @access_key, @secret_key
|
49
71
|
else
|
50
|
-
raise ArgumentError, 'Missing access key and/or secret key'
|
72
|
+
#raise ArgumentError, 'Missing access key and/or secret key'
|
51
73
|
end
|
52
74
|
end
|
53
75
|
|
76
|
+
def check_auth!
|
77
|
+
raise ArgumentError, 'Missing access key and/or secret key' if @auth.nil?
|
78
|
+
end
|
54
79
|
end
|
55
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peatio_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peatio Opensource
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|