bitcoin-3rd-party-apis 0.1.0 → 0.2.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.
@@ -1,17 +1,22 @@
1
+ ## v0.2.0
2
+
3
+ * Added http://blockchain.info call, BlockchainInfo.getreceivedbyaddress.
4
+ * Refactored BlockExplorer slightly.
5
+
1
6
  ## v0.1.0
2
7
 
3
- * Renamed gem to bitcoin-3rd-party-apis
8
+ * Renamed gem to bitcoin-3rd-party-apis.
4
9
 
5
10
  ## v0.0.3
6
11
 
7
- * Fixed bug (accidental 'puts' left behind)
12
+ * Fixed bug (accidental 'puts' left behind).
8
13
 
9
14
  ## v0.0.2
10
15
 
11
- * Added BlockExplorer.getreceivedbyaddress
16
+ * Added BlockExplorer.getreceivedbyaddress.
12
17
 
13
18
  ## v0.0.1
14
19
 
15
20
  * Initial release
16
- * Added BlockExplorer.mytransactions
21
+ * Added BlockExplorer.mytransactions.
17
22
 
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # BlockExplorer
1
+ # Bitcoin 3rd-party APIs
2
2
 
3
- Ruby wrapper for Block Explorer (http://blockexplorer.com), a popular bitcoin blockchain explorer. BlockExplorer exposes some handy bitcoin blockchain query methods. This gem exposes some of those methods for easy consumption in a Ruby project.
3
+ Ruby wrapper for various popular 3rd-party bitcoin related APIs. At the moment only Block Explorer (http://blockexplorer.com) and BlockChain.info (http://blockchain.info) are wrapped. The gem exposes some handy bitcoin blockchain query methods, useful for thin bitcoin clients.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'block_explorer'
9
+ gem 'bitcoin-3rd-party-apis'
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,7 +14,7 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install block_explorer
17
+ $ gem install bitcoin-3rd-party-apis
18
18
 
19
19
  ## Usage
20
20
 
@@ -24,11 +24,14 @@ Or install it yourself as:
24
24
  BlockExplorer.mytransactions([address1, address2])
25
25
 
26
26
 
27
- `getreceivedbyaddress` returns BigDecimal of the total amount of bitcoins sent to the address.
27
+ `getreceivedbyaddress` returns BigDecimal of the total amount of bitcoins sent to the address. Note for the `BlockchainInfo` version, `120` is the maximum confirmation number.
28
28
 
29
29
  BlockExplorer.getreceivedbyaddress(address)
30
30
  BlockExplorer.getreceivedbyaddress(address, 3) # return received amount where transactions have minconf=3
31
31
 
32
+ BlockchainInfo.getreceivedbyaddress(address)
33
+ BlockchainInfo.getreceivedbyaddress(address, 3) # return received amount where transactions have minconf=3
34
+
32
35
 
33
36
  ## Contributing
34
37
 
@@ -3,3 +3,4 @@ require 'json'
3
3
 
4
4
  require "bitcoin-3rd-party-apis/version"
5
5
  require 'block_explorer'
6
+ require 'blockchain_info'
@@ -1,3 +1,3 @@
1
1
  module Bitcoin3rdPartyApis
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,10 @@
1
- require "block_explorer/constants"
2
1
  require "block_explorer/block_chain"
3
2
 
4
- module BlockExplorer
3
+ class BlockExplorer
4
+ private
5
+
6
+ def self.domain
7
+ "https://blockexplorer.com"
8
+ end
5
9
  end
6
10
 
@@ -1,22 +1,19 @@
1
- module BlockExplorer
1
+ class BlockExplorer
2
2
  module BlockChain
3
- MyTransactions = "#{BlockExplorer::Domain}/q/mytransactions"
4
- RawTx = "#{BlockExplorer::Domain}/rawtx"
5
- GetReceivedByAddress = "#{BlockExplorer::Domain}/q/getreceivedbyaddress"
6
3
 
7
4
  def mytransactions(addresses)
8
5
  if addresses.is_a?(String)
9
6
  addresses = [addresses]
10
7
  end
11
8
 
12
- get_json "#{MyTransactions}/#{addresses.join('.')}"
9
+ get_json "#{mytransactions_url}/#{addresses.join('.')}"
13
10
  end
14
11
 
15
12
  def getreceivedbyaddress(address, minconf = 0)
16
13
  if minconf > 0
17
- url = "#{GetReceivedByAddress}/#{address}/#{minconf}"
14
+ url = "#{getreceivedbyaddress_url}/#{address}/#{minconf}"
18
15
  else
19
- url = "#{GetReceivedByAddress}/#{address}"
16
+ url = "#{getreceivedbyaddress_url}/#{address}"
20
17
  end
21
18
 
22
19
  BigDecimal(open(url).read)
@@ -27,6 +24,18 @@ module BlockExplorer
27
24
  # end
28
25
 
29
26
  private
27
+
28
+ def mytransactions_url
29
+ "#{domain}/q/mytransactions"
30
+ end
31
+
32
+ def rawtx_url
33
+ "#{domain}/rawtx"
34
+ end
35
+
36
+ def getreceivedbyaddress_url
37
+ "#{domain}/q/getreceivedbyaddress"
38
+ end
30
39
 
31
40
  def get_json(url)
32
41
  JSON.parse open(url).read
@@ -0,0 +1,11 @@
1
+ require 'blockchain_info/block_chain'
2
+
3
+ class BlockchainInfo
4
+
5
+ private
6
+
7
+ def self.domain
8
+ "https://blockchain.info"
9
+ end
10
+ end
11
+
@@ -0,0 +1,30 @@
1
+ class BlockchainInfo
2
+ module BlockChain
3
+
4
+ def getreceivedbyaddress(address, minconf = 0)
5
+ if minconf > 0
6
+ url = "#{getreceivedbyaddress_url}/#{address}?confirmations=#{minconf}"
7
+ else
8
+ url = "#{getreceivedbyaddress_url}/#{address}"
9
+ end
10
+
11
+ satoshi_to_bitcoins BigDecimal(open(url).read)
12
+ end
13
+
14
+ private
15
+
16
+ def satoshi_to_bitcoins(satoshi)
17
+ satoshi / (10 ** 8)
18
+ end
19
+
20
+ def getreceivedbyaddress_url
21
+ "#{domain}/q/getreceivedbyaddress"
22
+ end
23
+
24
+ def get_json(url)
25
+ JSON.parse open(url).read
26
+ end
27
+ end
28
+
29
+ extend BlockChain
30
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe BlockchainInfo do
4
+ let(:addressA) { '1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs' }
5
+ let(:addressB) { '1KxepETPK2Xz8e5FaZE62y7Rww4LWuJUhG' }
6
+
7
+ context '#getreceivedbyaddress' do
8
+ context "without minconf" do
9
+ use_vcr_cassette
10
+
11
+ it "returns the total received" do
12
+ BlockchainInfo.getreceivedbyaddress(addressA).should == BigDecimal("0.1")
13
+ end
14
+ end
15
+
16
+ context "minconf" do
17
+ use_vcr_cassette
18
+
19
+ it "returns same number for old transactions" do
20
+ BlockchainInfo.getreceivedbyaddress(addressA, 120).should == BigDecimal("0.1")
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,123 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://blockchain.info/q/getreceivedbyaddress/1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs?confirmations=99999999
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 500
17
+ message: Internal Server Error
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ Content-Type:
22
+ - text/plain
23
+ Content-Length:
24
+ - '39'
25
+ Date:
26
+ - Mon, 18 Jun 2012 01:00:03 GMT
27
+ Connection:
28
+ - close
29
+ body:
30
+ encoding: US-ASCII
31
+ string: Confirmations must be between 0 and 120
32
+ http_version:
33
+ recorded_at: Mon, 18 Jun 2012 01:00:03 GMT
34
+ - request:
35
+ method: get
36
+ uri: https://blockchain.info/q/getreceivedbyaddress/1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs?confirmations=10
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ''
40
+ headers:
41
+ Accept:
42
+ - ! '*/*'
43
+ User-Agent:
44
+ - Ruby
45
+ response:
46
+ status:
47
+ code: 200
48
+ message: OK
49
+ headers:
50
+ Server:
51
+ - Apache-Coyote/1.1
52
+ Content-Type:
53
+ - text/plain
54
+ Content-Length:
55
+ - '8'
56
+ Date:
57
+ - Mon, 18 Jun 2012 01:04:50 GMT
58
+ body:
59
+ encoding: US-ASCII
60
+ string: '10000000'
61
+ http_version:
62
+ recorded_at: Mon, 18 Jun 2012 01:04:51 GMT
63
+ - request:
64
+ method: get
65
+ uri: https://blockchain.info/q/getreceivedbyaddress/1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs?confirmations=999999
66
+ body:
67
+ encoding: US-ASCII
68
+ string: ''
69
+ headers:
70
+ Accept:
71
+ - ! '*/*'
72
+ User-Agent:
73
+ - Ruby
74
+ response:
75
+ status:
76
+ code: 500
77
+ message: Internal Server Error
78
+ headers:
79
+ Server:
80
+ - Apache-Coyote/1.1
81
+ Content-Type:
82
+ - text/plain
83
+ Content-Length:
84
+ - '39'
85
+ Date:
86
+ - Mon, 18 Jun 2012 01:04:50 GMT
87
+ Connection:
88
+ - close
89
+ body:
90
+ encoding: US-ASCII
91
+ string: Confirmations must be between 0 and 120
92
+ http_version:
93
+ recorded_at: Mon, 18 Jun 2012 01:04:52 GMT
94
+ - request:
95
+ method: get
96
+ uri: https://blockchain.info/q/getreceivedbyaddress/1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs?confirmations=120
97
+ body:
98
+ encoding: US-ASCII
99
+ string: ''
100
+ headers:
101
+ Accept:
102
+ - ! '*/*'
103
+ User-Agent:
104
+ - Ruby
105
+ response:
106
+ status:
107
+ code: 200
108
+ message: OK
109
+ headers:
110
+ Server:
111
+ - Apache-Coyote/1.1
112
+ Content-Type:
113
+ - text/plain
114
+ Content-Length:
115
+ - '8'
116
+ Date:
117
+ - Mon, 18 Jun 2012 01:06:21 GMT
118
+ body:
119
+ encoding: US-ASCII
120
+ string: '10000000'
121
+ http_version:
122
+ recorded_at: Mon, 18 Jun 2012 01:06:23 GMT
123
+ recorded_with: VCR 2.2.1
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://blockchain.info/q/getreceivedbyaddress/1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ Content-Type:
22
+ - text/plain
23
+ Content-Length:
24
+ - '8'
25
+ Date:
26
+ - Mon, 18 Jun 2012 01:06:21 GMT
27
+ body:
28
+ encoding: US-ASCII
29
+ string: '10000000'
30
+ http_version:
31
+ recorded_at: Mon, 18 Jun 2012 01:06:22 GMT
32
+ recorded_with: VCR 2.2.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoin-3rd-party-apis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-16 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70299806946180 !ruby/object:Gem::Requirement
16
+ requirement: &70255676113420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70299806946180
24
+ version_requirements: *70255676113420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: vcr
27
- requirement: &70299806848620 !ruby/object:Gem::Requirement
27
+ requirement: &70255675997220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70299806848620
35
+ version_requirements: *70255675997220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ir_b
38
- requirement: &70299806776800 !ruby/object:Gem::Requirement
38
+ requirement: &70255675850020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70299806776800
46
+ version_requirements: *70255675850020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &70299806717860 !ruby/object:Gem::Requirement
49
+ requirement: &70255675283360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70299806717860
57
+ version_requirements: *70255675283360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70299806683180 !ruby/object:Gem::Requirement
60
+ requirement: &70255675361500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70299806683180
68
+ version_requirements: *70255675361500
69
69
  description: Ruby wrapper for Block Explorer and Blockchain.info. Plan to add additional
70
70
  3rd-party bitcoin APIs
71
71
  email:
@@ -86,12 +86,16 @@ files:
86
86
  - lib/bitcoin-3rd-party-apis/version.rb
87
87
  - lib/block_explorer.rb
88
88
  - lib/block_explorer/block_chain.rb
89
- - lib/block_explorer/constants.rb
89
+ - lib/blockchain_info.rb
90
+ - lib/blockchain_info/block_chain.rb
90
91
  - spec/block_explorer/block_explorer_spec.rb
92
+ - spec/blockchain_info/blockchain_info_spec.rb
91
93
  - spec/cassettes/BlockExplorer/_getreceivedbyaddress/minconf.yml
92
94
  - spec/cassettes/BlockExplorer/_getreceivedbyaddress/without_minconf.yml
93
95
  - spec/cassettes/BlockExplorer/_mytransactions/getting_transactions_for_2_addresses.yml
94
96
  - spec/cassettes/BlockExplorer/_mytransactions/getting_transactions_for_one_address.yml
97
+ - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/minconf.yml
98
+ - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/without_minconf.yml
95
99
  - spec/spec_helper.rb
96
100
  homepage: https://github.com/matholroyd/bitcoin-3rd-party-apis
97
101
  licenses: []
@@ -119,8 +123,11 @@ specification_version: 3
119
123
  summary: Ruby wrapper for various 3rd-party bitcoin APIs
120
124
  test_files:
121
125
  - spec/block_explorer/block_explorer_spec.rb
126
+ - spec/blockchain_info/blockchain_info_spec.rb
122
127
  - spec/cassettes/BlockExplorer/_getreceivedbyaddress/minconf.yml
123
128
  - spec/cassettes/BlockExplorer/_getreceivedbyaddress/without_minconf.yml
124
129
  - spec/cassettes/BlockExplorer/_mytransactions/getting_transactions_for_2_addresses.yml
125
130
  - spec/cassettes/BlockExplorer/_mytransactions/getting_transactions_for_one_address.yml
131
+ - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/minconf.yml
132
+ - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/without_minconf.yml
126
133
  - spec/spec_helper.rb
@@ -1,3 +0,0 @@
1
- module BlockExplorer
2
- Domain = "https://blockexplorer.com"
3
- end