better-coinbase 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +336 -0
- data/Rakefile +6 -0
- data/better-coinbase.gemspec +33 -0
- data/lib/better-coinbase.rb +5 -0
- data/lib/better-coinbase/ca-coinbase.crt +629 -0
- data/lib/better-coinbase/client.rb +315 -0
- data/lib/better-coinbase/oauth_client.rb +77 -0
- data/lib/better-coinbase/version.rb +3 -0
- data/spec/client_spec.rb +429 -0
- data/spec/oauth_client_spec.rb +81 -0
- data/supported_currencies.json +163 -0
- metadata +185 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
require 'better-coinbase'
|
3
|
+
|
4
|
+
describe BetterCoinbase::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
|
+
@credentials = {
|
9
|
+
:token => 'access_token',
|
10
|
+
:refresh_token => 'refresh_token',
|
11
|
+
:expires_at => Time.now.to_i + 100
|
12
|
+
}
|
13
|
+
@client_options = {
|
14
|
+
base_uri: BASE_URI,
|
15
|
+
authorize_url: "http://fake.com/oauth/authorize",
|
16
|
+
token_url: "http://fake.com/oauth/token"
|
17
|
+
}
|
18
|
+
@c = BetterCoinbase::OAuthClient.new 'api key', 'api secret', @credentials, @client_options
|
19
|
+
FakeWeb.allow_net_connect = false
|
20
|
+
end
|
21
|
+
|
22
|
+
# Auth and Errors
|
23
|
+
|
24
|
+
it "raise errors" do
|
25
|
+
fake :get, '/account/balance', {error: "some error"}
|
26
|
+
expect{ @c.balance }.to raise_error(BetterCoinbase::Client::Error, 'some error')
|
27
|
+
fake :get, '/account/balance', {errors: ["some", "error"]}
|
28
|
+
expect{ @c.balance }.to raise_error(BetterCoinbase::Client::Error, 'some, error')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should get balance" do
|
32
|
+
fake :get, '/account/balance', {amount: "50.00000000", currency: 'BTC'}
|
33
|
+
@c.balance.should == 50.to_money('BTC')
|
34
|
+
|
35
|
+
# Ensure we're passing the access token
|
36
|
+
FakeWeb.last_request['Authorization'].should == 'Bearer access_token'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should support pagination" do
|
40
|
+
response = {"transfers" => [{"transfer" => {"type" => "Buy", "code" => "QPCUCZHL", "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 }
|
41
|
+
fake :get, "/transfers?page=3", response
|
42
|
+
r = @c.transfers :page => 3
|
43
|
+
t = r.transfers.first.transfer
|
44
|
+
t.type.should == "Buy"
|
45
|
+
t.code.should == "QPCUCZHL"
|
46
|
+
t.status.should == "Pending"
|
47
|
+
t.btc.should == 1.to_money("BTC")
|
48
|
+
FakeWeb.last_request.path.should include("page=3")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should refresh an expired token" do
|
52
|
+
credentials = @credentials.dup
|
53
|
+
credentials[:expires_at] = Time.now.to_i - 100
|
54
|
+
c = BetterCoinbase::OAuthClient.new 'api key', 'api secret', credentials, @client_options
|
55
|
+
|
56
|
+
|
57
|
+
token_refresh_response = {
|
58
|
+
:access_token => "new_access_token",
|
59
|
+
:refresh_token => "new_refresh_token",
|
60
|
+
:token_type => "bearer",
|
61
|
+
:expires_in => 7200,
|
62
|
+
}
|
63
|
+
FakeWeb.register_uri(:post, @client_options[:token_url], body: token_refresh_response.to_json, :content_type => "application/json")
|
64
|
+
|
65
|
+
fake :get, '/account/balance', {amount: "50.00000000", currency: 'BTC'}
|
66
|
+
c.balance.should == 50.to_money('BTC')
|
67
|
+
|
68
|
+
# Ensure we're passing the new access token
|
69
|
+
FakeWeb.last_request['Authorization'].should == 'Bearer new_access_token'
|
70
|
+
|
71
|
+
# Make sure we can retrieve the new credentials for persistance after a refresh
|
72
|
+
c.credentials[:refresh_token].should == "new_refresh_token"
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def fake method, path, body
|
78
|
+
FakeWeb.register_uri(method, "#{BASE_URI}#{path}", body: body.to_json)
|
79
|
+
end
|
80
|
+
|
81
|
+
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
|
+
}
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: better-coinbase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Larisch, Brian Armstrong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fakeweb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multi_json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.4
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: money
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: monetize
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.3.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: hashie
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.2.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: oauth2
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
139
|
+
description: The Coinbase API, wrapped, maintained, and better.
|
140
|
+
email: root@jameslarisch.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- .gitignore
|
146
|
+
- .travis.yml
|
147
|
+
- Gemfile
|
148
|
+
- LICENSE.txt
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- better-coinbase.gemspec
|
152
|
+
- lib/better-coinbase.rb
|
153
|
+
- lib/better-coinbase/ca-coinbase.crt
|
154
|
+
- lib/better-coinbase/client.rb
|
155
|
+
- lib/better-coinbase/oauth_client.rb
|
156
|
+
- lib/better-coinbase/version.rb
|
157
|
+
- spec/client_spec.rb
|
158
|
+
- spec/oauth_client_spec.rb
|
159
|
+
- supported_currencies.json
|
160
|
+
homepage: https://coinbase.com/api/doc
|
161
|
+
licenses: []
|
162
|
+
metadata: {}
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
166
|
+
- lib
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 2.2.2
|
180
|
+
signing_key:
|
181
|
+
specification_version: 4
|
182
|
+
summary: The Coinbase API, wrapped, maintained, and better.
|
183
|
+
test_files:
|
184
|
+
- spec/client_spec.rb
|
185
|
+
- spec/oauth_client_spec.rb
|