An official Ruby gem for interacting with the Blockchain.info API.
This gem was recently updated to support additional functionality of the Blockchain API. As part of this process, the archticture was changed. Rather than calling static methods under the Blockchain module, applications can now create instances of different classes supporting different Blockchain API endpoints. Calling the static methods will still work, but these have been deprecated.
Installation via RubyGems:
$ gem install blockchain
Manual installation:
$ git clone https://github.com/blockchain/api-v1-client-ruby
$ cd api-v1-client-ruby
$ rake install
To use the wallet
and createwallet
functionality, you'll also need an instance of service-my-wallet.
The gem consists of the following functionality:
blockexplorer
(docs) (api/blockchain_api)createwallet
(docs) (api/create_wallet)exchangerates
(docs) (api/exchange_rates_api)pushtx
(docs) (pushtx)receive
(docs) (api/api_receive)statistics
(docs) (api/charts_api)wallet
(docs) (api/blockchain_wallet_api)
The main module is called Blockchain
Every class instance creates an instance of the client class, which is used to make calls to the API. The client instance will be created with a default base url if none is provided. You can also provide an API code when creating an instance of any class. For example:
require 'Blockchain'
# creates a block explorer instance pointing to the default base url, https://blockchain.info/, with no api code
explorer = Blockchain::BlockExplorer.new
# creates a block explorer pointing to an alternative base url and using an api code
explorer = Blockchain::BlockExplorer.new('http://some-other-url.com/', 'api-code')
All functions may raise exceptions caused by incorrectly passed parameters or other problems. If a call is rejected server-side, the APIException
exception will be raised.
It is possible to set arbitrary connection timeouts.
require 'Blockchain'
Blockchain::TIMEOUT_SECONDS = 5 #time out after 5 seconds
In order to prevent abuse some API methods require an API key approved with some basic contact information and a description of its intended use. Please request an API key here.
The same API key can be used to bypass the request limiter.