block_io 0.1.0

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: 2c5193b5a4dd01b4b24b14f64b19dfcf2456804a
4
+ data.tar.gz: db1abcc37ba23f373029aaaa167dd00a04b96ebc
5
+ SHA512:
6
+ metadata.gz: f38eb4a78f03aeab0feb85a7f4780643a857766adaf6e1efd7d2b751dda0434419d2bfdcaaf15be1dbc0d08a44412eb42e9e79dfde9b47f2ed8a7bf45d134065
7
+ data.tar.gz: 05fcea2062eb66e6683959659eccbd41914900874db4e0db706fe239a7b8b7a962ca02f80656ab2d44ef542f5e095e3d0f867b2587043d2eb327315ed30f7aee
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in block_io.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 BlockIo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Atif Nazir
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,39 @@
1
+ # BlockIo
2
+
3
+ This Ruby Gem is the official reference client for the Block.io payments API. To use this, you will need the Dogecoin, Bitcoin, or Litecoin API key(s) from <a href="https://block.io" target="_blank">Block.io</a>. Go ahead, sign up :)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'block_io'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install block_io
18
+
19
+ ## Usage
20
+
21
+ It's super easy to get started. In your Ruby shell ($ irb), for example, do this:
22
+
23
+ require 'block_io'
24
+ BlockIo.set_options :api_key => 'API KEY', :pin => 'SECRET PIN'
25
+
26
+ And you're good to go:
27
+
28
+ BlockIo.get_new_address
29
+ BlockIo.get_my_addresses
30
+
31
+ For more information, see https://block.io/api
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/block_io/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/block_io.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'block_io/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "block_io"
8
+ spec.version = BlockIo::VERSION
9
+ spec.authors = ["Atif Nazir"]
10
+ spec.email = ["a@block.io"]
11
+ spec.summary = %q{An easy to use Dogecoin, Bitcoin, Litecoin wallet API by Block.io. Sign up required at Block.io.}
12
+ spec.description = %q{This Ruby Gem is the official reference client for the Block.io payments API. To use this, you will need the Dogecoin, Bitcoin, or Litecoin API key(s) from Block.io. Go ahead, sign up :)}
13
+ spec.homepage = "https://block.io/api/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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "httpclient", "~> 2.4"
23
+ spec.add_development_dependency "json", "~> 1.8"
24
+ spec.add_development_dependency "connection_pool", "~> 2.0"
25
+ spec.add_development_dependency "rake", "~> 0"
26
+ end
@@ -0,0 +1,3 @@
1
+ module BlockIo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/block_io.rb ADDED
@@ -0,0 +1,203 @@
1
+ require "block_io/version"
2
+ require 'httpclient'
3
+ require 'json'
4
+ require 'connection_pool'
5
+
6
+ module BlockIo
7
+
8
+ @api_key = nil
9
+ @base_url = "https://block.io/api/v1/API_CALL/?api_key="
10
+ @pin = nil
11
+ @conn_pool = nil
12
+
13
+ def self.set_options(args = {})
14
+ # initialize BlockIo
15
+ @api_key = args[:api_key]
16
+ @pin = args[:pin]
17
+ @conn_pool = ConnectionPool.new(size: 5, timeout: 300) { HTTPClient.new }
18
+
19
+ self.api_call(['get_balance',""])
20
+ end
21
+
22
+ def self.get_offline_vault_balance
23
+ # returns the offline vault's balance
24
+ endpoint = ["get_offline_vault_balance",""]
25
+ self.api_call(endpoint)
26
+ end
27
+
28
+ def self.get_offline_vault_address
29
+ # returns the offline vault's address and balance info
30
+ self.get_offline_vault_balance
31
+ end
32
+
33
+ def self.get_balance
34
+ # returns the balances for your account tied to the API key
35
+ endpoint = ["get_balance", ""]
36
+ self.api_call(endpoint)
37
+ end
38
+
39
+ def self.get_user_balance(args)
40
+ # returns the specified user's balance
41
+
42
+ user_id = args[:user_id]
43
+
44
+ raise Exception.new("Must provide user_id") if user_id.nil?
45
+
46
+ endpoint = ['get_user_balance',"&user_id=#{user_id}"]
47
+
48
+ self.api_call(endpoint)
49
+ end
50
+
51
+ def self.get_address_balance(args)
52
+ # returns the specified address or address_label's balance
53
+
54
+ address = args[:address]
55
+ address_label = args[:address_label]
56
+
57
+ raise Exception.new("Must provide ONE of address or address_label") if (!address.nil? and !address_label.nil?) or (address.nil? and address_label.nil?)
58
+
59
+ endpoint = ['get_address_balance',"&address=#{address}"] unless address.nil?
60
+ endpoint = ['get_address_balance',"&address_label=#{address_label}"] unless address_label.nil?
61
+
62
+ self.api_call(endpoint)
63
+ end
64
+
65
+ def self.get_current_price(args = {})
66
+ # returns prices from different exchanges as an array of hashes
67
+ price_base = args[:price_base]
68
+
69
+ endpoint = ['get_current_price', '']
70
+ endpoint = ['get_current_price',"&price_base=#{price_base}"] unless price_base.nil? or price_base.to_s.length == 0
71
+
72
+ self.api_call(endpoint)
73
+ end
74
+
75
+ def self.withdraw_from_user(args = {})
76
+ # withdraws coins from the given user(s)
77
+ self.withdraw(args)
78
+ end
79
+
80
+ def self.withdraw(args = {})
81
+ # validate arguments for withdrawal of funds TODO
82
+
83
+ raise Exception.new("PIN not set. Use BlockIo.set_options(:api_key=>'API KEY',:pin=>'SECRET PIN')") if @pin.nil?
84
+
85
+ # validate argument sets
86
+ amount = args[:amount]
87
+ to_user_id = args[:to_user_id]
88
+ payment_address = args[:payment_address]
89
+ from_user_ids = args[:from_user_ids] || args[:from_user_id]
90
+
91
+ raise Exception.new("Must provide ONE of payment_address, or to_user_id") if (!to_user_id.nil? and !payment_address.nil?) or (to_user_id.nil? and payment_address.nil?)
92
+ raise Exception.new("Must provide amount to withdraw") if amount.nil?
93
+
94
+ endpoint = ['withdraw',"&amount=#{amount}&payment_address=#{payment_address}&pin=#{@pin}"] unless payment_address.nil?
95
+ endpoint = ['withdraw',"&amount=#{amount}&to_user_id=#{to_user_id}&pin=#{@pin}"] unless to_user_id.nil?
96
+ endpoint = ['withdraw',"&amount=#{amount}&from_user_ids=#{from_user_ids}&pin=#{@pin}&payment_address=#{payment_address}"] unless from_user_ids.nil? or payment_address.nil?
97
+ endpoint = ['withdraw',"&amount=#{amount}&from_user_ids=#{from_user_ids}&to_user_id=#{to_user_id}&pin=#{@pin}"] unless to_user_id.nil? or from_user_ids.nil?
98
+
99
+ self.api_call(endpoint)
100
+ end
101
+
102
+ def self.get_new_address(args = {})
103
+ # validate arguments for getting a new address
104
+ address_label = args[:address_label]
105
+
106
+ endpoint = ['get_new_address','']
107
+ endpoint = ["get_new_address","&address_label=#{address_label}"] unless address_label.nil?
108
+
109
+ self.api_call(endpoint)
110
+ end
111
+
112
+ def self.create_user(args = {})
113
+ # validate arguments for getting a new address
114
+ address_label = args[:address_label]
115
+
116
+ endpoint = ['create_user','']
117
+ endpoint = ['create_user',"&address_label=#{address_label}"] unless address_label.nil?
118
+
119
+ self.api_call(endpoint)
120
+ end
121
+
122
+ def self.get_my_addresses(args = {})
123
+ # returns all the addresses in your account tied to the API key
124
+ endpoint = ["get_my_addresses",""]
125
+
126
+ self.api_call(endpoint)
127
+ end
128
+
129
+ def self.get_users(args = {})
130
+ # returns all the addresses in your account tied to the API key
131
+ endpoint = ['get_users',""]
132
+
133
+ self.api_call(endpoint)
134
+ end
135
+
136
+ def self.get_address_received(args = {})
137
+ # get coins received, confirmed and unconfirmed, by the given address, address_label, or user_id
138
+ address_label = args[:address_label]
139
+ user_id = args[:user_id]
140
+ address = args[:address]
141
+
142
+ raise Exception.new("Must provide ONE of address_label, user_id, or address") unless args.keys.length == 1 and (!address_label.nil? or !user_id.nil? or !address.nil?)
143
+
144
+ endpoint = ['get_address_received','']
145
+ endpoint = ["get_address_received","&user_id=#{user_id}"] unless user_id.nil?
146
+ endpoint = ['get_address_received',"&address_label=#{address_label}"] unless address_label.nil?
147
+ endpoint = ['get_address_received',"&address=#{address}"] unless address.nil?
148
+
149
+ self.api_call(endpoint)
150
+ end
151
+
152
+ def self.get_user_received(args = {})
153
+ # returns the user's received coins, confirmed and unconfirmed
154
+
155
+ user_id = args[:user_id]
156
+
157
+ raise Exception.new("Must provide user_id") if user_id.nil?
158
+
159
+ self.get_address_received(:user_id => user_id)
160
+ end
161
+
162
+ def self.get_address_by_label(args = {})
163
+ # get address by label
164
+
165
+ address_label = args[:address_label]
166
+
167
+ raise Exception.new("Must provide address_label") if address_label.nil?
168
+
169
+ endpoint = ["get_address_by_label","&address_label=#{address_label}"]
170
+
171
+ self.api_call(endpoint)
172
+ end
173
+
174
+ def self.get_user_address(args = {})
175
+ # gets the user's address
176
+
177
+ user_id = args[:user_id]
178
+
179
+ raise Exception.new("Must provide user_id") if user_id.nil?
180
+
181
+ endpoint = ['get_user_address',"&user_id=#{user_id}"]
182
+
183
+ self.api_call(endpoint)
184
+ end
185
+
186
+ private
187
+
188
+ def self.api_call(endpoint)
189
+
190
+ body = nil
191
+
192
+ @conn_pool.with do |hc|
193
+ # prevent initiation of HTTPClients every time we make this call, use a connection_pool
194
+
195
+ response = hc.get("#{@base_url.gsub('API_CALL',endpoint[0]) + @api_key + endpoint[1]}")
196
+ body = JSON.parse(response.body)
197
+
198
+ end
199
+
200
+ body
201
+ end
202
+
203
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: block_io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Atif Nazir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httpclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: connection_pool
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This Ruby Gem is the official reference client for the Block.io payments
84
+ API. To use this, you will need the Dogecoin, Bitcoin, or Litecoin API key(s) from
85
+ Block.io. Go ahead, sign up :)
86
+ email:
87
+ - a@block.io
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - Gemfile
93
+ - LICENSE
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - block_io.gemspec
98
+ - lib/block_io.rb
99
+ - lib/block_io/version.rb
100
+ homepage: https://block.io/api/ruby
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: An easy to use Dogecoin, Bitcoin, Litecoin wallet API by Block.io. Sign up
124
+ required at Block.io.
125
+ test_files: []