peatio_client 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5e6ad1f696dcab93ecc46656033fa2a57fe11a1
4
- data.tar.gz: 6f6e6b96158c309cb1ce5c7e64021f0470ecd231
3
+ metadata.gz: 47c7870dd981ae09fa76adc319fed3c4b53a81fb
4
+ data.tar.gz: 525e1f70390a331183bbea7158ddddf0b7b72aba
5
5
  SHA512:
6
- metadata.gz: 81a34eadff332965787ccd5dcb978e93cd92aca23774eca2d69108910eb0c7b6135cb660c7e7d5559160233de776a8f9db78c0117263fbda0f356f7849581de7
7
- data.tar.gz: e60227427a4973b3adb7421a4782e24631420cce6e6f38f979fb491aea57f121d7d6b5fd6b94397bef6626d94e1c048980597db3969a8c8b08d15b7bc7885c0a
6
+ metadata.gz: dcf7ae4613ed0a12d68047caf35cf82780af214d84b2c31d214a1aa4c80c556adcc5762cbb0c381ad82fb6ddc3a238b0d5aa3317ae479f4666b6cfc7f5dafb5f
7
+ data.tar.gz: bf74ea2bb5e9d67a2f49c772c372801a24b7e9b0bad9b7daec5ac6797cd5ee9681f61142abb1284ee2780c38e449681a273fa326e0d32b8d8e5991c4ec293096
@@ -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
- # initialize client. `endpoint` can be ignored
31
- client = PeatioAPI::Client.new access_key: 'your_access_key', secret_key: 'your_secret_key', endpoint: 'https://peatio.com'
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
- client.get '/api/v2/markets'
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'
@@ -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://peatio.com'
13
+ @endpoint = options[:endpoint] || 'https://yunbi.com'
14
+ @timeout = options[:timeout] || 60
14
15
  end
15
16
 
16
- def get(path, params={})
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
- # sign on all requests, even those to public API
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
- parse Net::HTTP.get_response(uri)
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
- params = @auth.signed_params 'POST', path, params
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
@@ -1,5 +1,5 @@
1
1
  module PeatioAPI
2
2
  class Client
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  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.5
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-07-24 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport