coinbase_exchange 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/coinbase_exchange.rb +60 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc8263b315b0dbfb96f482155e6e49669984dcd3
|
4
|
+
data.tar.gz: bd4fa9626fa6cc6a447fd7905a89ed2aaae1eeb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10bb65fb31345ee868276f77079ad69ff30e5a70c9f153cf263ef3013b08d735f1b1920d22e82e940d35b317d49e1e48b0370b73bbd735133c825dc4135933e5
|
7
|
+
data.tar.gz: f637de00c3ddfe5a1f0f67e0c1cae03339895d613ac494dbefb927e2da41f3eafdb59d6cb6f979aa8e7f8c240a4d6c5e95dfc15c6be811408aa4e039d9a55a90
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'unirest'
|
2
|
+
require "base64"
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class CoinbaseExchangeSignatureMaker
|
7
|
+
def initialize(key, secret, passphrase)
|
8
|
+
@key = key
|
9
|
+
@secret = secret
|
10
|
+
@passphrase = passphrase
|
11
|
+
end
|
12
|
+
|
13
|
+
def signature(request_url='', body='', timestamp=nil, method='GET')
|
14
|
+
body = body.to_json if body.is_a?(Hash)
|
15
|
+
timestamp = Time.now.to_i if !timestamp
|
16
|
+
|
17
|
+
what = "#{timestamp}#{method.upcase}#{request_url}#{body}";
|
18
|
+
# create a sha256 hmac with the secret
|
19
|
+
secret = Base64.decode64(@secret)
|
20
|
+
hash = OpenSSL::HMAC.digest('sha256', secret, what)
|
21
|
+
Base64.strict_encode64(hash)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class CoinbaseExchange
|
26
|
+
API_URL = 'https://api.exchange.coinbase.com/'
|
27
|
+
|
28
|
+
def initialize(key, secret, passphrase)
|
29
|
+
@key = key
|
30
|
+
@secret = secret
|
31
|
+
@passphrase = passphrase
|
32
|
+
@coinbaseExchange = CoinbaseExchangeSignatureMaker.new(key, secret, passphrase)
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(method, uri, json=nil)
|
36
|
+
params = json.to_json if json
|
37
|
+
headers = {
|
38
|
+
'CB-ACCESS-SIGN'=> @coinbaseExchange.signature('/'+uri, params, nil, method),
|
39
|
+
'CB-ACCESS-TIMESTAMP'=> Time.now.to_i,
|
40
|
+
'CB-ACCESS-KEY'=> @key,
|
41
|
+
'CB-ACCESS-PASSPHRASE'=> @passphrase,
|
42
|
+
'Content-Type' => 'application/json'
|
43
|
+
}
|
44
|
+
if method == :get
|
45
|
+
r=Unirest.get(API_URL + uri, headers: headers)
|
46
|
+
elsif method == :post
|
47
|
+
r=Unirest.post(API_URL + uri, headers: headers, parameters: params)
|
48
|
+
end
|
49
|
+
yield r.body if block_given?
|
50
|
+
return r.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def get(uri, json=nil, &block)
|
54
|
+
request(:get, uri, json, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def post(uri, json=nil, &block)
|
58
|
+
request(:post, uri, json, &block)
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coinbase_exchange
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Silver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: unirest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.2
|
33
|
+
description: Coinbase Exchange ruby client
|
34
|
+
email: dannysilver3@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/coinbase_exchange.rb
|
40
|
+
homepage:
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.4.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Coinbase Exchange ruby client
|
64
|
+
test_files: []
|