bitcointerminal-rb 0.0.2
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 +7 -0
- data/lib/bitcointerminal-api-rb.rb +1 -0
- data/lib/bitcointerminal.rb +16 -0
- data/lib/bitcointerminal/api_versions.rb +4 -0
- data/lib/bitcointerminal/authenticated_rest.rb +120 -0
- data/lib/bitcointerminal/client.rb +15 -0
- data/lib/bitcointerminal/configurable.rb +39 -0
- data/lib/bitcointerminal/v1/addresses.rb +42 -0
- data/lib/bitcointerminal/v1/crypto_addresses.rb +11 -0
- data/lib/bitcointerminal/v1/currencies.rb +13 -0
- data/lib/bitcointerminal/version.rb +3 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6dca21ccf654ee147fd162a32653b261aed493441eb1ff1f2b30f3231ef01f1b
|
4
|
+
data.tar.gz: 919518f9f40faf5ef4adc3ca0aa045fb1cac9e7a62ecd2bca0b6f45f93b8ff1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23569a3e20dded0ff40dcb3957681090bfcf2243f434f5d39fc4a0ba45cf0b63d9ab28094f78feab01a710aae1ca2448f406471ca134ee6d6473fd20acc149f5
|
7
|
+
data.tar.gz: 59418ac54d389406566e4a5d01a26c9378e567788779c011c13415e465301ca362e6c2b12808afc7957351b173b0839141f2bbb0f5bfdcbd1a89862516016f14
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "./bitcointerminal.rb"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
require 'base64'
|
4
|
+
require 'active_support'
|
5
|
+
require 'bitcointerminal/configurable'
|
6
|
+
require 'bitcointerminal/authenticated_rest'
|
7
|
+
require 'bitcointerminal/api_versions'
|
8
|
+
require 'bitcointerminal/client'
|
9
|
+
|
10
|
+
require 'bitcointerminal/client'
|
11
|
+
|
12
|
+
|
13
|
+
# API Version 1
|
14
|
+
require 'bitcointerminal/v1/addresses'
|
15
|
+
require 'bitcointerminal/v1/crypto_addresses'
|
16
|
+
require 'bitcointerminal/v1/currencies'
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Bitcointerminal
|
3
|
+
|
4
|
+
module AuthenticatedConnection
|
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
|
+
full_path = fullpath(req.path, req.params.to_query)
|
14
|
+
req.headers = get_auth_headers(full_path)
|
15
|
+
|
16
|
+
req.options.timeout = config.rest_timeout
|
17
|
+
req.options.open_timeout = config.rest_open_timeout
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def authenticated_post(url, options = {})
|
23
|
+
body = options[:params] || {}
|
24
|
+
# p "x: #{url} #{body}"
|
25
|
+
new_rest_connection.post do |req|
|
26
|
+
req.url build_url(url)
|
27
|
+
req.headers = get_auth_headers(url,body)
|
28
|
+
req.body = body.to_json
|
29
|
+
req.options.timeout = config.rest_timeout
|
30
|
+
req.options.open_timeout = config.rest_open_timeout
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def authenticated_patch(url, options = {})
|
35
|
+
# p "authenticated_patch: #{url} #{options}"
|
36
|
+
body = options[:params] || {}
|
37
|
+
new_rest_connection.patch do |req|
|
38
|
+
req.url build_url(url)
|
39
|
+
req.headers = get_auth_headers(url,body)
|
40
|
+
req.body = body.to_json
|
41
|
+
req.options.timeout = config.rest_timeout
|
42
|
+
req.options.open_timeout = config.rest_open_timeout
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def get_auth_headers(url, params = {})
|
48
|
+
nonce = new_nonce
|
49
|
+
|
50
|
+
complete_url = build_url(url)
|
51
|
+
# p "url: #{url}, complete_url: #{complete_url}"
|
52
|
+
headers = {}
|
53
|
+
payload = build_payload(complete_url, params, nonce)
|
54
|
+
# puts "encode64: #{payload}"
|
55
|
+
headers['bterm-signature'] = sign(payload)
|
56
|
+
headers['bterm-apikey'] = config.api_key
|
57
|
+
headers['bterm-nonce'] = nonce
|
58
|
+
headers['Content-Type'] = 'application/json'
|
59
|
+
headers['Accept'] = 'application/json'
|
60
|
+
return headers
|
61
|
+
end
|
62
|
+
|
63
|
+
def build_payload(url, params = {}, nonce)
|
64
|
+
payload = {}
|
65
|
+
payload['nonce'] = nonce
|
66
|
+
payload['request'] = url
|
67
|
+
payload.merge!(params) if params
|
68
|
+
# pp "payload1: #{payload.inspect}"
|
69
|
+
# pp "payload: #{payload.to_json.encoding} #{payload['request'].encoding}"
|
70
|
+
# pp "fuck it: #{payload.to_json}"
|
71
|
+
Base64.strict_encode64(payload.to_json)
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_nonce
|
76
|
+
(Time.now.to_f * 10_000).to_i.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def sign(payload)
|
80
|
+
OpenSSL::HMAC.hexdigest('sha384', config.secret_key, payload)
|
81
|
+
end
|
82
|
+
|
83
|
+
def valid_key?
|
84
|
+
!! (config.api_key && config.secret_key)
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_url(url)
|
88
|
+
# URI.join(config.api_endpoint, url).path
|
89
|
+
URI.join(config.api_endpoint, url).request_uri
|
90
|
+
end
|
91
|
+
|
92
|
+
def new_rest_connection
|
93
|
+
Faraday.new(url: base_api_endpoint) do |conn|
|
94
|
+
# conn.use Bitfinex::CustomErrors
|
95
|
+
# conn.response :logger, Logger.new(STDOUT) , bodies: true if config.debug_connection
|
96
|
+
# conn.request :json
|
97
|
+
# conn.response :json, :content_type => /\bjson$/
|
98
|
+
conn.response :logger
|
99
|
+
conn.adapter :net_http
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def base_api_endpoint
|
104
|
+
# puts "config: #{config.api_endpoint}"
|
105
|
+
url = URI.parse(config.api_endpoint)
|
106
|
+
"#{url.scheme}://#{url.host}:#{url.port}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def fullpath(path, query)
|
110
|
+
if query.empty?
|
111
|
+
path
|
112
|
+
else
|
113
|
+
"#{path}?#{query}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bitcointerminal
|
2
|
+
|
3
|
+
class Client
|
4
|
+
include Bitcointerminal::AuthenticatedConnection
|
5
|
+
include Bitcointerminal::Configurable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
extend Bitcointerminal::V1::Addresses
|
9
|
+
extend Bitcointerminal::V1::CryptoAddresses
|
10
|
+
extend Bitcointerminal::V1::Currencies
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Bitcointerminal
|
2
|
+
module Configurable
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
def config
|
8
|
+
self.class.config
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def configure
|
13
|
+
yield config
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Configuration
|
23
|
+
attr_accessor :api_endpoint, :debug, :debug_connection
|
24
|
+
attr_accessor :api_key, :secret_key
|
25
|
+
attr_accessor :rest_open_timeout, :rest_timeout
|
26
|
+
attr_accessor :api_version
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
self.api_endpoint = "http://bitcointerminal-center-api.herokuapp.com/"
|
30
|
+
self.debug = false
|
31
|
+
self.rest_timeout = 30
|
32
|
+
self.rest_open_timeout = 30
|
33
|
+
self.debug_connection = false
|
34
|
+
self.api_version = 1
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Bitcointerminal
|
2
|
+
module V1::Addresses
|
3
|
+
|
4
|
+
def post_address(currency='BTC')
|
5
|
+
params = {currency: currency}
|
6
|
+
s = authenticated_post('/v1/addresses', params: params).body
|
7
|
+
JSON.parse(s,:symbolize_names => true)
|
8
|
+
# puts "authenticated_post: #{s}"
|
9
|
+
# JSON.parse(s,:symbolize_names => true)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def addresses_size
|
14
|
+
s = authenticated_get("/v1/addresses/size").body
|
15
|
+
JSON.parse(s,:symbolize_names => true)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def items()
|
21
|
+
s = authenticated_get('/v1/items').body
|
22
|
+
JSON.parse(s,:symbolize_names => true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def networks()
|
26
|
+
s = authenticated_get('/v1/networks/').body
|
27
|
+
JSON.parse(s,:symbolize_names => true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def post_item(name, description)
|
31
|
+
params = {name: name, description: description}
|
32
|
+
authenticated_post('/v1/items', params: params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def patch_item(id, name)
|
36
|
+
params = {name: name}
|
37
|
+
s = authenticated_patch("/v1/items/#{id}", params: params).body
|
38
|
+
JSON.parse(s,:symbolize_names => true)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Bitcointerminal
|
2
|
+
module V1::Currencies
|
3
|
+
def currencies()
|
4
|
+
s = authenticated_get("/v1/currencies").body
|
5
|
+
JSON.parse(s,:symbolize_names => true)
|
6
|
+
end
|
7
|
+
|
8
|
+
def symbols()
|
9
|
+
s = authenticated_get("/v1/symbols").body
|
10
|
+
JSON.parse(s,:symbolize_names => true)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitcointerminal-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Plánský
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.3
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.8.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.8.3
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.8.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.14.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.14.0
|
47
|
+
description: Simple Bitcointerminal API ruby wrapper
|
48
|
+
email: adamplansky@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/bitcointerminal-api-rb.rb
|
54
|
+
- lib/bitcointerminal.rb
|
55
|
+
- lib/bitcointerminal/api_versions.rb
|
56
|
+
- lib/bitcointerminal/authenticated_rest.rb
|
57
|
+
- lib/bitcointerminal/client.rb
|
58
|
+
- lib/bitcointerminal/configurable.rb
|
59
|
+
- lib/bitcointerminal/v1/addresses.rb
|
60
|
+
- lib/bitcointerminal/v1/crypto_addresses.rb
|
61
|
+
- lib/bitcointerminal/v1/currencies.rb
|
62
|
+
- lib/bitcointerminal/version.rb
|
63
|
+
homepage: http://rubygems.org/gems/bitcointerminal-rb
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.7.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Bitcointerminal API
|
87
|
+
test_files: []
|