api_auth-client 0.0.1 → 0.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
- SHA1:
3
- metadata.gz: 4e8971d12299355746c2105b860d727dd53ccb0f
4
- data.tar.gz: 1799f574233186f9a684215c1a7d0812ea8e2b20
2
+ SHA256:
3
+ metadata.gz: 455d5827fdd8ae7651d128b4e0f2617d6060389603d0b93d32db72235ad569f3
4
+ data.tar.gz: 5058e1cb48faaa17d4e49b2f793ce230f51694941453a4f9ee04024b222e44eb
5
5
  SHA512:
6
- metadata.gz: 856c0df82b6d75937b380bc874ca6061d1b3d1d80d29ce239a5eb6d9742ff34c87d23ed8d0676ae498a1ed22ea69ac47f98461413eb837f8ce7f326f3ae4bc44
7
- data.tar.gz: e4987909bac40b0cfa7722e5a8cee13f541013cd2c92e1eae36bfa04dd469f8b3b8554e24e6e10125f9235b78403effba7bfc7341f4480d43a8ce1966983d891
6
+ metadata.gz: 490476ac43525e3dd7f1069ee8ae8846e38f5cacc9af91386b847d19e7c0a8b37eca1cd98c3ef44a7ed6711b41d7d30b35eba25d1a54e3fb84048a71b4687cc2
7
+ data.tar.gz: a6e40302f1a0f903ebbff5f945ad55a90aee8f9d3ea9cb75c4d33af6c19a411fd7e64f81d9364cce18332ff6a1ffee4fdc000bb2e702d774f48c1c7ca18b82d0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.5
1
+ 3.4.7
data/README.md CHANGED
@@ -27,7 +27,9 @@ Or install it yourself as:
27
27
 
28
28
  ```ruby
29
29
  class VolabitClient < ApiAuth::Client::Base
30
- connect url: 'https://www.volabit.com/api/v1'
30
+ connect url: 'https://www.volabit.com/api/v1',
31
+ app_id: 'some-app-id',
32
+ secret_key: 'some-app-secret'
31
33
 
32
34
  def tickers
33
35
  connection.get('/tickers')
@@ -10,12 +10,15 @@ module ApiAuth
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- attr_reader :attr_url, :attr_app_id, :attr_secret_key
13
+ attr_reader :attr_url, :attr_app_id, :attr_secret_key, :attr_type, :attr_auth_token, :attr_args
14
14
 
15
- def connect(url:, app_id: nil, secret_key: nil)
15
+ def connect(url:, app_id: nil, secret_key: nil, type: :hmac, auth_token: nil, args: {}) # rubocop:disable Metrics/ParameterLists
16
16
  @attr_url = url
17
17
  @attr_app_id = app_id
18
18
  @attr_secret_key = secret_key
19
+ @attr_type = type&.to_sym
20
+ @attr_auth_token = auth_token
21
+ @attr_args = args
19
22
  end
20
23
  end
21
24
 
@@ -26,6 +29,9 @@ module ApiAuth
26
29
  url: self.class.attr_url,
27
30
  app_id: self.class.attr_app_id,
28
31
  secret_key: self.class.attr_secret_key,
32
+ type: self.class.attr_type,
33
+ auth_token: self.class.attr_auth_token,
34
+ args: self.class.attr_args || {},
29
35
  )
30
36
  end
31
37
  end
@@ -6,12 +6,15 @@ require 'api-auth'
6
6
  module ApiAuth
7
7
  module Client
8
8
  class Connection
9
- attr_reader :url, :app_id, :secret_key
9
+ attr_reader :url, :app_id, :secret_key, :type, :auth_token, :args
10
10
 
11
- def initialize(url:, app_id: nil, secret_key: nil)
11
+ def initialize(url:, app_id: nil, secret_key: nil, type: nil, auth_token: nil, args: {}) # rubocop:disable Metrics/ParameterLists
12
12
  @url = url
13
13
  @app_id = app_id
14
14
  @secret_key = secret_key
15
+ @type = type
16
+ @auth_token = auth_token
17
+ @args = args
15
18
  end
16
19
 
17
20
  %i[
@@ -20,11 +23,11 @@ module ApiAuth
20
23
  put
21
24
  delete
22
25
  ].each do |mtd|
23
- define_method("#{mtd}!") do |path, payload = {}|
26
+ define_method("#{mtd}!") do |path = nil, payload = {}|
24
27
  query(mtd, path, payload)
25
28
  end
26
29
 
27
- define_method(mtd) do |path, payload = {}|
30
+ define_method(mtd) do |path = nil, payload = {}|
28
31
  begin
29
32
  send("#{mtd}!", path, payload)
30
33
  rescue ConnectionError, ApiEndpointError => e
@@ -54,26 +57,32 @@ module ApiAuth
54
57
  url: endpoint_uri(path),
55
58
  ssl_version: 'SSLv23',
56
59
  headers: json_headers,
57
- }
58
- params[:payload] = payload.to_json if mtd == :post
60
+ }.merge(args&.except(:headers)&.to_h)
61
+
62
+ params[:payload] = payload.to_json if payload.present?
63
+ params.merge!(user: app_id, password: secret_key) if type == :basic
59
64
  RestClient::Request.new(params)
60
65
  end
61
66
 
62
67
  def json_headers
63
- {
68
+ headers = {
64
69
  content_type: :json,
65
70
  accept: :json,
66
71
  }
72
+ headers.merge!(authorization: "Bearer #{auth_token}") if type == :token
73
+ headers.merge!(args[:headers]) if args.key?(:headers)
74
+ headers
67
75
  end
68
76
 
69
77
  def execute(req)
70
- return req.execute if app_id.nil? || app_id.empty?
71
-
72
- ::ApiAuth.sign!(req, app_id, secret_key, with_http_method: true).execute
78
+ req = ::ApiAuth.sign!(req, app_id, secret_key, with_http_method: true).execute if type == :hmac
79
+ req.execute
73
80
  end
74
81
 
75
82
  def endpoint_uri(path = '')
76
- "#{url}/#{path.gsub(%r{^\/}, '')}"
83
+ return "#{url}/#{path.gsub(%r{^\/}, '')}" if path.present?
84
+
85
+ url
77
86
  end
78
87
  end
79
88
  end
@@ -19,7 +19,7 @@ module ApiAuth
19
19
  parsed.send(arg) if parsed.respond_to?(arg)
20
20
  end
21
21
 
22
- def to_json
22
+ def to_json(*_args)
23
23
  JSON.parse(response)
24
24
  rescue JSON::ParserError
25
25
  { 'error' => 'Bad JSON', 'body' => response.body }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ApiAuth
4
4
  module Client
5
- VERSION = '0.0.1'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_auth-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genaro Madrid
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: api-auth
@@ -185,7 +184,6 @@ files:
185
184
  homepage: https://github.com/Mifiel/api-auth-client
186
185
  licenses: []
187
186
  metadata: {}
188
- post_install_message:
189
187
  rdoc_options: []
190
188
  require_paths:
191
189
  - lib
@@ -200,9 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
198
  - !ruby/object:Gem::Version
201
199
  version: '0'
202
200
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.5.2.1
205
- signing_key:
201
+ rubygems_version: 3.6.9
206
202
  specification_version: 4
207
203
  summary: Base ApiClient
208
204
  test_files: []