max_exchange_api 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29e67831c545b85f3e39db7cdab7dcbf293c8d2958a5fed7affa29b2617d4a79
4
- data.tar.gz: '08ba7fe4b157b1abcd9611e47c170c406975dcea7497cc9be6490ec7bd3985f3'
3
+ metadata.gz: 47011d6e19cad34466caa491f4aca3e9500167275377019fd8803dbfa81d0acf
4
+ data.tar.gz: 3642c750db63d9e66fc38a9d8f6b4502251b7911be8c30a506c1d02369973aff
5
5
  SHA512:
6
- metadata.gz: c10c08e3462a21a8ea9cb5be83327d06bdc8e406757895004ef31ed38df4606903337edbf7c07e0c5944ca88f8817c203abd7319369cbe763fed74785d3a788a
7
- data.tar.gz: dd2bc0c74f8ae55bb1df54cfed702c6c908678ebca08f10c4181adc26162b23401ecaaddbbe9ff2698a9a96fb0662a041431044b2f6327d26285dba12b62c10a
6
+ metadata.gz: e9243e4bb8bd16c8de3bc0d2290791242b4337dfec90f4105f5c191485f30e4664213ed8cea8e99f83460606d647ac5e9964a52de522521bae75c0c716cf67e7
7
+ data.tar.gz: f41f4c2d3d62bfa2c0d9d3d379734ffcd290988365848cc582259b6732d0701f9a3d3ea2daa608d7e9ad2700fe7b90bd58529794273d864f66d3525e0670d4d1
data/README.md CHANGED
@@ -37,19 +37,29 @@ Or install it yourself as:
37
37
 
38
38
  ## Configuration
39
39
 
40
- ### Api timeout time
40
+ ### Set timeout time
41
41
 
42
42
  ```rb
43
+ # default config
43
44
  MaxExchangeApi.default_config.timeout = 3 # seconds
45
+
46
+ # custom config
47
+ MaxExchangeApi::PublicApi.new(config: { timeout: 12 })
48
+ MaxExchangeApi::PrivateApi.new(access_key, secret_key, config: { timeout: 12 })
44
49
  ```
45
50
 
46
- ### Api logging
51
+ ### Logging
47
52
 
48
53
  ```rb
49
54
  require 'logger'
50
55
 
56
+ # default config
51
57
  MaxExchangeApi.default_config.logger = Logger.new(STDOUT) # print log to stdand output
52
58
  MaxExchangeApi.default_config.logger = Logger.new('log/api.log')
59
+
60
+ # custom config
61
+ MaxExchangeApi::PublicApi.new(config: { logger: Logger.new(STDOUT) })
62
+ MaxExchangeApi::PrivateApi.new(access_key, secret_key, config: { logger: Logger.new(STDOUT) })
53
63
  ```
54
64
 
55
65
  ## Usage
@@ -7,6 +7,13 @@ module MaxExchangeApi
7
7
  class BaseApi
8
8
  include HTTParty
9
9
 
10
+ attr_reader :config
11
+
12
+ def initialize(config: nil)
13
+ @config = Config.new(config)
14
+ @config.reverse_merge!(MaxExchangeApi.default_config)
15
+ end
16
+
10
17
  protected
11
18
 
12
19
  def send_request(method, path, headers, query)
@@ -19,7 +26,7 @@ module MaxExchangeApi
19
26
  path,
20
27
  headers: headers,
21
28
  query: query,
22
- timeout: MaxExchangeApi.default_config.timeout,
29
+ timeout: @config.timeout,
23
30
  ).parsed_response
24
31
 
25
32
  print_log(:info, "[API] #{uuid} response #{response}")
@@ -33,7 +40,7 @@ module MaxExchangeApi
33
40
  private
34
41
 
35
42
  def print_log(method, message)
36
- logger = MaxExchangeApi.default_config.logger
43
+ logger = @config.logger
37
44
  logger.send(method, message) if logger
38
45
  end
39
46
  end
@@ -5,13 +5,20 @@ module MaxExchangeApi
5
5
  attr_accessor :timeout
6
6
  attr_accessor :logger
7
7
 
8
- def initialize
9
- @timeout = 3
10
- @logger = nil
8
+ def initialize(data = nil)
9
+ data ||= {}
10
+ @timeout = data[:timeout]
11
+ @logger = data[:logger]
12
+ end
13
+
14
+ def reverse_merge!(other)
15
+ @timeout ||= other.timeout
16
+ @logger ||= other.logger
11
17
  end
12
18
  end
13
19
 
14
20
  @default_config = Config.new
21
+ @default_config.timeout = 3
15
22
 
16
23
  class << self
17
24
  attr_reader :default_config
@@ -6,8 +6,8 @@ module MaxExchangeApi
6
6
  class PrivateApi < BaseApi
7
7
  base_uri 'https://max-api.maicoin.com/api/v2'
8
8
 
9
- def initialize(access_key, secret_key)
10
- super()
9
+ def initialize(access_key, secret_key, config: nil)
10
+ super(config: config)
11
11
 
12
12
  @access_key = access_key
13
13
  @secret_key = secret_key
@@ -1,3 +1,3 @@
1
1
  module MaxExchangeApi
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: max_exchange_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy