okcoin 0.1.3 → 0.1.4

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: 6d6e50b5d0bf07480589a5c0ace82601a66d604f
4
- data.tar.gz: 36026e98e7ff68ec78b02fa5bc72d314de90c626
3
+ metadata.gz: 52ceb78aea2b8a2c40806cd6c1c71306d2a060c4
4
+ data.tar.gz: 01faf344026e9f3a924cf1940082fe2a9860be3f
5
5
  SHA512:
6
- metadata.gz: df673216a9422fa2f8ea644af39b95bcea54e79188e61d5ac7db882a38068ec16f7bc1e31ee2289b945c008667a2fb3892fb1cba833b409e07ad516be7421640
7
- data.tar.gz: 89e3c77063db92f9f9507b60a96944718989cba9aea22357c618b077a6f2bafece7f39902bf09c8accf9e59b579ce3a5deef511a7e6fd2adb6ac93d8455560cf
6
+ metadata.gz: 5ca6eac2e7b68629fc60b55495d004402f984549a0156f1b4b0aca9cca42757d7bcbba85c199ae13894a6eb00c8f1f06f4b8219028a0e04d4088bc5ca1c7a4a1
7
+ data.tar.gz: 4e9f5c3e55535643b2087cd7eec006b6bce0e366732310cd5b7f3247e37bfe340bc1ed6f36af267f24cd3467f2a05e421bc7bc7efe018937c054becbfce26003
data/README.md CHANGED
@@ -27,8 +27,14 @@ gem 'okcoin'
27
27
  ## 使用
28
28
 
29
29
  ```ruby
30
+ require 'okcoin'
31
+
32
+ # 如果要看详细的访问情况,把日志级别设置为debug
33
+ Okcoin::logger.level = Logger::DEBUG
34
+
30
35
  # url可选,默认就是https://www.okcoin.cn/api/,后面两个必选
31
36
  client = Okcoin::Client.new url: 'https://www.okcoin.cn/api/', api_key: 'YOUR_OKCOIN_APIKEY', secret_key: 'YOUR_OKCOIN_SECRET'
37
+
32
38
  client.ticker(symbol: "btc_cny")
33
39
  client.trades(symbol: 'btc_cny', since: nil)
34
40
  ```
@@ -1,23 +1,25 @@
1
- module ApiDefineTool
1
+ module Okcoin
2
+ module ApiDefineTool
2
3
 
3
- def define_get_api(*api_names)
4
- api_names.each do |api_name|
5
- define_method(api_name) do |**params|
6
- params.reject! do |k, v| v.blank? end
7
- http_get(@url+"v1/#{api_name}.do", params)
4
+ def define_get_api(*api_names)
5
+ api_names.each do |api_name|
6
+ define_method(api_name) do |**params|
7
+ params.reject! do |k, v| v.blank? end
8
+ http_get(@url+"v1/#{api_name}.do", params)
9
+ end
8
10
  end
9
11
  end
10
- end
11
12
 
12
- def define_post_api(*api_names)
13
- api_names.each do |api_name|
14
- define_method(api_name) do |**params|
15
- params.reject! do |k, v| v.blank? end
16
- params[:api_key] = @api_key
17
- params[:sign] = sign(params)
18
- http_post(@url+"v1/#{api_name}.do", params)
13
+ def define_post_api(*api_names)
14
+ api_names.each do |api_name|
15
+ define_method(api_name) do |**params|
16
+ params.reject! do |k, v| v.blank? end
17
+ params[:api_key] = @api_key
18
+ params[:sign] = sign(params)
19
+ http_post(@url+"v1/#{api_name}.do", params)
20
+ end
19
21
  end
20
22
  end
21
- end
22
23
 
24
+ end
23
25
  end
@@ -1,39 +1,39 @@
1
- module HttpUtils
1
+ module Okcoin
2
+ module HttpUtils
3
+ # result = http_get("https://www.okcoin.cn/api/v1/trades.do", { symbol: 'btc_usd', since: nil })
4
+ def http_get(url, params={})
5
+ uri = URI(url)
6
+ uri.query = URI.encode_www_form(params)
7
+ Okcoin::logger.debug( 'GET: ' + (uri.query.blank? ? url : "#{url}?#{uri.query}") )
2
8
 
3
- # result = http_get("https://www.okcoin.cn/api/v1/trades.do", { symbol: 'btc_usd', since: nil })
4
- def http_get(url, params={})
5
- uri = URI(url)
6
- uri.query = URI.encode_www_form(params)
7
- logger.debug( 'GET: ' + (uri.query.blank? ? url : "#{url}?#{uri.query}") )
9
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
10
+ request = Net::HTTP::Get.new uri
11
+ http.request request
12
+ end
8
13
 
9
- response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
10
- request = Net::HTTP::Get.new uri
11
- http.request request
14
+ if response.is_a?(Net::HTTPOK)
15
+ JSON.parse(response.body)
16
+ else
17
+ Okcoin::logger.error('response code is not 200!')
18
+ nil # todo: 报个异常
19
+ end
12
20
  end
13
21
 
14
- if response.is_a?(Net::HTTPOK)
15
- JSON.parse(response.body)
16
- else
17
- logger.error('response code is not 200!')
18
- nil # todo: 报个异常
19
- end
20
- end
22
+ def http_post(url, params={})
23
+ uri = URI(url)
24
+ Okcoin::logger.debug( "POST: #{url}?#{URI.encode_www_form(params)}" )
25
+ response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
26
+ request = Net::HTTP::Post.new(uri)
27
+ request.set_form_data(params)
28
+ http.request request
29
+ end
21
30
 
22
- def http_post(url, params={})
23
- uri = URI(url)
24
- logger.debug( "POST: #{url}?#{URI.encode_www_form(params)}" )
25
- response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
26
- request = Net::HTTP::Post.new(uri)
27
- request.set_form_data(params)
28
- http.request request
29
- end
30
-
31
- if response.is_a?(Net::HTTPOK)
32
- JSON.parse(response.body)
33
- else
34
- logger.error('response code is not 200!')
35
- nil # todo: 报个异常
31
+ if response.is_a?(Net::HTTPOK)
32
+ JSON.parse(response.body)
33
+ else
34
+ Okcoin::logger.error('response code is not 200!')
35
+ nil # todo: 报个异常
36
+ end
36
37
  end
37
38
  end
38
39
  end
39
-
@@ -1,3 +1,3 @@
1
1
  module Okcoin
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/okcoin.rb CHANGED
@@ -9,15 +9,15 @@ require "okcoin/api_define_tool"
9
9
  require 'okcoin/base'
10
10
  require "okcoin/client"
11
11
 
12
- def logger
13
- if $logger.nil?
14
- $logger = Logger.new(STDOUT)
15
- $logger.level = Logger::DEBUG
12
+ module Okcoin
13
+ def self.logger
14
+ if $logger.nil?
15
+ $logger = Logger.new(STDOUT)
16
+ $logger.level = Logger::WARN
17
+ end
18
+ return $logger
16
19
  end
17
- return $logger
18
- end
19
20
 
20
- module Okcoin
21
21
  class Object
22
22
  def blank?
23
23
  respond_to?(:empty?) ? !!empty? : !self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wu Minzhe