helloblock-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88a1a989cdcc3a44441a2ecc0e300016074ca45d
4
+ data.tar.gz: 9a5234bcca9038a62de9084e36018bcd837ee14e
5
+ SHA512:
6
+ metadata.gz: 2945c98405b7654d50c72ee0e028529dbe4a203eddd16ab620efe070b71fa29d22de3cfd565231ca8127ec3fb970fd13461f7e8efc13d3ab161ed4ee1d0338be
7
+ data.tar.gz: ced578c8bdeaa3a66e7814971ca5af93e378ac99f081798e5431134b170f9c3444053745b864c987eb04dc3d4a1c4beb5e673bf9df8588d05819f51c00915092
@@ -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
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in helloblock-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nathaniel Wroblewski
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.
@@ -0,0 +1,48 @@
1
+ # HelloBlock
2
+
3
+ Ruby wrapper for the [HelloBlock.io](http://helloblock.io) API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'helloblock-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install helloblock-ruby
18
+
19
+ ## Usage
20
+
21
+ Initialize the HelloBlock client, and set the network to testnet or mainnet.
22
+
23
+ ```rb
24
+ block = HelloBlock::Client.new
25
+ block.network = :mainnet # defaults to :testnet
26
+ ```
27
+
28
+ Description | Method
29
+ ------------- | ------------- |
30
+ Batch get addresses | `block.addresses(addresses: ['ADDRESS1', 'ADDRESS2'])`|
31
+ Batch get unspents | `block.unspents(addresses: [...])` |
32
+ Batch get transactions from address | `block.transactions_for_address(addresses: [...])`
33
+ Batch get transactions | `block.transactions(txHashes: [...])` |
34
+ Get latest transactions | `block.latest_transaction` |
35
+ Post transaction propagation | `block.propagate(rawTxHash: '...')` |
36
+ Get block | `block.blocks(blockId: '...')` |
37
+ Get latest block | `block.latest_blocks` |
38
+ Get wallet info | `block.wallet(addresses: [...])` |
39
+ Get faucet coins | `block.faucet(type: 3)` |
40
+ Post coins withdrawal | `block.withdrawal(amount: 100000, toAddress: '...')` |
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://testnet.helloblock.io/addresses/?addresses=1DQN9nopGvSCDnM3LH1w7j36FtnQDZKnej
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*'
12
+ User-Agent:
13
+ - HelloBlock Ruby Gem 0.0.1
14
+ Content-Type:
15
+ - application/json; charset=UTF-8
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - cloudflare-nginx
25
+ Date:
26
+ - Tue, 11 Mar 2014 08:04:14 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - __cfduid=d5eeced580ba2f4e54df36669bb813c661394525054678; expires=Mon, 23-Dec-2019
35
+ 23:50:00 GMT; path=/; domain=.helloblock.io; HttpOnly
36
+ X-Powered-By:
37
+ - Express
38
+ Cf-Ray:
39
+ - 10963d77bde40651-SJC
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"status":"fail","message":"The endpoint you are looking for does not
43
+ exist!","details":[]}'
44
+ http_version:
45
+ recorded_at: Tue, 11 Mar 2014 08:04:14 GMT
46
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'helloblock/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "helloblock-ruby"
8
+ spec.version = HelloBlock::VERSION
9
+ spec.authors = ["Nathaniel Wroblewski"]
10
+ spec.email = ["nathanielwroblewski@gmail.com"]
11
+ spec.description = %q{Ruby wrapper for the HelloBlock.io API}
12
+ spec.summary = %q{Ruby wrapper for the HelloBlock.io API}
13
+ spec.homepage = "http://www.github.com/nathanielwroblewski/helloblock-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 2.14'
24
+ spec.add_development_dependency 'webmock', '~> 1.17'
25
+ spec.add_development_dependency 'vcr', '~> 2.8'
26
+ spec.add_development_dependency 'guard-rspec', '~> 4.2'
27
+
28
+ spec.add_runtime_dependency 'multi_json', '~> 1.9'
29
+ spec.add_runtime_dependency 'yajl-ruby', '~> 1.2'
30
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.9'
31
+ spec.add_runtime_dependency 'rash', '~> 0.4'
32
+ end
@@ -0,0 +1,6 @@
1
+ require 'helloblock/version'
2
+ require 'helloblock/client'
3
+
4
+ module HelloBlock
5
+
6
+ end
@@ -0,0 +1,25 @@
1
+ require 'helloblock/client/connection'
2
+ require 'helloblock/client/request'
3
+ require 'helloblock/client/endpoints'
4
+
5
+ module HelloBlock
6
+ class Client
7
+ attr_writer :network
8
+
9
+ include Connection
10
+ include Request
11
+ include Endpoints
12
+
13
+ def initialize
14
+
15
+ end
16
+
17
+ def network
18
+ @env ||= :testnet # :mainnet
19
+ end
20
+
21
+ def target_url
22
+ "http://#{network}.helloblock.io"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'faraday_middleware'
2
+
3
+ module HelloBlock
4
+ class Client
5
+ module Connection
6
+ attr_writer :connection_options
7
+
8
+ private
9
+
10
+ def connection
11
+ @connection ||= Faraday.new(base_url, connection_options) do |connection|
12
+ connection.request :json
13
+ connection.response :json
14
+ connection.use FaradayMiddleware::Rashify
15
+
16
+ connection.adapter :net_http
17
+ end
18
+ end
19
+
20
+ def connection_options
21
+ @connection_options ||= {
22
+ headers: {
23
+ accept: 'application/json',
24
+ user_agent: "HelloBlock Ruby Gem #{HelloBlock::VERSION}"
25
+ },
26
+ request: {
27
+ open_timeout: 10,
28
+ timeout: 30
29
+ }
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,47 @@
1
+ module HelloBlock
2
+ class Client
3
+ module Endpoints
4
+
5
+ ADDRESSES_PATH = '/addresses/'
6
+ UNSPENTS_PATH = '/addresses/unspents'
7
+ TRANSACTIONS_FOR_ADDRESS_PATH = '/addresses/transactions'
8
+ TRANSACTIONS_PATH = '/transactions'
9
+ LATEST_TRANSACTION_PATH = '/transactions/latest'
10
+ PROPAGATE_PATH = '/transactions' # POST
11
+ BLOCKS_PATH = '/blocks'
12
+ LATEST_BLOCKS_PATH = '/blocks/latest'
13
+ WALLET_PATH = '/wallet'
14
+ FAUCET_PATH = '/faucet'
15
+ WITHDRAWAL_PATH = '/withdrawal' # POST
16
+
17
+ POST_REQUESTS = [:propagate, :withdrawal]
18
+
19
+ def base_url
20
+ "http://#{network}.helloblock.io"
21
+ end
22
+
23
+ # client.unspents(addresses: ...) => method_missing(:unspents, addresses: ... )
24
+
25
+ def method_missing(method, *args, &block)
26
+ endpoint_defined?(method) ? navigate_to_path(method, args[0]) : super
27
+ end
28
+
29
+ # :unspents => UNSPENTS_PATH
30
+
31
+ def endpoint_defined?(method)
32
+ Endpoints.constants.include?("#{method.upcase}_PATH".to_sym)
33
+ end
34
+
35
+ # get(UNSPENTS_PATH, addresses: ...)
36
+
37
+ def navigate_to_path(method, *args)
38
+ path = Endpoints.const_get("#{method.upcase}_PATH".to_sym)
39
+ post_request?(method) ? post(path, body: args[0]) : get(path, args[0])
40
+ end
41
+
42
+ def post_request?(method)
43
+ POST_REQUESTS.include?(method)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ module HelloBlock
2
+ class Client
3
+ module Request
4
+
5
+ def get(path, params={})
6
+ request(:get, path, params, headers)
7
+ end
8
+
9
+ def post(path, params={})
10
+ request(:post, path, { body: params }, headers)
11
+ end
12
+
13
+ private
14
+
15
+ def request(method, path, params={}, headers={})
16
+ format_batches(params) if params
17
+ connection.send(method.to_sym, path, params, headers).body
18
+ end
19
+
20
+ def headers
21
+ { accept: '*/*', content_type: 'application/json; charset=UTF-8' }
22
+ end
23
+
24
+ def format_batches(params)
25
+ params.each do |key, value|
26
+ params[key] = value.join("&#{key}=") if value.is_a?(Array)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module HelloBlock
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://testnet.helloblock.io/addresses/?addresses=1DQN9nopGvSCDnM3LH1w7j36FtnQDZKnej
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*'
12
+ User-Agent:
13
+ - HelloBlock Ruby Gem 0.0.1
14
+ Content-Type:
15
+ - application/json; charset=UTF-8
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - cloudflare-nginx
25
+ Date:
26
+ - Tue, 11 Mar 2014 08:23:07 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - __cfduid=d664258a348122c961459c49b3f0cc08a1394526187048; expires=Mon, 23-Dec-2019
35
+ 23:50:00 GMT; path=/; domain=.helloblock.io; HttpOnly
36
+ X-Powered-By:
37
+ - Express
38
+ Cf-Ray:
39
+ - 1096591d050c0651-SJC
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"status":"fail","message":"The endpoint you are looking for does not
43
+ exist!","details":[]}'
44
+ http_version:
45
+ recorded_at: Tue, 11 Mar 2014 08:23:07 GMT
46
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://testnet.helloblock.io/blocks?blockId=
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*'
12
+ User-Agent:
13
+ - HelloBlock Ruby Gem 0.0.1
14
+ Content-Type:
15
+ - application/json; charset=UTF-8
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - cloudflare-nginx
25
+ Date:
26
+ - Tue, 11 Mar 2014 08:40:10 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - __cfduid=dd5f037677b4debb8bbb64f726b9cb40a1394527209887; expires=Mon, 23-Dec-2019
35
+ 23:50:00 GMT; path=/; domain=.helloblock.io; HttpOnly
36
+ X-Powered-By:
37
+ - Express
38
+ Cf-Ray:
39
+ - 10967215c800070d-SJC
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"status":"fail","message":"The endpoint you are looking for does not
43
+ exist!","details":[]}'
44
+ http_version:
45
+ recorded_at: Tue, 11 Mar 2014 08:40:10 GMT
46
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://testnet.helloblock.io/faucet?type=3
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*'
12
+ User-Agent:
13
+ - HelloBlock Ruby Gem 0.0.1
14
+ Content-Type:
15
+ - application/json; charset=UTF-8
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - cloudflare-nginx
25
+ Date:
26
+ - Tue, 11 Mar 2014 08:40:11 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - __cfduid=de2567497499f3e146f152cad910d824b1394527210396; expires=Mon, 23-Dec-2019
35
+ 23:50:00 GMT; path=/; domain=.helloblock.io; HttpOnly
36
+ X-Powered-By:
37
+ - Express
38
+ Cf-Ray:
39
+ - 10967218f2820651-SJC
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"status":"success","data":{"privateKeyWIF":"92iusiayAuJYFNPZiPMTS38AhgBYgdYQxMRh9479ayjMPxkCmU1","privateKeyHex":"95d98c8d17c7823d7a55a543ede007cd38d0b6ffd94a382b73b7e7c0a0e95aec","address":"mkh5mguJjf9RKNYoU6eRxb4k8mbr1U175D","hash160":"38c307920ed2a0cb53a021ff5d3407aa5aac2c08","faucetType":3,"unspents":[{"confirmations":11704,"blockHeight":192654,"txHash":"b3ea79f7f0d0ee55853ad1587b3848f428d5c7cb318641bd461368e23a05ea6b","index":0,"scriptPubKey":"76a91438c307920ed2a0cb53a021ff5d3407aa5aac2c0888ac","type":"pubkeyhash","value":100000,"hash160":"38c307920ed2a0cb53a021ff5d3407aa5aac2c08","address":"mkh5mguJjf9RKNYoU6eRxb4k8mbr1U175D"},{"confirmations":11704,"blockHeight":192654,"txHash":"9cd62ac433117f09ba0707346d28df6d9f3b1bb02b1ef0cc46f19c0fda1bad68","index":0,"scriptPubKey":"76a91438c307920ed2a0cb53a021ff5d3407aa5aac2c0888ac","type":"pubkeyhash","value":50000,"hash160":"38c307920ed2a0cb53a021ff5d3407aa5aac2c08","address":"mkh5mguJjf9RKNYoU6eRxb4k8mbr1U175D"},{"confirmations":11704,"blockHeight":192654,"txHash":"b381965d5fecafefca829d50a5b6f4553b3eb6e0c20cddd1ab41a50f860fb43c","index":0,"scriptPubKey":"76a91438c307920ed2a0cb53a021ff5d3407aa5aac2c0888ac","type":"pubkeyhash","value":10000,"hash160":"38c307920ed2a0cb53a021ff5d3407aa5aac2c08","address":"mkh5mguJjf9RKNYoU6eRxb4k8mbr1U175D"}]}}'
43
+ http_version:
44
+ recorded_at: Tue, 11 Mar 2014 08:40:11 GMT
45
+ recorded_with: VCR 2.8.0