blockr-ruby 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 498b72dcb9ef9d4c1fea8a950d4b1f4cbafca8f1
4
+ data.tar.gz: e4a081cc4c44e69354290945756a4b18a5acb81b
5
+ SHA512:
6
+ metadata.gz: f896be7fd5f6428c67d7db733adc25c5cbeebbecfe68206eee2712b95c86cb3e01ccda6c79c84ac8e7b0c0dc7c3d9b959cefe701479230c9d5f538846c854a97
7
+ data.tar.gz: 4e08a583bebbfb4981eafcbc146c89b18b64b477e59723148e2cf219239615f634eb34beed682f31328dae8adfe9bb6dc6f1a783da5bdfeae9913840ef0fb142
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ # Change these settings to your own preference
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ # We recommend you to keep these unchanged
14
+ end_of_line = lf
15
+ charset = utf-8
16
+ trim_trailing_whitespace = true
17
+ insert_final_newline = true
18
+
19
+ [*.md]
20
+ trim_trailing_whitespace = false
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ blockr
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blockr-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Genaro Madrid
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,31 @@
1
+ # Blockr
2
+
3
+ Ruby SDK for Blockr.io
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'blockr-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install blockr-ruby
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/blockr-ruby/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :console do
4
+ exec 'irb -r blockr -I ./lib'
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blockr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'blockr-ruby'
8
+ spec.version = Blockr::VERSION
9
+ spec.authors = ['Genaro Madrid']
10
+ spec.email = ['genmadrid@gmail.com']
11
+ spec.summary = %q{Ruby SDK for Blockr.io}
12
+ spec.description = %q{Ruby SDK for Blockr.io API}
13
+ spec.homepage = 'https://github.com/genaromadrid/blockr-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency 'rest-client', '~> 1.7'
22
+ spec.add_runtime_dependency 'json', '~> 1.8'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '3.1.0'
27
+ spec.add_development_dependency 'pry-byebug', '~> 3.0'
28
+ end
data/lib/blockr.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module Blockr
5
+ autoload :API, 'blockr/api'
6
+ autoload :Connection, 'blockr/connection'
7
+
8
+ attr_writer :api
9
+
10
+ API_VERSION = 'v1'
11
+ BLOCK_CHAIN = 'btc'
12
+
13
+ def self.api
14
+ @api ||= API.new(network:BLOCK_CHAIN, api_version:API_VERSION)
15
+ end
16
+
17
+ def self.method_missing(sym, *args, &block)
18
+ api.send(sym, *args, &block)
19
+ end
20
+
21
+ end
data/lib/blockr/api.rb ADDED
@@ -0,0 +1,65 @@
1
+ module Blockr
2
+ class API
3
+
4
+ attr_reader :network,
5
+ :api_version
6
+
7
+ def initialize(network:'btc', api_version:'v1')
8
+ @network = network
9
+ @api_version = api_version
10
+ @connection = Connection.new(url)
11
+ end
12
+
13
+ def url
14
+ "http://#{network}.blockr.io/api/#{api_version}"
15
+ end
16
+
17
+ def network=(network)
18
+ @network = network
19
+ @connection = Connection.new(url)
20
+ end
21
+
22
+ def block(hash)
23
+ @connection.get("/block/info/#{hash}")
24
+ end
25
+
26
+ def latest_block
27
+ @connection.get("/block/info/last")
28
+ end
29
+
30
+ def transaction(hash)
31
+ @connection.get("/tx/info/#{hash}")
32
+ end
33
+
34
+ def decode_transaction(hex)
35
+ @connection.post('/tx/decode', hex: hex)
36
+ end
37
+
38
+ def push_transaction(hex)
39
+ @connection.post('/tx/push', hex: hex)
40
+ end
41
+
42
+ def address(address)
43
+ @connection.get("/address/info/#{address}")
44
+ end
45
+
46
+ def address_balance(address)
47
+ @connection.get("/address/balance/#{address}")
48
+ end
49
+
50
+ def address_unspent_transactions(address, params=nil)
51
+ @connection.get("/address/unspent/#{address}#{'?' + params.to_param if params}")
52
+ end
53
+
54
+ def address_unconfirmed
55
+ @connection.get("/address/unconfirmed/#{address}")
56
+ end
57
+
58
+ end
59
+ end
60
+
61
+ class Hash
62
+ def to_param
63
+ collect {|k, v| "#{k}=#{v}"} * '&'
64
+ end
65
+ end
@@ -0,0 +1,38 @@
1
+ module Blockr
2
+
3
+ class Connection
4
+
5
+ def initialize(url=nil)
6
+ @url = url
7
+ end
8
+
9
+ def get(path, payload={})
10
+ query :get, path, payload
11
+ end
12
+
13
+ def post(path, payload={})
14
+ query :post, path, payload
15
+ end
16
+
17
+ def query(method, path, payload={})
18
+ uri = endpoint_uri(path)
19
+ begin
20
+ response = RestClient::Request.execute(:method => method, :url => uri, :payload => payload, :ssl_version => 'SSLv23')
21
+ rescue Exception => e
22
+ response = e.response
23
+ end
24
+ JSON.parse response, :symbolize_names => true
25
+ end
26
+
27
+ private
28
+
29
+ def endpoint_uri(path='')
30
+ if path[0] == '/'
31
+ path[0] = ''
32
+ end
33
+ "#{@url}/#{path}"
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ module Blockr
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blockr-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Genaro Madrid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Ruby SDK for Blockr.io API
98
+ email:
99
+ - genmadrid@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".editorconfig"
105
+ - ".gitignore"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - blockr-ruby.gemspec
113
+ - lib/blockr.rb
114
+ - lib/blockr/api.rb
115
+ - lib/blockr/connection.rb
116
+ - lib/blockr/version.rb
117
+ homepage: https://github.com/genaromadrid/blockr-ruby
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Ruby SDK for Blockr.io
141
+ test_files: []