stocks_exchange_api_client 2.0.2 → 2.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: 64f20bbdfb95093e37810f7c8e6043735bd1541b117a853e2a9d360fc8220f74
4
- data.tar.gz: 599d208824ddde9fa115213a0568fd5205d9d5a86caa7e62f3822fbc585f4916
3
+ metadata.gz: a3b9f4a242d3ee4b520912a52f1081c358b5ea19beb300b4d47a3aab67a798d4
4
+ data.tar.gz: ffda3c3fce465e7e6b76870322d7586029222e81eb4cb2429f06c09f344f0e5c
5
5
  SHA512:
6
- metadata.gz: 330b054d1086b65df58dd91937139f606756fae43ab3cc0cb0f084e39bb2f32f5784e42c191d2f294accd4152cfb542e91c48a1fd73cfb1f9ffe89721361571b
7
- data.tar.gz: 59b538f6a5ec4d5d97059947af9f5a94f00664aa0f5310d1e1bbbbbe43f9a7ae174ca90e88fc557363f2f0431a42b6af2faaafe5bde14ab54b2e8bd99a4b5f17
6
+ metadata.gz: '09413046673714035f8509efa697c16b463997bbeb2591cf0b1a4468f347ddada2d1e4f63f3f255c984afec29874da7a2857444e953aff74a8062d9778bb3d4a'
7
+ data.tar.gz: 75b96003a8fad63a4968007f704a341dc217e9ccc6527c068105d240a463473c04e5072805378f14909c1f149bb194155ba0e405b9fc6f63b1c18cd48568990d
data/README.md CHANGED
@@ -12,7 +12,6 @@ STEX (former Stocks.Exchange) provides all the core exchange functionality, and
12
12
  ## General
13
13
  The base URL for all the requests other than public methods is
14
14
  ```
15
- https://app.stocks.exchange/api2
16
15
  https://app.stex.com/api2
17
16
  https://api3.stex.com
18
17
  ```
@@ -115,31 +115,36 @@ module StocksExchangeApiClient
115
115
  end
116
116
 
117
117
  def get_token
118
- if File.exist?(JSON_SETTINGS)
119
- current_token = JSON.parse(File.read(JSON_SETTINGS))
120
- else
121
- current_token = {'access_token' => configuration.option[:token_object][:access_token],
122
- 'refresh_token' => configuration.option[:token_object][:refresh_token],
123
- 'expires_in' => nil,
124
- 'expires_in_date' => nil}
125
- end
126
- if !current_token.nil? && !current_token['expires_in_date'].nil?
127
- return current_token['access_token'] if DateTime.parse(current_token['expires_in_date']).to_datetime > DateTime.now.to_datetime
118
+ if !configuration.s2s
119
+ if File.exist?(JSON_SETTINGS)
120
+ current_token = JSON.parse(File.read(JSON_SETTINGS))
121
+ else
122
+ current_token = {'access_token' => configuration.option[:token_object][:access_token],
123
+ 'refresh_token' => configuration.option[:token_object][:refresh_token],
124
+ 'expires_in' => nil,
125
+ 'expires_in_date' => nil}
126
+ end
127
+ if !current_token.nil? && !current_token['expires_in_date'].nil?
128
+ return current_token['access_token'] if DateTime.parse(current_token['expires_in_date']).to_datetime > DateTime.now.to_datetime
129
+ end
130
+ begin
131
+ response = HTTParty.post(configuration.option[:access_token_url], body: {
132
+ grant_type: 'refresh_token',
133
+ refresh_token: current_token['refresh_token'],
134
+ client_id: configuration.option[:client_id],
135
+ client_secret: configuration.option[:client_secret],
136
+ scope: configuration.option[:scope]
137
+ }).body
138
+ current_token = JSON.parse(response)
139
+ current_token['expires_in_date'] = Time.at(Time.now.to_i + current_token['expires_in']).to_s
140
+ File.write(JSON_SETTINGS, current_token.to_json)
141
+ current_token['access_token']
142
+ rescue StandardError => e
143
+ puts "Rescued: #{e.inspect}"
144
+ end
128
145
  end
129
- begin
130
- response = HTTParty.post(configuration.option[:access_token_url], body: {
131
- grant_type: 'refresh_token',
132
- refresh_token: current_token['refresh_token'],
133
- client_id: configuration.option[:client_id],
134
- client_secret: configuration.option[:client_secret],
135
- scope: configuration.option[:scope]
136
- }).body
137
- current_token = JSON.parse(response)
138
- current_token['expires_in_date'] = Time.at(Time.now.to_i + current_token['expires_in']).to_s
139
- File.write(JSON_SETTINGS, current_token.to_json)
140
- current_token['access_token']
141
- rescue StandardError => e
142
- puts "Rescued: #{e.inspect}"
146
+ if configuration.s2s
147
+ configuration.option[:token_object][:access_token]
143
148
  end
144
149
  end
145
150
 
@@ -1,12 +1,20 @@
1
+ require 'stocks_exchange_api_client/errors/configuration_error'
2
+
1
3
  module StocksExchangeApiClient
2
4
  class Configuration
3
- URL_V2 = 'https://app.stocks.exchange/api2'.freeze
5
+ URL_V2 = 'https://app.stex.com/api2'.freeze
4
6
  URL_V3 = 'https://api3.stex.com'.freeze
5
- attr_accessor :url, :option, :use_version
7
+ attr_accessor :url, :option, :use_version, :s2s
6
8
 
7
- def initialize
8
- @use_version ||= 2
9
- @url ||= URL_V2
9
+ def initialize(url: URL_V2, option: {}, use_version: 2, s2s: false)
10
+ if use_version == 3
11
+ @url||= URL_V3
12
+ else
13
+ @url||= URL_V3
14
+ end
15
+ @option||= option
16
+ @use_version||= use_version
17
+ @s2s||= s2s
10
18
  end
11
19
 
12
20
  def validate!
@@ -15,11 +23,16 @@ module StocksExchangeApiClient
15
23
  raise Errors::ConfigurationError
16
24
  end
17
25
  end
18
- if use_version == 3
26
+ if use_version == 3 && !s2s
19
27
  unless option[:client_id] && option[:client_secret] && option[:token_object][:access_token] && option[:token_object][:refresh_token]
20
28
  raise Errors::ConfigurationError
21
29
  end
22
30
  end
31
+ if use_version == 3 && s2s
32
+ unless option[:token_object][:access_token]
33
+ raise Errors::ConfigurationError
34
+ end
35
+ end
23
36
  end
24
37
  end
25
38
  end
@@ -2,7 +2,7 @@ module StocksExchangeApiClient
2
2
  module Errors
3
3
  class ConfigurationError < StandardError
4
4
  def initialize
5
- super 'Not all config vars were set. Stocks Exchange requires API key and API secret. Get this fields on url https://app.stocks.exchange/en/profile/settings'
5
+ super 'Not all config vars were set. Stocks Exchange requires API key and API secret. Get this fields on url https://app.stex.com/profile/settings'
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module StocksExchangeApiClient
2
- VERSION = '2.0.2'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stocks_exchange_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stocks Exchange
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-11 00:00:00.000000000 Z
11
+ date: 2019-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl