blockchain-info-ruby 1.0.0
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/blockchain_info.rb +34 -0
- data/lib/charts.rb +15 -0
- data/lib/exchange.rb +19 -0
- data/lib/merchant.rb +8 -0
- data/lib/ressource.rb +63 -0
- data/lib/wallet.rb +41 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b74e95ddaf7655095f9960c7b33965ad07e5beda
|
4
|
+
data.tar.gz: 62357db58cec6998961c1ef69919f9f479c4b862
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80b04916ccc3880062462658a08db24f5d1051a3eb02f9ea1dac007dd28f4de90238100f60465149c2cb56751bbdcbbc58d22b6f823315631b87ae9ce655c647
|
7
|
+
data.tar.gz: a13dceed4ae0faf3e142600bc752302025b49bb7d69ce0134b31fa098ae697d813ddafc4ae142f1edfe849c756611f961a7ca4af65d306a42983236c104a54e1
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module BlockchainInfo
|
3
|
+
require 'json'
|
4
|
+
require 'base64'
|
5
|
+
require 'openssl'
|
6
|
+
require 'net/http'
|
7
|
+
|
8
|
+
autoload(:Ressource, 'ressource')
|
9
|
+
autoload(:Charts, 'charts')
|
10
|
+
autoload(:Exchange, 'exchange')
|
11
|
+
autoload(:Wallet, 'wallet')
|
12
|
+
autoload(:Merchant, 'merchant')
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :domain
|
16
|
+
attr_accessor :my_wallet_guid
|
17
|
+
attr_accessor :main_password
|
18
|
+
attr_accessor :second_password
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_accessor :configuration
|
23
|
+
end
|
24
|
+
|
25
|
+
# BlockchainInfo.configure do |c|
|
26
|
+
# c.domain = 'blockchain.info'
|
27
|
+
# c.my_wallet_guid = 'YOUR_GUID_ID'
|
28
|
+
# ...
|
29
|
+
# end
|
30
|
+
def self.configure
|
31
|
+
self.configuration ||= Configuration.new
|
32
|
+
yield configuration
|
33
|
+
end
|
34
|
+
end
|
data/lib/charts.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module BlockchainInfo
|
2
|
+
|
3
|
+
# See https://blockchain.info/fr/api/charts_api for more informations.
|
4
|
+
class Charts < BlockchainInfo::Ressource
|
5
|
+
|
6
|
+
def self.chart type, format="json"
|
7
|
+
query_charts_api(type, { format: format })
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a JSON object containing the statistics seen on the stats page.
|
11
|
+
def self.stats
|
12
|
+
query('stats', { format: "json" })
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/exchange.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module BlockchainInfo
|
2
|
+
class Exchange < BlockchainInfo::Ressource
|
3
|
+
|
4
|
+
# Returns a JSON object with the currency codes as keys. "15m" is the 15 minutes delayed market price, "24h" is the 24 hour average market price, "symbol" is the currency symbol.
|
5
|
+
# {
|
6
|
+
# "GBP" : {"last" : 22.9525, "buy" : 22.83201, "sell" : 23.0, "24h" : 23.1, "symbol" : "£"},
|
7
|
+
# "EUR" : {"last" : 26.32999, "buy" : 26.33, "sell" : 26.81774, "24h" : 26.7, "symbol" : "€"},
|
8
|
+
# ...
|
9
|
+
# }
|
10
|
+
def self.ticker
|
11
|
+
query('ticker')
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the value in BTC.
|
15
|
+
def self.to_btc currency, value
|
16
|
+
query('tobtc', { currency: currency, value: value })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/merchant.rb
ADDED
data/lib/ressource.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module BlockchainInfo
|
2
|
+
class Ressource
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def self.query_merchant_api(route, data={})
|
7
|
+
query('fr/api/' + route, data, true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.query_charts_api(route, data={})
|
11
|
+
query('charts/' + route, data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.query_wallet_api(route, data={})
|
15
|
+
guid = BlockchainInfo.configuration.my_wallet_guid
|
16
|
+
query("fr/merchant/#{guid}/" + route, data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.query_auth_wallet_api(route, data={})
|
20
|
+
data[:password] = BlockchainInfo.configuration.main_password
|
21
|
+
query_wallet_api(route, data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.query_two_auth_wallet_api(route, data={})
|
25
|
+
second_password = BlockchainInfo.configuration.second_password.present?
|
26
|
+
data[:second_password] = second_password if second_password
|
27
|
+
query_auth_wallet_api(route, data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.query(route, data={}, secure=false)
|
31
|
+
uri = uri_for(route, data, secure)
|
32
|
+
request(uri)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.request(uri)
|
38
|
+
return {} if Rails.env.test?
|
39
|
+
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
40
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
41
|
+
http.request request
|
42
|
+
end
|
43
|
+
|
44
|
+
if res.code.to_i == 200
|
45
|
+
begin
|
46
|
+
JSON.parse(res.body)
|
47
|
+
rescue JSON::ParserError => e
|
48
|
+
res.body.is_a?(String) ? res.body : {"error" => "invalid json response" }
|
49
|
+
end
|
50
|
+
else
|
51
|
+
{"error" => "service not available"}
|
52
|
+
end
|
53
|
+
rescue
|
54
|
+
{"error" => "connexion refused"}
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.uri_for(route, data, secure=true)
|
58
|
+
path = '/' + route
|
59
|
+
path += "?" + data.to_query if data.present?
|
60
|
+
URI((secure ? "https" : "http") + "://" + File.join(BlockchainInfo.configuration.domain, path))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/wallet.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module BlockchainInfo
|
2
|
+
|
3
|
+
# See https://blockchain.info/fr/api/blockchain_wallet_api for more information.
|
4
|
+
class Wallet < BlockchainInfo::Ressource
|
5
|
+
|
6
|
+
# Return { "message" : "Sent 0.1 BTC to 1A8Ji..." , "tx_hash" : "f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c" , "notice" : "Additional Message" }
|
7
|
+
def self.send address, satoshi_amount, note=nil
|
8
|
+
raise "Allowed only in production env" unless Rails.env.production?
|
9
|
+
query_two_auth_wallet_api('payment', { method:"create", to:address, amount: satoshi_amount, note: note })
|
10
|
+
end
|
11
|
+
|
12
|
+
# recipients is Hash of {btc_address => amount}.
|
13
|
+
# Return { "message" : "Sent To Multiple Recipients" , "tx_hash" : "f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c" }
|
14
|
+
def self.send_many recipients, note=nil
|
15
|
+
raise "Allowed only in production env" unless Rails.env.production?
|
16
|
+
query_two_auth_wallet_api('sendmany', { method:"create", recipients: recipients.to_json, note: note })
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return { "balance": 1000 }
|
20
|
+
def self.balance
|
21
|
+
query_auth_wallet_api('balance', { method:"create" })
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return { "addresses": [
|
25
|
+
# {"balance": 1400938800, "address": "1Q1AtvCyKhtveGm3187mgNRh5YcukUWjQC", "label": "SMS Deposits", "total_received": 5954572400 }
|
26
|
+
# ] }
|
27
|
+
def self.list_addresses confirmations=0
|
28
|
+
query_auth_wallet_api('list', { method:"create", confirmations: confirmations })
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return {"balance" : 50000000, "address" : "19r7jAbPDtfTKQ9VJpvDzFFxCjUJFKesVZ", "total_received" : 100000000}
|
32
|
+
def self.address_balance address, confirmations=0
|
33
|
+
query_auth_wallet_api('list', { method:"create", address: address, confirmations: confirmations })
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return { "address" : "18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy" , "label": "Order No : 1234" }
|
37
|
+
def self.new_address label=nil
|
38
|
+
query_two_auth_wallet_api('new_address', { method:"create", label: label })
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blockchain-info-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Larcheveque
|
8
|
+
- Vincent Renaudineau
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This API allow you to interact with blockchain.info APIs
|
15
|
+
email: ''
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/blockchain_info.rb
|
21
|
+
- lib/charts.rb
|
22
|
+
- lib/exchange.rb
|
23
|
+
- lib/merchant.rb
|
24
|
+
- lib/ressource.rb
|
25
|
+
- lib/wallet.rb
|
26
|
+
homepage: https://github.com/EpicDream/blockchain-info-ruby
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.2.2
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: blockchain.info API
|
50
|
+
test_files: []
|