helloblock 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/helloblock.gemspec +32 -0
- data/lib/helloblock.rb +20 -0
- data/lib/helloblock/api_interface/api_parameters.rb +10 -0
- data/lib/helloblock/api_interface/endpoints.rb +23 -0
- data/lib/helloblock/configuration.rb +22 -0
- data/lib/helloblock/http/connection.rb +28 -0
- data/lib/helloblock/http/request.rb +26 -0
- data/lib/helloblock/resources/address.rb +15 -0
- data/lib/helloblock/resources/block.rb +7 -0
- data/lib/helloblock/resources/faucet.rb +17 -0
- data/lib/helloblock/resources/query.rb +74 -0
- data/lib/helloblock/resources/transaction.rb +15 -0
- data/lib/helloblock/resources/wallet.rb +7 -0
- data/lib/helloblock/spec_helper.rb +11 -0
- data/lib/helloblock/utils.rb +17 -0
- data/lib/helloblock/version.rb +3 -0
- data/spec/fixture/vcr_cassettes/batch_address_unspents.yml +49 -0
- data/spec/fixture/vcr_cassettes/batch_addresses.yml +47 -0
- data/spec/fixture/vcr_cassettes/batch_transactions.yml +47 -0
- data/spec/fixture/vcr_cassettes/batch_transactions_addresses.yml +49 -0
- data/spec/fixture/vcr_cassettes/batch_unspents.yml +49 -0
- data/spec/fixture/vcr_cassettes/faucet.yml +45 -0
- data/spec/fixture/vcr_cassettes/latest_blocks.yml +47 -0
- data/spec/fixture/vcr_cassettes/latest_transactions.yml +47 -0
- data/spec/fixture/vcr_cassettes/propagate.yml +49 -0
- data/spec/fixture/vcr_cassettes/single_address.yml +47 -0
- data/spec/fixture/vcr_cassettes/single_address_unspents.yml +49 -0
- data/spec/fixture/vcr_cassettes/single_block.yml +47 -0
- data/spec/fixture/vcr_cassettes/single_transaction.yml +47 -0
- data/spec/fixture/vcr_cassettes/wallet.yml +47 -0
- data/spec/fixture/vcr_cassettes/withdrawal.yml +45 -0
- data/spec/integration/api_calls_work_spec.rb +176 -0
- data/spec/lib/address_spec.rb +77 -0
- data/spec/lib/connection_spec.rb +28 -0
- data/spec/lib/faucet_spec.rb +30 -0
- data/spec/lib/helloblock_spec.rb +51 -0
- data/spec/lib/request_spec.rb +41 -0
- data/spec/lib/transaction_spec.rb +106 -0
- data/spec/spec_helper.rb +13 -0
- metadata +251 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5705b196e7b8ac0e977d9958c959f8126f21fd5
|
4
|
+
data.tar.gz: a16a2f4bcc24a6cb4f42a2cacb0dfa6875987526
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5df3bdc542e11603862ca74da25cebec116923d61b8d5cd0c365047fb0e63768f7204290a568351797b514048a797d9349589fe4371d9e3c0e4637749a9b27fb
|
7
|
+
data.tar.gz: 970ea0b35c990cddeb516cca21ee03946a84feaff1ba02228dffb3e6f8e903950e88de61924fc049f5d7bd3ee25bfbd35afd3f374b3bdde4ba48bea2137665b9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# HelloBlock
|
2
|
+
|
3
|
+
Fluent ruby wrapper for the [HelloBlock](http://www.helloblock.io) API. For a simple, non-fluent wrapper that avoids the Singleton pattern, see [helloblock-ruby](http://github.com/nathanielwroblewski/helloblock-ruby).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'helloblock'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install helloblock
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Configure your HelloBlock session:
|
22
|
+
|
23
|
+
```rb
|
24
|
+
HelloBlock.configure do |config|
|
25
|
+
config.api_key = ENV['APIKEY'] # your api key goes here
|
26
|
+
config.version = :v1 # defaults to latest version
|
27
|
+
config.network = :mainnet # defaults to testnet
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Query the HelloBlock API with familiar [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord)-like syntax. NOTE: As of the current version, `#to_hash` must be called on each completed query as a kicker method.
|
32
|
+
|
33
|
+
Description | Method
|
34
|
+
------------- | ------------- |
|
35
|
+
Fetch a single address | `HelloBlock::Address.find('1DQN9nop...')`|
|
36
|
+
Fetch batch addresses | `HelloBlock::Address.where(address: ['1DQN9nop...', ...])` |
|
37
|
+
Fetch unspents for address | `HelloBlock::Address.find('1DQN9nop...').unspents` |
|
38
|
+
Fetch unspents for addresses | `HelloBlock::Address.unspents.where(address: ['1DQN9nop...', ...])` |
|
39
|
+
Fetch a single transaction | `HelloBlock::Transaction.find('f37e6181...')` |
|
40
|
+
Fetch batch transactions | `HelloBlock::Transaction.where(transaction: ['f37e6181...', ...])` |
|
41
|
+
Fetch transactions by addresses | `HelloBlock::Transaction.where(address: ['1DQN9nop...', ...])` |
|
42
|
+
Fetch latest transactions | `HelloBlock::Transaction.last(5).offset(7)` |
|
43
|
+
Propagate a transaction | `HelloBlock::Transaction.create('01000...')` |
|
44
|
+
Fetch a block | `HelloBlock::Block.find('00000...')` |
|
45
|
+
Fetch latest block | `HelloBlock::Block.last(1)` |
|
46
|
+
Fetch wallet information | `HelloBlock::Wallet.where(addresses: [...], unspents: false)` |
|
47
|
+
Fetch unspents from faucet | `HelloBlock::Faucet.where(type: 3)` |
|
48
|
+
Withdraw from faucet | `HelloBlock::Faucet.withdraw(to: '1DQN9nop...', amount: 100_000)` |
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/helloblock.gemspec
ADDED
@@ -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"
|
8
|
+
spec.version = HelloBlock::VERSION
|
9
|
+
spec.authors = ["Nathaniel Wroblewski"]
|
10
|
+
spec.email = ["nathanielwroblewski@gmail.com"]
|
11
|
+
spec.description = %q{Fluent Ruby wrapper for the helloblock.io API}
|
12
|
+
spec.summary = %q{Fluent Ruby wrapper for the helloblock.io API}
|
13
|
+
spec.homepage = ""
|
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
|
data/lib/helloblock.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helloblock/version'
|
2
|
+
require 'helloblock/api_interface/endpoints'
|
3
|
+
require 'helloblock/resources/query'
|
4
|
+
require 'helloblock/resources/address'
|
5
|
+
require 'helloblock/resources/transaction'
|
6
|
+
require 'helloblock/resources/block'
|
7
|
+
require 'helloblock/resources/wallet'
|
8
|
+
require 'helloblock/resources/faucet'
|
9
|
+
require 'helloblock/http/connection'
|
10
|
+
require 'helloblock/http/request'
|
11
|
+
require 'helloblock/configuration'
|
12
|
+
require 'helloblock/spec_helper'
|
13
|
+
|
14
|
+
module HelloBlock
|
15
|
+
extend HelloBlock::Endpoints
|
16
|
+
extend HelloBlock::Request
|
17
|
+
extend HelloBlock::Connection
|
18
|
+
extend HelloBlock::Configuration
|
19
|
+
extend HelloBlock::SpecHelper
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HelloBlock
|
2
|
+
module Endpoints
|
3
|
+
ENDPOINTS = {
|
4
|
+
address: '/addresses/',
|
5
|
+
addresses_transactions: '/addresses/transactions',
|
6
|
+
unspents: '/unspents',
|
7
|
+
transaction: '/transactions/',
|
8
|
+
latest: 'latest',
|
9
|
+
wallet: '/wallet',
|
10
|
+
block: '/blocks/',
|
11
|
+
faucet: '/faucet',
|
12
|
+
withdraw: '/faucet/withdrawal'
|
13
|
+
}
|
14
|
+
|
15
|
+
def base_url
|
16
|
+
"http://#{network}.helloblock.io"
|
17
|
+
end
|
18
|
+
|
19
|
+
def version_path
|
20
|
+
"/#{version}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helloblock/utils'
|
2
|
+
|
3
|
+
module HelloBlock
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
extend HelloBlock::Utils
|
7
|
+
mattr_accessor :api_key, :network, :version
|
8
|
+
|
9
|
+
|
10
|
+
def network
|
11
|
+
@network ||= :testnet
|
12
|
+
end
|
13
|
+
|
14
|
+
def version
|
15
|
+
@version ||= :v1
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield self if block_given?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module HelloBlock
|
4
|
+
module Connection
|
5
|
+
def connection
|
6
|
+
@connection ||= Faraday.new(base_url, connection_options) do |connection|
|
7
|
+
connection.request :json
|
8
|
+
connection.response :json
|
9
|
+
connection.use FaradayMiddleware::Rashify
|
10
|
+
|
11
|
+
connection.adapter :net_http
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def connection_options
|
16
|
+
@connection_options ||= {
|
17
|
+
headers: {
|
18
|
+
accept: 'application/json',
|
19
|
+
user_agent: "HelloBlock Gem #{HelloBlock::VERSION}"
|
20
|
+
},
|
21
|
+
request: {
|
22
|
+
open_timeout: 10,
|
23
|
+
timeout: 30
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helloblock/api_interface/endpoints'
|
2
|
+
|
3
|
+
module HelloBlock
|
4
|
+
module Request
|
5
|
+
|
6
|
+
include HelloBlock::Endpoints
|
7
|
+
|
8
|
+
def get(path, params={})
|
9
|
+
request(:get, version_path + path, params, headers)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path, params={})
|
13
|
+
request(:post, version_path + path, { body: params }, headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def request(method, path, params={}, headers={})
|
19
|
+
connection.send(method.to_sym, path, params, headers).body
|
20
|
+
end
|
21
|
+
|
22
|
+
def headers
|
23
|
+
{ accept: '*/*', content_type: 'application/json; charset=UTF-8' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helloblock/resources/query'
|
2
|
+
require 'helloblock/api_interface/endpoints'
|
3
|
+
|
4
|
+
module HelloBlock
|
5
|
+
class Address
|
6
|
+
extend HelloBlock::Query
|
7
|
+
include HelloBlock::Endpoints
|
8
|
+
|
9
|
+
def self.unspents
|
10
|
+
query[:path] += ENDPOINTS[:unspents]
|
11
|
+
query[:path].squeeze!('/')
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helloblock/resources/query'
|
2
|
+
require 'helloblock/api_interface/endpoints'
|
3
|
+
require 'helloblock/api_interface/api_parameters'
|
4
|
+
|
5
|
+
module HelloBlock
|
6
|
+
class Faucet
|
7
|
+
extend HelloBlock::Query
|
8
|
+
include HelloBlock::Endpoints
|
9
|
+
include HelloBlock::APIParameters
|
10
|
+
|
11
|
+
def self.withdraw(conditions)
|
12
|
+
where(conditions.merge({post: true}))
|
13
|
+
query[:path] = ENDPOINTS[:withdraw]
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'helloblock/api_interface/endpoints'
|
2
|
+
require 'helloblock/api_interface/api_parameters'
|
3
|
+
|
4
|
+
module HelloBlock
|
5
|
+
module Query
|
6
|
+
include HelloBlock::Endpoints
|
7
|
+
include HelloBlock::APIParameters
|
8
|
+
|
9
|
+
def query
|
10
|
+
@query ||= default_query
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_query
|
14
|
+
{ path: ENDPOINTS[parent_class], params: {} }
|
15
|
+
end
|
16
|
+
|
17
|
+
def parent_class
|
18
|
+
self.to_s.split('::').last.downcase.to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
def find(id)
|
22
|
+
query[:path] += id
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# where(transaction: [...]) => converts :transaction to API's :txHashes
|
27
|
+
def where(conditions)
|
28
|
+
conditions.each do |resource, ids|
|
29
|
+
api_resource = API_PARAMETERS[resource] || resource
|
30
|
+
query[:params][api_resource] = ids
|
31
|
+
end
|
32
|
+
determine_parent_resource
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def last(limit)
|
37
|
+
query[:path] = ENDPOINTS[parent_class] + ENDPOINTS[:latest]
|
38
|
+
query[:params][:limit] = limit
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def offset(number)
|
43
|
+
query[:params][:offset] = number
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_hash
|
48
|
+
(query_copy = query.clone) and (@query = default_query)
|
49
|
+
method = query_copy[:params][:post] ? :post : :get
|
50
|
+
query_copy[:params].delete(:post)
|
51
|
+
HelloBlock.send(method, query_copy[:path], query_copy[:params])
|
52
|
+
end
|
53
|
+
|
54
|
+
def [](attribute)
|
55
|
+
to_hash[attribute]
|
56
|
+
end
|
57
|
+
|
58
|
+
def []=(attribute, value)
|
59
|
+
to_hash[attribute] = value
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
to_hash.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
# exceptions: querying transactions with addresses actually hits
|
67
|
+
# /addresses/transactions endpoint
|
68
|
+
def determine_parent_resource
|
69
|
+
if query[:path] == ENDPOINTS[:transaction] && query[:params][:addresses]
|
70
|
+
query[:path] = ENDPOINTS[:addresses_transactions]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helloblock/resources/query'
|
2
|
+
require 'helloblock/api_interface/api_parameters'
|
3
|
+
|
4
|
+
module HelloBlock
|
5
|
+
class Transaction
|
6
|
+
extend HelloBlock::Query
|
7
|
+
include HelloBlock::APIParameters
|
8
|
+
|
9
|
+
def self.create(raw_tx_hex)
|
10
|
+
api_parameter = API_PARAMETERS[:propagate]
|
11
|
+
query[:params][api_parameter] = raw_tx_hex
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|