coinbase 0.0.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of coinbase might be problematic. Click here for more details.

data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ .tddium*
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coinbase-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Coinbase
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,265 @@
1
+ # Coinbase
2
+
3
+ An easy way to buy, send, and accept [bitcoin](http://en.wikipedia.org/wiki/Bitcoin) through the [Coinbase API](https://coinbase.com/docs/api/overview).
4
+
5
+ This gem is a wrapper around the [Coinbase JSON API](https://coinbase.com/api/doc). It uses the [api key + secret authentication method](https://coinbase.com/docs/api/authentication) which is an easy way to get started if you only need to connect to your own Coinbase account. If you need other users to grant your application access, you may want to try an OAuth2 integration instead using the [OAuth2 Ruby Gem](https://github.com/intridea/oauth2) as a starting point.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'coinbase'
12
+
13
+ Then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install coinbase
20
+
21
+ ## Usage
22
+
23
+ Start by [enabling an API Key on your account](https://coinbase.com/account/integrations).
24
+
25
+ Next, create an instance of the client and pass it your API Key + Secret as parameters.
26
+
27
+ ```ruby
28
+ coinbase = Coinbase::Client.new(ENV['COINBASE_API_KEY'], ENV['COINBASE_API_SECRET'])
29
+ ```
30
+
31
+ Notice here that we did not hard code the API key into our codebase, but set it in an environment variable instead. This is just one example, but keeping your credentials separate from your code base is a good [security practice](https://coinbase.com/docs/api/authentication#security).
32
+
33
+ Now you can call methods on `coinbase` similar to the ones described in the [api reference](https://coinbase.com/api/doc). For example:
34
+
35
+ ```ruby
36
+ coinbase.balance
37
+ => #<Money fractional:20035300000 currency:BTC>
38
+ coinbase.balance.format
39
+ => "200.35300000 BTC"
40
+ coinbase.balance.to_f
41
+ => 200.353
42
+ ```
43
+
44
+ [Money objects](https://github.com/RubyMoney/money) are returned for most amounts dealing with currency. You can call `to_f`, `format`, or perform math operations on money objects.
45
+
46
+ ## Examples
47
+
48
+ ### Check your balance
49
+
50
+ ```ruby
51
+ coinbase.balance.to_f
52
+ => 200.353 # BTC amount
53
+ ```
54
+
55
+ ### Send bitcoin
56
+
57
+ ```ruby
58
+ r = coinbase.send_money 'user@example.com', 1.23
59
+ r.success?
60
+ => true
61
+ r.transaction.status
62
+ => 'pending' # this will change to 'complete' in a few seconds if you are sending coinbase-to-coinbase, otherwise it will take about 1 hour, 'complete' means it cannot be reversed or canceled
63
+ r.transaction.id
64
+ => '501a1791f8182b2071000087'
65
+ r.transaction.recipient.email
66
+ => 'user@example.com'
67
+ r.to_hash
68
+ => ... # raw hash response
69
+ ```
70
+
71
+ You can also send money in [a number of currencies](https://github.com/coinbase/coinbase-ruby/blob/master/supported_currencies.json). The amount will be automatically converted to the correct BTC amount using the current exchange rate.
72
+
73
+ ```ruby
74
+ r = coinbase.send_money 'user@example.com', 1.23.to_money('AUS')
75
+ r.transaction.amount.format
76
+ => "0.06713955 BTC"
77
+ ```
78
+
79
+ The first parameter can also be a bitcoin address and the third parameter can be a note or description of the transaction. Descriptions are only visible on Coinbase (not on the general bitcoin network).
80
+
81
+ ```ruby
82
+ r = coinbase.send_money 'mpJKwdmJKYjiyfNo26eRp4j6qGwuUUnw9x', 2.23.to_money("USD"), "thanks for the coffee!"
83
+ r.transaction.recipient_address
84
+ => "mpJKwdmJKYjiyfNo26eRp4j6qGwuUUnw9x"
85
+ r.transaction.notes
86
+ => "thanks for the coffee!"
87
+ ```
88
+
89
+ ### Request bitcoin
90
+
91
+ This will send an email to the recipient, requesting payment, and give them an easy way to pay.
92
+
93
+ ```ruby
94
+ r = coinbase.request_money 'client@example.com', 50, "contractor hours in January (website redesign for 50 BTC)"
95
+ r.transaction.request?
96
+ => true
97
+ r.transaction.id
98
+ => '501a3554f8182b2754000003'
99
+ r = coinbase.resend_request '501a3554f8182b2754000003'
100
+ r.success?
101
+ => true
102
+ r = coinbase.cancel_request '501a3554f8182b2754000003'
103
+ r.success?
104
+ => true
105
+ # from the other account
106
+ r = coinbase.complete_request '501a3554f8182b2754000003'
107
+ r.success?
108
+ => true
109
+ ```
110
+
111
+ ### List your current transactions
112
+
113
+ Sorted in descending order by timestamp, 30 per page. You can pass an integer as the first param to page through results, for example `coinbase.transactions(2)`.
114
+
115
+ ```ruby
116
+ r = coinbase.transactions
117
+ r.current_page
118
+ => 1
119
+ r.num_pages
120
+ => 7
121
+ r.transactions.collect{|t| t.transaction.id }
122
+ => ["5018f833f8182b129c00002f", "5018f833f8182b129c00002e", ...]
123
+ r.transactions.collect{|t| t.transaction.amount.format }
124
+ => ["-1.10000000 BTC", "42.73120000 BTC", ...]
125
+ ```
126
+
127
+ Transactions will always have an `id` attribute which is the primary way to identity them through the Coinbase api. They will also have a `hsh` (bitcoin hash) attribute once they've been broadcast to the network (usually within a few seconds).
128
+
129
+ ### Check bitcoin prices
130
+
131
+ Check the buy or sell price by passing a `quantity` of bitcoin that you'd like to buy or sell. This price includes Coinbase's fee of 1% and the bank transfer fee of $0.15.
132
+
133
+ ```ruby
134
+ coinbase.buy_price(1).format
135
+ => "$17.95"
136
+ coinbase.buy_price(30).format
137
+ => "$539.70"
138
+ ```
139
+
140
+
141
+ ```ruby
142
+ coinbase.sell_price(1).format
143
+ => "$17.93"
144
+ coinbase.buy_price(30).format
145
+ => "$534.60"
146
+ ```
147
+
148
+ ### Buy or Sell bitcoin
149
+
150
+ Buying and selling bitcoin requires you to [add a payment method](https://coinbase.com/buys) through the web app first.
151
+
152
+ Then you can call `buy!` or `sell!` and pass a `quantity` of bitcoin you want to buy (as a float or integer).
153
+
154
+ ```ruby
155
+ r = coinbase.buy!(1)
156
+ r.transfer.code
157
+ => '6H7GYLXZ'
158
+ r.transfer.btc.format
159
+ => "1.00000000 BTC"
160
+ r.transfer.total.format
161
+ => "$17.95"
162
+ r.transfer.payout_date
163
+ => 2013-02-01 18:00:00 -0800
164
+ ```
165
+
166
+
167
+ ```ruby
168
+ r = coinbase.sell!(1)
169
+ r.transfer.code
170
+ => 'RD2OC8AL'
171
+ r.transfer.btc.format
172
+ => "1.00000000 BTC"
173
+ r.transfer.total.format
174
+ => "$17.93"
175
+ r.transfer.payout_date
176
+ => 2013-02-01 18:00:00 -0800
177
+ ```
178
+
179
+ ### Listing Buy/Sell History
180
+
181
+ You can use `transfers` to view past buys and sells.
182
+
183
+ ```ruby
184
+ r = coinbase.transfers
185
+ r.current_page
186
+ => 1
187
+ r.total_count
188
+ => 7
189
+ r.transfers.collect{|t| t.transfer.type }
190
+ => ["Buy", "Buy", ...]
191
+ r.transfers.collect{|t| t.transfer.btc.amount }
192
+ => [0.01, 0.01, ...]
193
+ r.transfers.collect{|t| t.transfer.total.amount }
194
+ => [5.72, 8.35, ...]
195
+ ```
196
+
197
+ ### Create a payment button
198
+
199
+ This will create the code for a payment button (and modal window) that you can use to accept bitcoin on your website. You can read [more about payment buttons here and try a demo](https://coinbase.com/docs/merchant_tools/payment_buttons).
200
+
201
+ The method signature is `def create_button name, price, description=nil, custom=nil, options={}`. The `custom` param will get passed through in [callbacks](https://coinbase.com/docs/merchant_tools/callbacks) to your site. The list of valid `options` [are described here](https://coinbase.com/api/doc/buttons/create.html).
202
+
203
+ ```ruby
204
+ r = coinbase.create_button "Your Order #1234", 42.95.to_money('EUR'), "1 widget at €42.95", "my custom tracking code for this order"
205
+ r.button.code
206
+ => "93865b9cae83706ae59220c013bc0afd"
207
+ r.embed_html
208
+ => "<div class=\"coinbase-button\" data-code=\"93865b9cae83706ae59220c013bc0afd\"></div><script src=\"https://coinbase.com/assets/button.js\" type=\"text/javascript\"></script>"
209
+ ```
210
+
211
+ ### Create an order for a button
212
+
213
+ This will generate an order associated with a button. You can read [more about creating an order for a button here](https://coinbase.com/api/doc/1.0/buttons/create_order.html).
214
+
215
+ ```ruby
216
+ r = coinbase.create_order_for_button "93865b9cae83706ae59220c013bc0afd"
217
+ => "{\"success\"=>true, \"order\"=>{\"id\"=>\"ASXTKPZM\", \"created_at\"=>\"2013-12-13T01:36:47-08:00\", \"status\"=>\"new\", \"total_btc\"=>{\"cents\"=>6859115, \"currency_iso\"=>\"BTC\"}, \"total_native\"=>{\"cents\"=>4295, \"currency_iso\"=>\"EUR\"}, \"custom\"=>\"my custom tracking code for this order\", \"receive_address\"=>\"mpJKwdmJKYjiyfNo26eRp4j6qGwuUUnw9x\", \"button\"=>{\"type\"=>\"buy_now\", \"name\"=>\"Your Order #1234\", \"description\"=>\"1 widget at 42.95\", \"id\"=>\"93865b9cae83706ae59220c013bc0afd\"}, \"transaction\"=>nil}}"
218
+ ```
219
+
220
+ ### Create a new user
221
+
222
+ ```ruby
223
+ r = coinbase.create_user "newuser@example.com", "some password"
224
+ r.user.email
225
+ => "newuser@example.com"
226
+ r.receive_address
227
+ => "mpJKwdmJKYjiyfNo26eRp4j6qGwuUUnw9x"
228
+ ```
229
+
230
+ A receive address is returned also in case you need to send the new user a payment right away.
231
+
232
+ ## Adding new methods
233
+
234
+ You can see a [list of method calls here](https://github.com/coinbase/coinbase-ruby/blob/master/lib/coinbase/client.rb) and how they are implemented. They are a wrapper around the [Coinbase JSON API](https://coinbase.com/api/doc).
235
+
236
+ If there are any methods listed in the [API Reference](https://coinbase.com/api/doc) that haven't been added to the gem yet, you can also call `get`, `post`, `put`, or `delete` with a `path` and optional `params` hash for a quick implementation. The raw response will be returned. For example:
237
+
238
+ ```ruby
239
+ coinbase.get('/account/balance').to_hash
240
+ => {"amount"=>"50.00000000", "currency"=>"BTC"}
241
+ ```
242
+
243
+ Or feel free to add a new wrapper method and submit a pull request.
244
+
245
+ ## Security Notes
246
+
247
+ If someone gains access to your API Key they will have complete control of your Coinbase account. This includes the abillity to send all of your bitcoins elsewhere.
248
+
249
+ For this reason, API access is disabled on all Coinbase accounts by default. If you decide to enable API key access you should take precautions to store your API key securely in your application. How to do this is application specific, but it's something you should [research](http://programmers.stackexchange.com/questions/65601/is-it-smart-to-store-application-keys-ids-etc-directly-inside-an-application) if you have never done this before.
250
+
251
+ ## Testing
252
+
253
+ If you'd like to contribute code or modify this gem, you can run the test suite with:
254
+
255
+ ```ruby
256
+ gem install coinbase --dev
257
+ bundle exec rspec # or just 'rspec' may work
258
+ ```
259
+
260
+ ## Contributing
261
+
262
+ 1. Fork this repo and make changes in your own copy
263
+ 2. Add a test if applicable and run the existing tests with `rspec` to make sure they pass
264
+ 3. Commit your changes and push to your fork `git push origin master`
265
+ 4. Create a new pull request and submit it back to us!
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/coinbase.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coinbase/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "coinbase"
8
+ gem.version = Coinbase::VERSION
9
+ gem.authors = ["Brian Armstrong"]
10
+ gem.email = [""]
11
+ gem.description = ["An easy way to buy, send, and accept bitcoin."]
12
+ gem.summary = ["An easy way to buy, send, and accept bitcoin."]
13
+ gem.homepage = "https://coinbase.com/api/doc"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+
21
+ # Gems that must be intalled for sift to compile and build
22
+ gem.add_development_dependency "rspec", "~> 2.12"
23
+ gem.add_development_dependency "fakeweb", "~> 1.3.0"
24
+ gem.add_development_dependency "rake"
25
+
26
+ # Gems that must be intalled for sift to work
27
+ gem.add_dependency "httparty", ">= 0.8.3"
28
+ gem.add_dependency "multi_json", ">= 1.3.4"
29
+ gem.add_dependency "money", "= 5.1.1"
30
+ gem.add_dependency "hashie", ">= 1.2.0"
31
+ end