coinbase 0.0.1 → 1.3.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.
Potentially problematic release.
This version of coinbase might be problematic. Click here for more details.
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +265 -0
- data/Rakefile +6 -0
- data/coinbase.gemspec +31 -0
- data/lib/coinbase/ca-coinbase.crt +629 -0
- data/lib/coinbase/client.rb +254 -0
- data/lib/coinbase/money.rb +13 -0
- data/lib/coinbase/version.rb +3 -0
- data/lib/coinbase.rb +5 -18
- data/spec/client_spec.rb +191 -0
- data/supported_currencies.json +163 -0
- metadata +83 -116
- checksums.yaml +0 -7
- data/lib/coinbase/address.rb +0 -127
- data/lib/coinbase/asset.rb +0 -20
- data/lib/coinbase/balance_map.rb +0 -48
- data/lib/coinbase/constants.rb +0 -38
- data/lib/coinbase/network.rb +0 -55
- data/lib/coinbase/transfer.rb +0 -153
- data/lib/coinbase/wallet.rb +0 -160
@@ -0,0 +1,254 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'hashie'
|
4
|
+
require 'money'
|
5
|
+
require 'time'
|
6
|
+
require 'securerandom'
|
7
|
+
|
8
|
+
module Coinbase
|
9
|
+
class Client
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
def initialize(api_key, api_secret, options={})
|
13
|
+
@api_key = api_key
|
14
|
+
@api_secret = api_secret
|
15
|
+
|
16
|
+
# defaults
|
17
|
+
options[:base_uri] ||= 'https://coinbase.com/api/v1'
|
18
|
+
@base_uri = options[:base_uri]
|
19
|
+
options[:format] ||= :json
|
20
|
+
options.each do |k,v|
|
21
|
+
self.class.send k, v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Account
|
26
|
+
|
27
|
+
def balance options={}
|
28
|
+
h = get '/account/balance', options
|
29
|
+
h['amount'].to_money(h['currency'])
|
30
|
+
end
|
31
|
+
|
32
|
+
def receive_address options={}
|
33
|
+
get '/account/receive_address', options
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_receive_address options={}
|
37
|
+
post '/account/generate_receive_address', options
|
38
|
+
end
|
39
|
+
|
40
|
+
# Buttons
|
41
|
+
|
42
|
+
def create_button name, price, description=nil, custom=nil, options={}
|
43
|
+
options[:button] ||= {}
|
44
|
+
options[:button][:name] ||= name
|
45
|
+
price = price.to_money unless price.is_a?(Money)
|
46
|
+
options[:button][:price_string] ||= price.to_f.to_s
|
47
|
+
options[:button][:price_currency_iso] ||= price.currency.iso_code
|
48
|
+
options[:button][:description] ||= description
|
49
|
+
options[:button][:custom] ||= custom
|
50
|
+
r = post '/buttons', options
|
51
|
+
if r.success?
|
52
|
+
r.embed_html = case options[:button_mode]
|
53
|
+
when 'page'
|
54
|
+
%[<a href="https://coinbase.com/checkouts/#{r.button.code}" target="_blank"><img alt="#{r.button.text}" src="https://coinbase.com/assets/buttons/#{r.button.style}.png"></a>]
|
55
|
+
when 'iframe'
|
56
|
+
%[<iframe src="https://coinbase.com/inline_payments/#{r.button.code}" style="width:500px;height:160px;border:none;box-shadow:0 1px 3px rgba(0,0,0,0.25);overflow:hidden;" scrolling="no" allowtransparency="true" frameborder="0"></iframe>]
|
57
|
+
else
|
58
|
+
%[<div class="coinbase-button" data-code="#{r.button.code}"></div><script src="https://coinbase.com/assets/button.js" type="text/javascript"></script>]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
r
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_order_for_button button_id
|
65
|
+
post "/buttons/#{button_id}/create_order"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Transactions
|
69
|
+
|
70
|
+
def transactions page=1
|
71
|
+
r = get '/transactions', {page: page}
|
72
|
+
r.transactions ||= []
|
73
|
+
r.transactions.each do |t|
|
74
|
+
if amt = t.transaction.amount
|
75
|
+
t.transaction.amount = amt.amount.to_money(amt.currency)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
r
|
79
|
+
end
|
80
|
+
|
81
|
+
def send_money to, amount, notes=nil, options={}
|
82
|
+
options[:transaction] ||= {}
|
83
|
+
options[:transaction][:to] ||= to
|
84
|
+
amount = amount.to_money unless amount.is_a?(Money)
|
85
|
+
options[:transaction][:amount_string] ||= amount.to_f.to_s
|
86
|
+
options[:transaction][:amount_currency_iso] ||= amount.currency.iso_code
|
87
|
+
options[:transaction][:notes] ||= notes
|
88
|
+
r = post '/transactions/send_money', options
|
89
|
+
if amt = r.transaction.amount
|
90
|
+
r.transaction.amount = amt.amount.to_money(amt.currency)
|
91
|
+
end
|
92
|
+
r
|
93
|
+
end
|
94
|
+
|
95
|
+
def request_money from, amount, notes=nil, options={}
|
96
|
+
options[:transaction] ||= {}
|
97
|
+
options[:transaction][:from] ||= from
|
98
|
+
amount = amount.to_money unless amount.is_a?(Money)
|
99
|
+
options[:transaction][:amount_string] ||= amount.to_f.to_s
|
100
|
+
options[:transaction][:amount_currency_iso] ||= amount.currency.iso_code
|
101
|
+
options[:transaction][:notes] ||= notes
|
102
|
+
r = post '/transactions/request_money', options
|
103
|
+
if amt = r.transaction.amount
|
104
|
+
r.transaction.amount = amt.amount.to_money(amt.currency)
|
105
|
+
end
|
106
|
+
r
|
107
|
+
end
|
108
|
+
|
109
|
+
def resend_request transaction_id
|
110
|
+
put "/transactions/#{transaction_id}/resend_request"
|
111
|
+
end
|
112
|
+
|
113
|
+
def cancel_request transaction_id
|
114
|
+
delete "/transactions/#{transaction_id}/cancel_request"
|
115
|
+
end
|
116
|
+
|
117
|
+
def complete_request transaction_id
|
118
|
+
put "/transactions/#{transaction_id}/complete_request"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Users
|
122
|
+
|
123
|
+
def create_user email, password=nil
|
124
|
+
password ||= SecureRandom.urlsafe_base64(12)
|
125
|
+
options = {user: {email: email, password: password}}
|
126
|
+
post '/users', options
|
127
|
+
end
|
128
|
+
|
129
|
+
# Prices
|
130
|
+
|
131
|
+
def buy_price qty=1
|
132
|
+
r = get '/prices/buy', {qty: qty}
|
133
|
+
r['amount'].to_money(r['currency'])
|
134
|
+
end
|
135
|
+
|
136
|
+
def sell_price qty=1
|
137
|
+
r = get '/prices/sell', {qty: qty}
|
138
|
+
r['amount'].to_money(r['currency'])
|
139
|
+
end
|
140
|
+
|
141
|
+
# Buys
|
142
|
+
|
143
|
+
def buy! qty
|
144
|
+
r = post '/buys', {qty: qty}
|
145
|
+
r = convert_money_objects(r)
|
146
|
+
r.transfer.payout_date = Time.parse(r.transfer.payout_date) rescue nil
|
147
|
+
r
|
148
|
+
end
|
149
|
+
|
150
|
+
# Sells
|
151
|
+
|
152
|
+
def sell! qty
|
153
|
+
r = post '/sells', {qty: qty}
|
154
|
+
r = convert_money_objects(r)
|
155
|
+
r.transfer.payout_date = Time.parse(r.transfer.payout_date) rescue nil
|
156
|
+
r
|
157
|
+
end
|
158
|
+
|
159
|
+
# Transfers
|
160
|
+
|
161
|
+
def transfers options={}
|
162
|
+
r = get '/transfers', options
|
163
|
+
r = convert_money_objects(r)
|
164
|
+
r.transfers.each do |t|
|
165
|
+
t.transfer.payout_date = Time.parse(t.transfer.payout_date) rescue nil
|
166
|
+
end
|
167
|
+
r
|
168
|
+
end
|
169
|
+
|
170
|
+
# Wrappers for the main HTTP verbs
|
171
|
+
|
172
|
+
def get(path, options={})
|
173
|
+
http_verb :get, path, options
|
174
|
+
end
|
175
|
+
|
176
|
+
def post(path, options={})
|
177
|
+
http_verb :post, path, options
|
178
|
+
end
|
179
|
+
|
180
|
+
def put(path, options={})
|
181
|
+
http_verb :put, path, options
|
182
|
+
end
|
183
|
+
|
184
|
+
def delete(path, options={})
|
185
|
+
http_verb :delete, path, options
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.whitelisted_cert_store
|
189
|
+
return @cert_store if @cert_store
|
190
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), 'ca-coinbase.crt'))
|
191
|
+
|
192
|
+
certs = [ [] ]
|
193
|
+
File.readlines(path).each{|line|
|
194
|
+
next if ["\n","#"].include?(line[0])
|
195
|
+
certs.last << line
|
196
|
+
certs << [] if line == "-----END CERTIFICATE-----\n"
|
197
|
+
}
|
198
|
+
|
199
|
+
@cert_store = OpenSSL::X509::Store.new
|
200
|
+
|
201
|
+
certs.each{|lines|
|
202
|
+
next if lines.empty?
|
203
|
+
cert = OpenSSL::X509::Certificate.new(lines.join)
|
204
|
+
@cert_store.add_cert(cert)
|
205
|
+
}
|
206
|
+
|
207
|
+
@cert_store
|
208
|
+
end
|
209
|
+
|
210
|
+
def ssl_options
|
211
|
+
{ verify: true, cert_store: self.class.whitelisted_cert_store }
|
212
|
+
end
|
213
|
+
|
214
|
+
def http_verb(verb, path, options={})
|
215
|
+
nonce = options[:nonce] || (Time.now.to_f * 1e6).to_i
|
216
|
+
message = nonce.to_s + @base_uri + path + options.to_json
|
217
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @api_secret, message)
|
218
|
+
|
219
|
+
headers = {
|
220
|
+
'ACCESS_KEY' => @api_key,
|
221
|
+
'ACCESS_SIGNATURE' => signature,
|
222
|
+
'ACCESS_NONCE' => nonce.to_s,
|
223
|
+
"Content-Type" => "application/json",
|
224
|
+
}
|
225
|
+
|
226
|
+
r = self.class.send(verb, path, {headers: headers, body: options.to_json}.merge(ssl_options))
|
227
|
+
hash = Hashie::Mash.new(JSON.parse(r.body))
|
228
|
+
raise Error.new(hash.error) if hash.error
|
229
|
+
raise Error.new(hash.errors.join(", ")) if hash.errors
|
230
|
+
hash
|
231
|
+
end
|
232
|
+
|
233
|
+
class Error < StandardError; end
|
234
|
+
|
235
|
+
private
|
236
|
+
|
237
|
+
def convert_money_objects obj
|
238
|
+
if obj.is_a?(Array)
|
239
|
+
obj.each_with_index do |o, i|
|
240
|
+
obj[i] = convert_money_objects(o)
|
241
|
+
end
|
242
|
+
elsif obj.is_a?(Hash)
|
243
|
+
if obj[:amount] && (obj[:currency] || obj[:currency_iso])
|
244
|
+
obj = obj[:amount].to_money((obj[:currency] || obj[:currency_iso]))
|
245
|
+
else
|
246
|
+
obj.each do |k,v|
|
247
|
+
obj[k] = convert_money_objects(v)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
obj
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
curr = {
|
2
|
+
:priority => 1,
|
3
|
+
:iso_code => "BTC",
|
4
|
+
:name => "Bitcoin",
|
5
|
+
:symbol => "BTC",
|
6
|
+
:subunit => "Satoshi",
|
7
|
+
:subunit_to_unit => 100000000,
|
8
|
+
:separator => ".",
|
9
|
+
:delimiter => ","
|
10
|
+
}
|
11
|
+
|
12
|
+
Money::Currency.register(curr)
|
13
|
+
Money.default_currency = Money::Currency.new("BTC")
|
data/lib/coinbase.rb
CHANGED
@@ -1,18 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require_relative 'coinbase/constants'
|
7
|
-
require_relative 'coinbase/network'
|
8
|
-
require_relative 'coinbase/transfer'
|
9
|
-
require_relative 'coinbase/wallet'
|
10
|
-
require 'dotenv'
|
11
|
-
|
12
|
-
# The Coinbase SDK.
|
13
|
-
module Coinbase
|
14
|
-
# Initializes the Coinbase SDK.
|
15
|
-
def self.init
|
16
|
-
Dotenv.load
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require "json"
|
2
|
+
require "money"
|
3
|
+
require "coinbase/version"
|
4
|
+
require "coinbase/money"
|
5
|
+
require "coinbase/client"
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
require 'coinbase'
|
3
|
+
|
4
|
+
describe Coinbase::Client do
|
5
|
+
BASE_URI = 'http://fake.com/api/v1' # switching to http (instead of https) seems to help FakeWeb
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@c = Coinbase::Client.new 'api key', 'api secret', {base_uri: BASE_URI}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Auth and Errors
|
12
|
+
|
13
|
+
it "raise errors" do
|
14
|
+
fake :get, '/account/balance', {error: "some error"}
|
15
|
+
expect{ @c.balance }.to raise_error(Coinbase::Client::Error, 'some error')
|
16
|
+
fake :get, '/account/balance', {errors: ["some", "error"]}
|
17
|
+
expect{ @c.balance }.to raise_error(Coinbase::Client::Error, 'some, error')
|
18
|
+
end
|
19
|
+
|
20
|
+
# Account
|
21
|
+
|
22
|
+
it "should get balance" do
|
23
|
+
fake :get, '/account/balance', {amount: "50.00000000", currency: 'BTC'}
|
24
|
+
@c.balance.should == 50.to_money('BTC')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get a receive address" do
|
28
|
+
fake :get, '/account/receive_address', {address: "muVu2JZo8PbewBHRp6bpqFvVD87qvqEHWA", callback_url: nil}
|
29
|
+
a = @c.receive_address
|
30
|
+
a.address.should == "muVu2JZo8PbewBHRp6bpqFvVD87qvqEHWA"
|
31
|
+
a.callback_url.should == nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should generate new receive addresses" do
|
35
|
+
fake :post, '/account/generate_receive_address', {address: "mmxJyTdxHUJUDoptwLHAGxLEd1rAxDJ7EV", callback_url: "http://example.com/callback"}
|
36
|
+
a = @c.generate_receive_address
|
37
|
+
a.address.should == "mmxJyTdxHUJUDoptwLHAGxLEd1rAxDJ7EV"
|
38
|
+
a.callback_url.should == "http://example.com/callback"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Buttons
|
42
|
+
|
43
|
+
it "should create a new button" do
|
44
|
+
response = {:success=>true, :button=>{:code=>"93865b9cae83706ae59220c013bc0afd", :type=>"buy_now", :style=>"custom_large", :text=>"Pay With Bitcoin", :name=>"Order 123", :description=>"Sample description", :custom=>"Order123", :price=>{:cents=>123, :currency_iso=>"BTC"}}}
|
45
|
+
fake :post, '/buttons', response
|
46
|
+
r = @c.create_button "Order 123", 1.23, "Sample description"
|
47
|
+
r.success?.should == true
|
48
|
+
r.button.name.should == "Order 123"
|
49
|
+
r.embed_html.should == %[<div class="coinbase-button" data-code="93865b9cae83706ae59220c013bc0afd"></div><script src="https://coinbase.com/assets/button.js" type="text/javascript"></script>]
|
50
|
+
|
51
|
+
r = @c.create_button "Order 123", 1.23, "Sample description", nil, button_mode: 'page'
|
52
|
+
r.success?.should == true
|
53
|
+
r.button.name.should == "Order 123"
|
54
|
+
r.embed_html.should == %[<a href="https://coinbase.com/checkouts/93865b9cae83706ae59220c013bc0afd" target="_blank"><img alt="Pay With Bitcoin" src="https://coinbase.com/assets/buttons/custom_large.png"></a>]
|
55
|
+
|
56
|
+
r = @c.create_button "Order 123", 1.23, "Sample description", nil, button_mode: 'iframe'
|
57
|
+
r.success?.should == true
|
58
|
+
r.button.name.should == "Order 123"
|
59
|
+
r.embed_html.should == %[<iframe src="https://coinbase.com/inline_payments/93865b9cae83706ae59220c013bc0afd" style="width:500px;height:160px;border:none;box-shadow:0 1px 3px rgba(0,0,0,0.25);overflow:hidden;" scrolling="no" allowtransparency="true" frameborder="0"></iframe>]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should create order for the button" do
|
63
|
+
response = {"success"=>true, "order"=>{"id"=>"UAHXEK24", "created_at"=>"2013-12-13T01:15:56-08:00", "status"=>"new", "total_btc"=>{"cents"=>123, "currency_iso"=>"BTC"}, "total_native"=>{"cents"=>123, "currency_iso"=>"BTC"}, "custom"=>"Order123", "receive_address"=>"1EWxf61QGAkQDNUDq6XynH2PdFRyZUm111", "button"=>{"type"=>"buy_now", "name"=>"Order 123", "description"=>"Sample description", "id"=>"93865b9cae83706ae59220c013bc0afd"}, "transaction"=>nil}}
|
64
|
+
fake :post, '/buttons/93865b9cae83706ae59220c013bc0afd/create_order', response
|
65
|
+
r = @c.create_order_for_button "93865b9cae83706ae59220c013bc0afd"
|
66
|
+
r.order.button.id.should == "93865b9cae83706ae59220c013bc0afd"
|
67
|
+
r.order.status.should == "new"
|
68
|
+
end
|
69
|
+
|
70
|
+
# Transactions
|
71
|
+
|
72
|
+
it "should get transaction list" do
|
73
|
+
response = {"current_user"=>{"id"=>"5011f33df8182b142400000e", "email"=>"user2@example.com", "name"=>"user2@example.com"}, "balance"=>{"amount"=>"50.00000000", "currency"=>"BTC"}, "total_count"=>2, "num_pages"=>1, "current_page"=>1, "transactions"=>[{"transaction"=>{"id"=>"5018f833f8182b129c00002f", "created_at"=>"2012-08-01T02:34:43-07:00", "amount"=>{"amount"=>"-1.10000000", "currency"=>"BTC"}, "request"=>true, "status"=>"pending", "sender"=>{"id"=>"5011f33df8182b142400000e", "name"=>"User Two", "email"=>"user2@example.com"}, "recipient"=>{"id"=>"5011f33df8182b142400000a", "name"=>"User One", "email"=>"user1@example.com"}}}, {"transaction"=>{"id"=>"5018f833f8182b129c00002e", "created_at"=>"2012-08-01T02:36:43-07:00", "hsh" => "9d6a7d1112c3db9de5315b421a5153d71413f5f752aff75bf504b77df4e646a3", "amount"=>{"amount"=>"-1.00000000", "currency"=>"BTC"}, "request"=>false, "status"=>"complete", "sender"=>{"id"=>"5011f33df8182b142400000e", "name"=>"User Two", "email"=>"user2@example.com"}, "recipient_address"=>"37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare"}}]}
|
74
|
+
fake :get, '/transactions', response
|
75
|
+
r = @c.transactions
|
76
|
+
r.transactions.first.transaction.id.should == '5018f833f8182b129c00002f'
|
77
|
+
r.transactions.last.transaction.hsh.should == '9d6a7d1112c3db9de5315b421a5153d71413f5f752aff75bf504b77df4e646a3'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not fail if there are no transactions" do
|
81
|
+
response = {"current_user"=>{"id"=>"5011f33df8182b142400000e", "email"=>"user2@example.com", "name"=>"user2@example.com"}, "balance"=>{"amount"=>"0.00000000", "currency"=>"BTC"}, "total_count"=>0, "num_pages"=>0, "current_page"=>1}
|
82
|
+
fake :get, '/transactions', response
|
83
|
+
r = @c.transactions
|
84
|
+
r.transactions.should_not be_nil
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should send money" do
|
88
|
+
response = {"success"=>true, "transaction"=>{"id"=>"501a1791f8182b2071000087", "created_at"=>"2012-08-01T23:00:49-07:00", "notes"=>"Sample transaction for you!", "amount"=>{"amount"=>"-1.23400000", "currency"=>"BTC"}, "request"=>false, "status"=>"pending", "sender"=>{"id"=>"5011f33df8182b142400000e", "name"=>"User Two", "email"=>"user2@example.com"}, "recipient"=>{"id"=>"5011f33df8182b142400000a", "name"=>"User One", "email"=>"user1@example.com"}}}
|
89
|
+
fake :post, '/transactions/send_money', response
|
90
|
+
r = @c.send_money "user1@example.com", 1.2345, "Sample transaction for you"
|
91
|
+
r.success.should == true
|
92
|
+
r.transaction.id.should == '501a1791f8182b2071000087'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should request money" do
|
96
|
+
response = {"success"=>true, "transaction"=>{"id"=>"501a3554f8182b2754000003", "created_at"=>"2012-08-02T01:07:48-07:00", "notes"=>"Sample request for you!", "amount"=>{"amount"=>"1.23400000", "currency"=>"BTC"}, "request"=>true, "status"=>"pending", "sender"=>{"id"=>"5011f33df8182b142400000a", "name"=>"User One", "email"=>"user1@example.com"}, "recipient"=>{"id"=>"5011f33df8182b142400000e", "name"=>"User Two", "email"=>"user2@example.com"}}}
|
97
|
+
fake :post, '/transactions/request_money', response
|
98
|
+
r = @c.request_money "user1@example.com", 1.2345, "Sample transaction for you"
|
99
|
+
r.success.should == true
|
100
|
+
r.transaction.id.should == '501a3554f8182b2754000003'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should resend requests" do
|
104
|
+
response = {"success"=>true}
|
105
|
+
fake :put, "/transactions/501a3554f8182b2754000003/resend_request", response
|
106
|
+
r = @c.resend_request '501a3554f8182b2754000003'
|
107
|
+
r.success.should == true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should cancel requests" do
|
111
|
+
response = {"success"=>true}
|
112
|
+
fake :delete, "/transactions/501a3554f8182b2754000003/cancel_request", response
|
113
|
+
r = @c.cancel_request '501a3554f8182b2754000003'
|
114
|
+
r.success.should == true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should resend requests" do
|
118
|
+
response = {"success"=>true}
|
119
|
+
fake :put, "/transactions/501a3554f8182b2754000003/complete_request", response
|
120
|
+
r = @c.complete_request '501a3554f8182b2754000003'
|
121
|
+
r.success.should == true
|
122
|
+
end
|
123
|
+
|
124
|
+
# Users
|
125
|
+
|
126
|
+
it "should let you create users" do
|
127
|
+
response = {"success"=>true, "user"=>{"id"=>"501a3d22f8182b2754000011", "name"=>"New User", "email"=>"newuser@example.com", "receive_address"=>"mpJKwdmJKYjiyfNo26eRp4j6qGwuUUnw9x"}}
|
128
|
+
fake :post, "/users", response
|
129
|
+
r = @c.create_user "newuser@example.com"
|
130
|
+
r.success.should == true
|
131
|
+
r.user.email.should == "newuser@example.com"
|
132
|
+
r.user.receive_address.should == "mpJKwdmJKYjiyfNo26eRp4j6qGwuUUnw9x"
|
133
|
+
end
|
134
|
+
|
135
|
+
# Prices
|
136
|
+
|
137
|
+
it "should let you get buy and sell prices" do
|
138
|
+
response = {"amount"=>"13.84", "currency"=>"USD"}
|
139
|
+
fake :get, "/prices/buy", response
|
140
|
+
r = @c.buy_price 1
|
141
|
+
r.to_f.should == 13.84
|
142
|
+
|
143
|
+
fake :get, "/prices/sell", response
|
144
|
+
r = @c.sell_price 1
|
145
|
+
r.to_f.should == 13.84
|
146
|
+
end
|
147
|
+
|
148
|
+
# Buys
|
149
|
+
|
150
|
+
it "should let you buy bitcoin" do
|
151
|
+
response = {"success"=>true, "transfer"=>{"_type"=>"AchDebit", "code"=>"6H7GYLXZ", "created_at"=>"2013-01-28T16:08:58-08:00", "fees"=>{"coinbase"=>{"cents"=>14, "currency_iso"=>"USD"}, "bank"=>{"cents"=>15, "currency_iso"=>"USD"}}, "status"=>"created", "payout_date"=>"2013-02-01T18:00:00-08:00", "btc"=>{"amount"=>"1.00000000", "currency"=>"BTC"}, "subtotal"=>{"amount"=>"13.55", "currency"=>"USD"}, "total"=>{"amount"=>"13.84", "currency"=>"USD"}}}
|
152
|
+
fake :post, "/buys", response
|
153
|
+
r = @c.buy! 1
|
154
|
+
r.success?.should == true
|
155
|
+
r.transfer.code.should == '6H7GYLXZ'
|
156
|
+
r.transfer.status.should == 'created'
|
157
|
+
r.transfer.btc.should == 1.to_money
|
158
|
+
end
|
159
|
+
|
160
|
+
# Sells
|
161
|
+
|
162
|
+
it "should let you sell bitcoin" do
|
163
|
+
response = {"success"=>true, "transfer"=>{"_type"=>"AchCredit", "code"=>"RD2OC8AL", "created_at"=>"2013-01-28T16:32:35-08:00", "fees"=>{"coinbase"=>{"cents"=>14, "currency_iso"=>"USD"}, "bank"=>{"cents"=>15, "currency_iso"=>"USD"}}, "status"=>"created", "payout_date"=>"2013-02-01T18:00:00-08:00", "btc"=>{"amount"=>"1.00000000", "currency"=>"BTC"}, "subtotal"=>{"amount"=>"13.50", "currency"=>"USD"}, "total"=>{"amount"=>"13.21", "currency"=>"USD"}}}
|
164
|
+
fake :post, "/sells", response
|
165
|
+
r = @c.sell! 1
|
166
|
+
r.success?.should == true
|
167
|
+
r.transfer.code.should == 'RD2OC8AL'
|
168
|
+
r.transfer.status.should == 'created'
|
169
|
+
r.transfer.btc.should == 1.to_money
|
170
|
+
end
|
171
|
+
|
172
|
+
# Transfers
|
173
|
+
|
174
|
+
it "should get recent transfers" do
|
175
|
+
response = {"transfers" => [{"transfer" => {"type" => "Buy", "code" => "QPCUCZHR", "created_at" => "2013-02-27T23:28:18-08:00", "fees" => {"coinbase" => {"cents" => 14, "currency_iso" => "USD"}, "bank" => {"cents" => 15, "currency_iso" => "USD"} }, "payout_date" => "2013-03-05T18:00:00-08:00", "transaction_id" => "5011f33df8182b142400000e", "status" => "Pending", "btc" => {"amount" => "1.00000000", "currency" => "BTC"}, "subtotal" => {"amount" => "13.55", "currency" => "USD"}, "total" => {"amount" => "13.84", "currency" => "USD"}, "description" => "Paid for with $13.84 from Test xxxxx3111."} } ], "total_count" => 1, "num_pages" => 1, "current_page" => 1 }
|
176
|
+
fake :get, "/transfers", response
|
177
|
+
r = @c.transfers
|
178
|
+
t = r.transfers.first.transfer
|
179
|
+
t.type.should == "Buy"
|
180
|
+
t.code.should == "QPCUCZHR"
|
181
|
+
t.status.should == "Pending"
|
182
|
+
t.btc.should == 1.to_money
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
def fake method, path, body
|
189
|
+
FakeWeb.register_uri(method, "#{BASE_URI}#{path}", body: body.to_json)
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
{
|
2
|
+
"AED": "United Arab Emirates Dirham",
|
3
|
+
"AFN": "Afghan Afghani",
|
4
|
+
"ALL": "Albanian Lek",
|
5
|
+
"AMD": "Armenian Dram",
|
6
|
+
"ANG": "Netherlands Antillean Guilder",
|
7
|
+
"AOA": "Angolan Kwanza",
|
8
|
+
"ARS": "Argentine Peso",
|
9
|
+
"AUD": "Australian Dollar",
|
10
|
+
"AWG": "Aruban Florin",
|
11
|
+
"AZN": "Azerbaijani Manat",
|
12
|
+
"BAM": "Bosnia-Herzegovina Convertible Mark",
|
13
|
+
"BBD": "Barbadian Dollar",
|
14
|
+
"BDT": "Bangladeshi Taka",
|
15
|
+
"BGN": "Bulgarian Lev",
|
16
|
+
"BHD": "Bahraini Dinar",
|
17
|
+
"BIF": "Burundian Franc",
|
18
|
+
"BMD": "Bermudan Dollar",
|
19
|
+
"BND": "Brunei Dollar",
|
20
|
+
"BOB": "Bolivian Boliviano",
|
21
|
+
"BRL": "Brazilian Real",
|
22
|
+
"BSD": "Bahamian Dollar",
|
23
|
+
"BTC": "Bitcoin",
|
24
|
+
"BTN": "Bhutanese Ngultrum",
|
25
|
+
"BWP": "Botswanan Pula",
|
26
|
+
"BYR": "Belarusian Ruble",
|
27
|
+
"BZD": "Belize Dollar",
|
28
|
+
"CAD": "Canadian Dollar",
|
29
|
+
"CDF": "Congolese Franc",
|
30
|
+
"CHF": "Swiss Franc",
|
31
|
+
"CLF": "Chilean Unit of Account (UF)",
|
32
|
+
"CLP": "Chilean Peso",
|
33
|
+
"CNY": "Chinese Yuan",
|
34
|
+
"COP": "Colombian Peso",
|
35
|
+
"CRC": "Costa Rican Colón",
|
36
|
+
"CUP": "Cuban Peso",
|
37
|
+
"CVE": "Cape Verdean Escudo",
|
38
|
+
"CZK": "Czech Republic Koruna",
|
39
|
+
"DJF": "Djiboutian Franc",
|
40
|
+
"DKK": "Danish Krone",
|
41
|
+
"DOP": "Dominican Peso",
|
42
|
+
"DZD": "Algerian Dinar",
|
43
|
+
"EEK": "Estonian Kroon",
|
44
|
+
"EGP": "Egyptian Pound",
|
45
|
+
"ETB": "Ethiopian Birr",
|
46
|
+
"EUR": "Euro",
|
47
|
+
"FJD": "Fijian Dollar",
|
48
|
+
"FKP": "Falkland Islands Pound",
|
49
|
+
"GBP": "British Pound Sterling",
|
50
|
+
"GEL": "Georgian Lari",
|
51
|
+
"GHS": "Ghanaian Cedi",
|
52
|
+
"GIP": "Gibraltar Pound",
|
53
|
+
"GMD": "Gambian Dalasi",
|
54
|
+
"GNF": "Guinean Franc",
|
55
|
+
"GTQ": "Guatemalan Quetzal",
|
56
|
+
"GYD": "Guyanaese Dollar",
|
57
|
+
"HKD": "Hong Kong Dollar",
|
58
|
+
"HNL": "Honduran Lempira",
|
59
|
+
"HRK": "Croatian Kuna",
|
60
|
+
"HTG": "Haitian Gourde",
|
61
|
+
"HUF": "Hungarian Forint",
|
62
|
+
"IDR": "Indonesian Rupiah",
|
63
|
+
"ILS": "Israeli New Sheqel",
|
64
|
+
"INR": "Indian Rupee",
|
65
|
+
"IQD": "Iraqi Dinar",
|
66
|
+
"IRR": "Iranian Rial",
|
67
|
+
"ISK": "Icelandic Króna",
|
68
|
+
"JEP": "Jersey Pound",
|
69
|
+
"JMD": "Jamaican Dollar",
|
70
|
+
"JOD": "Jordanian Dinar",
|
71
|
+
"JPY": "Japanese Yen",
|
72
|
+
"KES": "Kenyan Shilling",
|
73
|
+
"KGS": "Kyrgystani Som",
|
74
|
+
"KHR": "Cambodian Riel",
|
75
|
+
"KMF": "Comorian Franc",
|
76
|
+
"KPW": "North Korean Won",
|
77
|
+
"KRW": "South Korean Won",
|
78
|
+
"KWD": "Kuwaiti Dinar",
|
79
|
+
"KYD": "Cayman Islands Dollar",
|
80
|
+
"KZT": "Kazakhstani Tenge",
|
81
|
+
"LAK": "Laotian Kip",
|
82
|
+
"LBP": "Lebanese Pound",
|
83
|
+
"LKR": "Sri Lankan Rupee",
|
84
|
+
"LRD": "Liberian Dollar",
|
85
|
+
"LSL": "Lesotho Loti",
|
86
|
+
"LTL": "Lithuanian Litas",
|
87
|
+
"LVL": "Latvian Lats",
|
88
|
+
"LYD": "Libyan Dinar",
|
89
|
+
"MAD": "Moroccan Dirham",
|
90
|
+
"MDL": "Moldovan Leu",
|
91
|
+
"MGA": "Malagasy Ariary",
|
92
|
+
"MKD": "Macedonian Denar",
|
93
|
+
"MMK": "Myanma Kyat",
|
94
|
+
"MNT": "Mongolian Tugrik",
|
95
|
+
"MOP": "Macanese Pataca",
|
96
|
+
"MRO": "Mauritanian Ouguiya",
|
97
|
+
"MUR": "Mauritian Rupee",
|
98
|
+
"MVR": "Maldivian Rufiyaa",
|
99
|
+
"MWK": "Malawian Kwacha",
|
100
|
+
"MXN": "Mexican Peso",
|
101
|
+
"MYR": "Malaysian Ringgit",
|
102
|
+
"MZN": "Mozambican Metical",
|
103
|
+
"NAD": "Namibian Dollar",
|
104
|
+
"NGN": "Nigerian Naira",
|
105
|
+
"NIO": "Nicaraguan Córdoba",
|
106
|
+
"NOK": "Norwegian Krone",
|
107
|
+
"NPR": "Nepalese Rupee",
|
108
|
+
"NZD": "New Zealand Dollar",
|
109
|
+
"OMR": "Omani Rial",
|
110
|
+
"PAB": "Panamanian Balboa",
|
111
|
+
"PEN": "Peruvian Nuevo Sol",
|
112
|
+
"PGK": "Papua New Guinean Kina",
|
113
|
+
"PHP": "Philippine Peso",
|
114
|
+
"PKR": "Pakistani Rupee",
|
115
|
+
"PLN": "Polish Zloty",
|
116
|
+
"PYG": "Paraguayan Guarani",
|
117
|
+
"QAR": "Qatari Rial",
|
118
|
+
"RON": "Romanian Leu",
|
119
|
+
"RSD": "Serbian Dinar",
|
120
|
+
"RUB": "Russian Ruble",
|
121
|
+
"RWF": "Rwandan Franc",
|
122
|
+
"SAR": "Saudi Riyal",
|
123
|
+
"SBD": "Solomon Islands Dollar",
|
124
|
+
"SCR": "Seychellois Rupee",
|
125
|
+
"SDG": "Sudanese Pound",
|
126
|
+
"SEK": "Swedish Krona",
|
127
|
+
"SGD": "Singapore Dollar",
|
128
|
+
"SHP": "Saint Helena Pound",
|
129
|
+
"SLL": "Sierra Leonean Leone",
|
130
|
+
"SOS": "Somali Shilling",
|
131
|
+
"SRD": "Surinamese Dollar",
|
132
|
+
"STD": "São Tomé and Príncipe Dobra",
|
133
|
+
"SVC": "Salvadoran Colón",
|
134
|
+
"SYP": "Syrian Pound",
|
135
|
+
"SZL": "Swazi Lilangeni",
|
136
|
+
"THB": "Thai Baht",
|
137
|
+
"TJS": "Tajikistani Somoni",
|
138
|
+
"TMT": "Turkmenistani Manat",
|
139
|
+
"TND": "Tunisian Dinar",
|
140
|
+
"TOP": "Tongan Paʻanga",
|
141
|
+
"TRY": "Turkish Lira",
|
142
|
+
"TTD": "Trinidad and Tobago Dollar",
|
143
|
+
"TWD": "New Taiwan Dollar",
|
144
|
+
"TZS": "Tanzanian Shilling",
|
145
|
+
"UAH": "Ukrainian Hryvnia",
|
146
|
+
"UGX": "Ugandan Shilling",
|
147
|
+
"USD": "United States Dollar",
|
148
|
+
"UYU": "Uruguayan Peso",
|
149
|
+
"UZS": "Uzbekistan Som",
|
150
|
+
"VEF": "Venezuelan Bolívar",
|
151
|
+
"VND": "Vietnamese Dong",
|
152
|
+
"VUV": "Vanuatu Vatu",
|
153
|
+
"WST": "Samoan Tala",
|
154
|
+
"XAF": "CFA Franc BEAC",
|
155
|
+
"XCD": "East Caribbean Dollar",
|
156
|
+
"XDR": "Special Drawing Rights",
|
157
|
+
"XOF": "CFA Franc BCEAO",
|
158
|
+
"XPF": "CFP Franc",
|
159
|
+
"YER": "Yemeni Rial",
|
160
|
+
"ZAR": "South African Rand",
|
161
|
+
"ZMK": "Zambian Kwacha",
|
162
|
+
"ZWL": "Zimbabwean Dollar"
|
163
|
+
}
|