bitcointerminal-rb 0.1.1 → 0.2.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: cc27d863f8b7fd125fd7673603ebfbde6b0aebced395d195fcbfb504f1ae636f
4
- data.tar.gz: ec7e74a7b15f775107f54644c280929406e7d0be09a8a0045218ff59aa2a7fa2
3
+ metadata.gz: 53b942ea259f1e0d2ce71c36092d43414d0dc8709fad4fb19ce27ba3fec1f1c0
4
+ data.tar.gz: 4e0ae79e7f6937f2df56eb4943c3a9235c672b232e13b06aa7258e0e5f82658b
5
5
  SHA512:
6
- metadata.gz: a5225f95cbfe223c78a312f6e03f5dc3bb4796adabff5cc9dfdc33e79f285cf923f1110977646e1d3b7707e8774b3fc2e9e25cdc1e98658b06cb08b3b4474d3d
7
- data.tar.gz: fa600064f2e28339c5e75f0b19d801cf7266f7c1337bd6a880ebf5f8873ce053638db019350645c672e95f7a6c63f09912e56bf5a9cbf88abd4de815744e3ca5
6
+ metadata.gz: 68bfe515dce5f39c48f27cdc2519034c97380fc0dc118d5cc0f1e282f6efbc0890299d392f5bb2ba8f2fc9d109095079f55c6b45eb6aa83faa5139b79732f24f
7
+ data.tar.gz: 2f8b36c2c40917328acd88fa51986d111313c1b30378e7a6509f5530cae334425c8f60858126a73855ded08d6dc3488759dc89991474b18a52a8e88a4dc80169
@@ -1,9 +1,12 @@
1
+ require 'uri'
2
+ require 'net/http'
1
3
  require 'json'
2
4
  require 'faraday'
3
5
  require 'base64'
4
6
  require 'active_support'
5
7
  require 'bitcointerminal/configurable'
6
- require 'bitcointerminal/authenticated_rest'
8
+ # require 'bitcointerminal/authenticated_rest'
9
+ require 'bitcointerminal/jwt_auth'
7
10
  require 'bitcointerminal/api_versions'
8
11
  require 'bitcointerminal/client'
9
12
 
@@ -1,7 +1,8 @@
1
1
  module Bitcointerminal
2
2
 
3
3
  class Client
4
- include Bitcointerminal::AuthenticatedConnection
4
+ # include Bitcointerminal::AuthenticatedConnection
5
+ include Bitcointerminal::JwtAuth
5
6
  include Bitcointerminal::Configurable
6
7
 
7
8
  def initialize
@@ -24,9 +24,13 @@ module Bitcointerminal
24
24
  attr_accessor :api_key, :secret_key
25
25
  attr_accessor :rest_open_timeout, :rest_timeout
26
26
  attr_accessor :api_version
27
+ #oauth / jwt tokens
28
+ attr_accessor :client_id, :client_secret
29
+ attr_accessor :audience, :grant_type, :token_url
30
+ #bearer
31
+ attr_accessor :authorization_token
27
32
 
28
33
  def initialize
29
- self.api_endpoint = "http://bitcointerminal-center-api.herokuapp.com/"
30
34
  self.debug = false
31
35
  self.rest_timeout = 30
32
36
  self.rest_open_timeout = 30
@@ -0,0 +1,106 @@
1
+ require 'json'
2
+ module Bitcointerminal
3
+
4
+ module JwtAuth
5
+
6
+ private
7
+ def authenticated_get(url, params = {})
8
+ new_rest_connection.get do |req|
9
+ req.url build_url(url)
10
+ params.each do |k,v|
11
+ req.params[k] = v
12
+ end
13
+ req.headers = req.headers = get_headers()
14
+ req.options.timeout = config.rest_timeout
15
+ req.options.open_timeout = config.rest_open_timeout
16
+ end
17
+ end
18
+
19
+
20
+ def authenticated_post(url, options = {})
21
+ body = options[:params] || {}
22
+ # p "x: #{url} #{body}"
23
+ new_rest_connection.post do |req|
24
+ req.url build_url(url)
25
+ req.headers = get_headers()
26
+ req.body = body.to_json
27
+ req.options.timeout = config.rest_timeout
28
+ req.options.open_timeout = config.rest_open_timeout
29
+ end
30
+ end
31
+
32
+ def authenticated_patch(url, options = {})
33
+ # p "authenticated_patch: #{url} #{options}"
34
+ body = options[:params] || {}
35
+ new_rest_connection.patch do |req|
36
+ req.url build_url(url)
37
+ req.headers = get_headers()
38
+ req.body = body.to_json
39
+ req.options.timeout = config.rest_timeout
40
+ req.options.open_timeout = config.rest_open_timeout
41
+ end
42
+ end
43
+
44
+
45
+ def get_headers()
46
+ headers = {}
47
+ headers['Content-Type'] = 'application/json'
48
+ #syscom
49
+ if config.authorization_token
50
+ headers['authorization'] = config.authorization_token
51
+ else
52
+ #auth0
53
+ bearer = get_bearer_token
54
+ headers['authorization'] = "#{bearer["token_type"]} #{bearer["access_token"]}"
55
+ end
56
+
57
+ puts "headers: #{headers}"
58
+ return headers
59
+ end
60
+
61
+ def get_bearer_token
62
+ url = URI(config.token_url)
63
+ http = Net::HTTP.new(url.host, url.port)
64
+ http.use_ssl = true
65
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
66
+ # http.verify_mode = OpenSSL::SSL::VERIFY_PEER
67
+ request = Net::HTTP::Post.new(url)
68
+ request["content-type"] = 'application/json'
69
+ request.body = "{\"client_id\":\"#{config.client_id}\",\"client_secret\":\"#{config.client_secret}\",\"audience\":\"#{config.audience}\",\"grant_type\":\"#{config.grant_type}\"}"
70
+ response = http.request(request)
71
+ JSON.parse(response.body)
72
+ end
73
+
74
+ def build_url(url)
75
+ # URI.join(config.api_endpoint, url).path
76
+ URI.join(config.api_endpoint, url).request_uri
77
+ end
78
+
79
+ def new_rest_connection
80
+ Faraday.new(url: base_api_endpoint) do |conn|
81
+ # conn.use Bitfinex::CustomErrors
82
+ conn.response :logger, Logger.new(STDOUT) , bodies: true if config.debug_connection
83
+ # conn.request :json
84
+ # conn.response :json, :content_type => /\bjson$/
85
+ # conn.response :logger
86
+ conn.adapter :net_http
87
+ end
88
+ end
89
+
90
+ def base_api_endpoint
91
+ # puts "config: #{config.api_endpoint}"
92
+ url = URI.parse(config.api_endpoint)
93
+ "#{url.scheme}://#{url.host}:#{url.port}"
94
+ end
95
+
96
+ def fullpath(path, query)
97
+ if query.empty?
98
+ path
99
+ else
100
+ "#{path}?#{query}"
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -1,3 +1,3 @@
1
1
  module Bitcointerminal
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcointerminal-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Plánský
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -56,6 +56,7 @@ files:
56
56
  - lib/bitcointerminal/authenticated_rest.rb
57
57
  - lib/bitcointerminal/client.rb
58
58
  - lib/bitcointerminal/configurable.rb
59
+ - lib/bitcointerminal/jwt_auth.rb
59
60
  - lib/bitcointerminal/v1/addresses.rb
60
61
  - lib/bitcointerminal/v1/crypto_addresses.rb
61
62
  - lib/bitcointerminal/v1/currencies.rb
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  version: '0'
81
82
  requirements: []
82
83
  rubyforge_project:
83
- rubygems_version: 2.7.6
84
+ rubygems_version: 2.7.7
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: Bitcointerminal API