insight_bitpay 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: 17f9cb5c880b7d374930d6c925cb31ad1d9599ee
4
+ data.tar.gz: c31760f11514c28c32a2a86d1cc678c5db0be3d8
5
+ SHA512:
6
+ metadata.gz: b59f5aa14cdc4c5e8fb405685c331036b58abb4389008694823f223fdf200924cc8a6475b4c10c3cd2508d50a0604f761b5a835dbb645f100f4109caf55caa93
7
+ data.tar.gz: 17b9805c4ae1133b2f8d086ab3641198c391080fd665c70f7d9e60d57c2bbc4d521fd66448f082f1e102777c6dbe346136ac7a0ec928b1622dd6821ea3ee7437
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,16 @@
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
16
+ *.sublime-workspace
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ insight
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 Insight-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,67 @@
1
+ # Insight
2
+
3
+ Ruby SDK for insight.bitpay.com
4
+
5
+ [![Gem Version][gem-version-image]][gem-version-url]
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'insight'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install insight
22
+
23
+ ## Usage
24
+
25
+ ### Initialize the library
26
+
27
+ ```ruby
28
+ insight_api = Insight::API.new(network: 'btc')
29
+ # For testnet3
30
+ insight_api = Insight::API.new(network: 'tbtc')
31
+ ```
32
+
33
+ You can also change the Blockchain using:
34
+ ```ruby
35
+ insight_api.network = 'tbtc'
36
+ ```
37
+
38
+ ### Posible Methods
39
+
40
+ You can use any of these methods with the initialized object or simply by calling:
41
+
42
+ ```ruby
43
+ Insight.block(hash)
44
+ Insight.block_raw(hash)
45
+ Insight.transaction(hash)
46
+ Insight.push_transaction(hex)
47
+ Insight.address(address)
48
+ Insight.address_balance(address)
49
+ Insight.address_total_received(address)
50
+ Insight.address_total_sent(address)
51
+ Insight.address_unconfirmed_balance(address)
52
+ Insight.address_unspent_transactions(address, params = nil)
53
+ Insight.estimatefee(nbBlocks = 2)
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ To bump the version you can use the `./bump` python script, just write it in the terminal to see the options.
59
+
60
+ 1. Fork it ( https://github.com/genaromadrid/insight-ruby/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
65
+
66
+ [gem-version-image]: https://badge.fury.io/rb/Insight-ruby.svg
67
+ [gem-version-url]: https://badge.fury.io/rb/Insight-ruby
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :console do
4
+ exec 'irb -r Insight -I ./lib'
5
+ end
data/bump ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env python
2
+ import re, glob, sys, os
3
+
4
+ __USAGE__ = \
5
+ """BUMP is a semantic versioning bump script which accepts the following
6
+ mutually exclusive arguments:
7
+ -m - a "major" version bump equal to +1.0.0
8
+ -n - a "minor" version bump equal to +0.1.0
9
+ -p - a "patch" version bump equal to +0.0.1
10
+ -h - a "hot fix" version bump equal to +0.0.1
11
+
12
+ All of these options allow for the -r flag, which indicates that the state
13
+ is a RELEASE not a SNAPSHOT. If -r is not specified, then -SNAPSHOT is
14
+ appended to the updated version string."""
15
+
16
+ __INITIAL__ = ['0', '0', '1']
17
+
18
+
19
+ if __name__ == "__main__":
20
+ v = []
21
+ try:
22
+ version_file = glob.glob("lib/*/version.rb")[0]
23
+ raw_v = re.search(r'VERSION = \'(.*)\'', open(version_file).read(), re.M|re.I|re.S).group(1)
24
+ v = re.split(re.compile("\.|-"), raw_v)
25
+ v = v[0:3]
26
+ map(int, v)
27
+
28
+ except ValueError:
29
+ print("failed to parse the existing VERSION file, assuming v 0.0.1")
30
+ v = ['0', '0', '1']
31
+
32
+ except FileNotFoundError:
33
+ print("failed to find a VERSION file, assuming v 0.0.0")
34
+ v = ['0', '0', '0']
35
+
36
+ op = ''
37
+ try:
38
+ op = sys.argv[1]
39
+ except:
40
+ print(__USAGE__)
41
+ sys.exit(-1)
42
+
43
+ if(op == '-m'):
44
+ v = [str(int(v[0])+1), '0', '0']
45
+
46
+ elif(op == '-n'):
47
+ v = [v[0], str(int(v[1])+1), '0']
48
+
49
+ elif(op == '-p' or op == '-h'):
50
+ v = [v[0], v[1], str(int(v[2])+1)]
51
+
52
+ else:
53
+ print(__USAGE__)
54
+ sys.exit(-1)
55
+
56
+ v = '.'.join(v)
57
+
58
+ if(op == '-h'):
59
+ os.system("git checkout -b hotfix/v%s master" % v)
60
+
61
+ else:
62
+ os.system("git checkout -b release/v%s develop" % v)
63
+
64
+ os.system("bump set %s" % v)
65
+
66
+ v += "\n"
67
+
68
+ print(v)
69
+
70
+ sys.exit(0)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'insight/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'insight_bitpay'
8
+ spec.version = Insight::VERSION
9
+ spec.authors = ['Genaro Madrid']
10
+ spec.email = ['genmadrid@gmail.com']
11
+ spec.summary = %q{Ruby SDK for insight.bitpay.com}
12
+ spec.description = %q{Ruby SDK for insight.bitpay.com API}
13
+ spec.homepage = 'https://github.com/genmadrid/insight-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
+ spec.add_development_dependency 'bump', '~> 0.5', '>= 0.5.3'
29
+ end
@@ -0,0 +1,12 @@
1
+ {
2
+ "folders":
3
+ [
4
+ {
5
+ "file_exclude_patterns": ["*.sublime-workspace"],
6
+ "path": ".",
7
+ "follow_symlinks": true,
8
+ "tab_size": 2,
9
+ "translate_tabs_to_spaces": false
10
+ }
11
+ ]
12
+ }
data/lib/insight.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module Insight
5
+ autoload :API, 'Insight/api'
6
+ autoload :Connection, 'Insight/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
@@ -0,0 +1,75 @@
1
+ module Insight
2
+ class API
3
+ attr_reader :network,
4
+ :api_version
5
+
6
+ def initialize(network:'btc')
7
+ @network = network
8
+ @api_version = api_version
9
+ @connection = Connection.new(url)
10
+ end
11
+
12
+ def url
13
+ if network == 'btc'
14
+ 'https://insight.bitpay.com/api'
15
+ else
16
+ 'https://test-insight.bitpay.com/api'
17
+ end
18
+ end
19
+
20
+ def network=(network)
21
+ @network = network
22
+ @connection = Connection.new(url)
23
+ end
24
+
25
+ def block(hash)
26
+ @connection.get("/block/#{hash}")
27
+ end
28
+
29
+ def block_raw(hash)
30
+ @connection.get("/rawblock/#{hash}")
31
+ end
32
+
33
+ def transaction(hash)
34
+ @connection.get("/tx/#{hash}")
35
+ end
36
+
37
+ def push_transaction(hex)
38
+ @connection.post('/tx/send', rawtx: hex)
39
+ end
40
+
41
+ def address(address)
42
+ @connection.get("/addr/#{address}")
43
+ end
44
+
45
+ def address_balance(address)
46
+ @connection.get("/addr/#{address}/balance")
47
+ end
48
+
49
+ def address_total_received(address)
50
+ @connection.get("/addr/#{address}/totalReceived")
51
+ end
52
+
53
+ def address_total_sent(address)
54
+ @connection.get("/addr/#{address}/totalSent")
55
+ end
56
+
57
+ def address_unconfirmed_balance(address)
58
+ @connection.get("/addr/#{address}/unconfirmedBalance")
59
+ end
60
+
61
+ def address_unspent_transactions(address, params = nil)
62
+ @connection.get("/addr/#{address}/utxo#{'?' + params.to_param if params}")
63
+ end
64
+
65
+ def estimatefee(nbBlocks = 2)
66
+ @connection.get("/utils/estimatefee?nbBlocks=#{nbBlocks}")
67
+ end
68
+ end
69
+ end
70
+
71
+ class Hash
72
+ def to_param
73
+ collect {|k, v| "#{k}=#{v}"} * '&'
74
+ end
75
+ end
@@ -0,0 +1,38 @@
1
+ module Insight
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 Insight
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: insight_bitpay
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: 2017-05-25 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
+ - !ruby/object:Gem::Dependency
98
+ name: bump
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.5'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 0.5.3
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '0.5'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 0.5.3
117
+ description: Ruby SDK for insight.bitpay.com API
118
+ email:
119
+ - genmadrid@gmail.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".editorconfig"
125
+ - ".gitignore"
126
+ - ".ruby-gemset"
127
+ - ".ruby-version"
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - bump
133
+ - insight-ruby.gemspec
134
+ - insight.sublime-project
135
+ - lib/insight.rb
136
+ - lib/insight/api.rb
137
+ - lib/insight/connection.rb
138
+ - lib/insight/version.rb
139
+ homepage: https://github.com/genmadrid/insight-ruby
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Ruby SDK for insight.bitpay.com
163
+ test_files: []