razrbit 0.0.1

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: e3a9def55d9ba4c6c840583dc906e09ecbd927fc
4
+ data.tar.gz: fcec83dc0d8f9f8a9ea18d40e2fde57b1f081f87
5
+ SHA512:
6
+ metadata.gz: 57bc74e555b32b655b573dbc7ea889faefdd9d56cfe58be1c61366e0afe235d158b45e3bd519781a53f307e9cb7ed0b5ebe98d9e56051b1d9578f035a3e41500
7
+ data.tar.gz: a78b9237ba805bc5e2c09ab7de969ec32758c48ed72edee504fc41f6097e46dfbfb2c2777f4a10c61329c4f87fb64fee7caa6b62718a31cccc1f1b7f65d28920
data/README.md ADDED
@@ -0,0 +1,257 @@
1
+ <img src="http://luxstack.com/images/razrbit-github-banner-dark-beta.png" style="width:100%"/>
2
+
3
+ Official SDKs:
4
+ [Android](https://github.com/LUXSTACK/razrbit-sdk-android) |
5
+ [iOS](https://github.com/LUXSTACK/razrbit-sdk-ios) |
6
+ [Javascript](https://github.com/LUXSTACK/razrbit-sdk-javascript) |
7
+ [PHP](https://github.com/LUXSTACK/razrbit-sdk-php) |
8
+ Ruby
9
+
10
+ **[Razrbit](https://www.razrbit.com) is a powerful API that helps developers quickly build and manage Bitcoin applications without creating and maintaining complicated block chain infrastructure.**
11
+
12
+ # Razrbit SDK for Ruby
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ gem install razrbit
18
+ ```
19
+
20
+ ## HTTP Examples
21
+
22
+ ### Wallet
23
+
24
+ ```ruby
25
+ require 'razrbit'
26
+
27
+ wallet = Razrbit::Wallet.new(app_id: '', app_secret: '')
28
+
29
+ response = wallet.create_new_address
30
+
31
+ response = wallet.send_amount(from_address_private_key: '',
32
+ to_address: '',
33
+ satoshi_amount: 0)
34
+
35
+ response = wallet.balance_from_address(address: '')
36
+
37
+ case response
38
+ when Net::HTTPSuccess then
39
+ response
40
+ else
41
+ # handle error
42
+ end
43
+ ```
44
+
45
+ ### Explorer
46
+
47
+ ```ruby
48
+ require 'razrbit'
49
+
50
+ explorer = Razrbit::Explorer.new(app_id: '', app_secret: '')
51
+
52
+ response = explorer.block(block_hash: '')
53
+ response = explorer.transaction(transaction_hash: '')
54
+ response = explorer.address(address: '')
55
+ response = explorer.address_unspent_outputs(address: '')
56
+
57
+ case response
58
+ when Net::HTTPSuccess then
59
+ response
60
+ else
61
+ # handle error
62
+ end
63
+ ```
64
+
65
+ ### Network
66
+
67
+ ```ruby
68
+ require 'razrbit'
69
+
70
+ network = Razrbit::Network.new(app_id: '', app_secret: '')
71
+
72
+ response = network.get_difficulty
73
+ response = network.push_transaction(transaction: '')
74
+
75
+ case response
76
+ when Net::HTTPSuccess then
77
+ response
78
+ else
79
+ # handle error
80
+ end
81
+ ```
82
+
83
+ ### Markets
84
+
85
+ ```ruby
86
+ require 'razrbit'
87
+
88
+ markets = Razrbit::Markets.new(app_id: '', app_secret: '')
89
+
90
+ response = markets.price(currency_code: 'USD')
91
+ response = markets.day_price(currency_code: 'USD')
92
+ response = markets.historical_price(currency_code: 'USD',
93
+ date: '2014-08-14')
94
+
95
+
96
+ case response
97
+ when Net::HTTPSuccess then
98
+ response
99
+ else
100
+ # handle error
101
+ end
102
+ ```
103
+
104
+ ### Webhook
105
+
106
+ ```ruby
107
+ require 'razrbit'
108
+
109
+ notifications = Razrbit::Notifications.new(app_id: '', app_secret: '')
110
+
111
+ response = notifications.address(address: '',
112
+ email: 'example@example.com')
113
+
114
+ response = notifications.block(block_hash: '',
115
+ email: 'example@example.com')
116
+
117
+ response = notifications.transaction(transaction_hash: '',
118
+ email: 'example@example.com')
119
+
120
+ case response
121
+ when Net::HTTPSuccess then
122
+ response
123
+ else
124
+ # handle error
125
+ end
126
+ ```
127
+
128
+ ## API
129
+
130
+ ### Wallet
131
+
132
+ ```
133
+ response = wallet.create_new_address
134
+ ```
135
+ Creates a new bitcoin address in your wallet
136
+
137
+ ```
138
+ response = wallet.send_amount(from_address_private_key: '', to_address: '', satoshi_amount: 0)
139
+ ```
140
+ Sends bitcoin from one of your addresses to the destination address.
141
+
142
+ ```
143
+ response = wallet.balance_from_address(address: '')
144
+ ```
145
+ Returns the balance of the given address in satoshis.
146
+
147
+
148
+ ### Explorer
149
+
150
+ ```
151
+ response = explorer.block(block_hash: '')
152
+ ```
153
+ Retrieve details about a given block
154
+
155
+ ```
156
+ response = explorer.transaction(transaction_hash: '')
157
+ ```
158
+ Retrieve details about a given transaction
159
+
160
+ ```
161
+ response = explorer.address(address: '')
162
+ ```
163
+ Retrieve details about a given address
164
+
165
+ ```
166
+ response = explorer.address_unspent_outputs(address: '')
167
+ ```
168
+ Returns the list of unspent outputs for a given address
169
+
170
+
171
+ ### Network
172
+
173
+ ```
174
+ response = network.get_difficulty
175
+ ```
176
+ Retrieve the current network difficulty
177
+
178
+ ```
179
+ response = network.push_transaction(transaction: '')
180
+ ```
181
+ Push a transaction on the network
182
+
183
+
184
+ ### Markets
185
+
186
+ `currencyCode` is a valid ISO 4217 code such as `USD` or `EUR`.
187
+
188
+ ```
189
+ response = markets.price(currency_code: 'USD')
190
+ ```
191
+ Returns the current bitcoin price
192
+
193
+ ```
194
+ response = markets.day_price(currency_code: 'USD')
195
+ ```
196
+ Returns the day price
197
+
198
+ ```
199
+ response = markets.historical_price(currency_code: 'USD', date: '2014-08-14')
200
+ ```
201
+ Returns the historical price at the given date.
202
+ `date` must be a date in the `yyyy-mm-dd` format.
203
+
204
+ ### Notifications
205
+
206
+ ```
207
+ response = notifications.address(address: '', email: 'example@example.com')
208
+ ```
209
+ Setup a notification email for a given address
210
+
211
+ ```
212
+ response = notifications.blocks(block_hash: '', email: 'example@example.com')
213
+ ```
214
+ Setup a notification email for a given block
215
+
216
+ ```
217
+ response = notifications.transactions(transaction_hash: '', email: 'example@example.com')
218
+ ```
219
+ Setup a notification email for a given transaction
220
+
221
+ # Support
222
+
223
+ Feel free to request a feature and make suggestions for our [product team](mailto:team@luxstack.com).
224
+
225
+ * [GitHub Issues](https://github.com/luxstack/razrbit-sdk-ruby/issues)
226
+
227
+ # License
228
+
229
+ The MIT License (MIT)
230
+
231
+ Copyright (c) 2014 LUXSTACK Inc.
232
+
233
+ Permission is hereby granted, free of charge, to any person obtaining a copy
234
+ of this software and associated documentation files (the "Software"), to deal
235
+ in the Software without restriction, including without limitation the rights
236
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
237
+ copies of the Software, and to permit persons to whom the Software is
238
+ furnished to do so, subject to the following conditions:
239
+
240
+ The above copyright notice and this permission notice shall be included in
241
+ all copies or substantial portions of the Software.
242
+
243
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
244
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
245
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
246
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
247
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
248
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
249
+ THE SOFTWARE.
250
+
251
+ # Official Razrbit SDKs for other platforms
252
+
253
+ * [Android](https://github.com/LUXSTACK/razrbit-sdk-android)
254
+ * [iOS](https://github.com/LUXSTACK/razrbit-sdk-ios)
255
+ * [Javascript](https://github.com/LUXSTACK/razrbit-sdk-javascript)
256
+ * [PHP](https://github.com/LUXSTACK/razrbit-sdk-php)
257
+ * Ruby
@@ -0,0 +1,45 @@
1
+ require 'razrbit/http'
2
+
3
+ module Razrbit
4
+ class Explorer < HTTP
5
+ def block(block_hash: nil)
6
+ uri = create_uri 'explorer/block'
7
+
8
+ form_data = {
9
+ 'blockHash' => block_hash
10
+ }
11
+
12
+ post(uri, form_data)
13
+ end
14
+
15
+ def transaction(transaction_hash: nil)
16
+ uri = create_uri 'explorer/transaction'
17
+
18
+ form_data = {
19
+ 'transactionHash' => transaction_hash
20
+ }
21
+
22
+ post(uri, form_data)
23
+ end
24
+
25
+ def address(address: nil)
26
+ uri = create_uri 'explorer/address'
27
+
28
+ form_data = {
29
+ 'address' => address
30
+ }
31
+
32
+ post(uri, form_data)
33
+ end
34
+
35
+ def address_unspent_outputs(address: nil)
36
+ uri = create_uri 'explorer/addressUnspentOutputs'
37
+
38
+ form_data = {
39
+ 'address' => address
40
+ }
41
+
42
+ post(uri, form_data)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+
4
+ module Razrbit
5
+ class HTTP
6
+ attr_accessor :app_id, :app_secret
7
+
8
+ def initialize(app_id: nil, app_secret: nil)
9
+ @app_id = app_id
10
+ @app_secret = app_secret
11
+ end
12
+
13
+ protected
14
+
15
+ def create_uri(endpoint)
16
+ site = 'https://api.razrbit.com/api/v1/'
17
+ uri = URI.join(site, endpoint)
18
+ end
19
+
20
+ def create_https(uri)
21
+ https = Net::HTTP.new(uri.hostname, uri.port)
22
+ https.use_ssl = true
23
+ https
24
+ end
25
+
26
+ def app_form_data
27
+ {
28
+ 'appId' => app_id,
29
+ 'appSecret' => app_secret,
30
+ }
31
+ end
32
+
33
+ def create_post(uri, data = {})
34
+ form_data = app_form_data.update(data)
35
+ request = Net::HTTP::Post.new(uri.path)
36
+ request.set_form_data(form_data)
37
+ request
38
+ end
39
+
40
+ def post(uri, form_data = {})
41
+ https = create_https uri
42
+ request = create_post(uri, form_data)
43
+ response = https.request request
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ require 'razrbit/http'
2
+
3
+ module Razrbit
4
+ class Markets < HTTP
5
+ def price(currency_code: nil)
6
+ uri = create_uri 'markets/price'
7
+
8
+ form_data = {
9
+ 'currencyCode' => currency_code
10
+ }
11
+
12
+ post(uri, form_data)
13
+ end
14
+
15
+ def day_price(currency_code: nil)
16
+ uri = create_uri 'markets/dayPrice'
17
+
18
+ form_data = {
19
+ 'currencyCode' => currency_code
20
+ }
21
+
22
+ post(uri, form_data)
23
+ end
24
+
25
+ def historical_price(currency_code: nil, date: nil)
26
+ uri = create_uri 'markets/historicalPrice'
27
+
28
+ form_data = {
29
+ 'currencyCode' => currency_code,
30
+ 'date' => date
31
+ }
32
+
33
+ post(uri, form_data)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ require 'razrbit/http'
2
+
3
+ module Razrbit
4
+ class Network < HTTP
5
+ def get_difficulty
6
+ uri = create_uri 'network/getDifficulty'
7
+
8
+ post(uri)
9
+ end
10
+
11
+ def push_transaction(transaction: nil)
12
+ uri = create_uri 'network/pushTransaction'
13
+
14
+ form_data = {
15
+ 'transaction' => transaction
16
+ }
17
+
18
+ post(uri, form_data)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'razrbit/http'
2
+
3
+ module Razrbit
4
+ class Notifications < HTTP
5
+ def address(address: nil, email: nil)
6
+ uri = create_uri 'notifications/address'
7
+
8
+ form_data = {
9
+ 'address' => address,
10
+ 'email' => email
11
+ }
12
+
13
+ post(uri, form_data)
14
+ end
15
+
16
+ def block(block_hash: nil, email: nil)
17
+ uri = create_uri 'notifications/block'
18
+
19
+ form_data = {
20
+ 'blockHash' => block_hash,
21
+ 'email' => email
22
+ }
23
+
24
+ post(uri, form_data)
25
+ end
26
+
27
+ def transaction(transaction_hash: nil, email: nil)
28
+ uri = create_uri 'notifications/transaction'
29
+
30
+ form_data = {
31
+ 'transactionHash' => transaction_hash,
32
+ 'email' => email
33
+ }
34
+
35
+ post(uri, form_data)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Razrbit
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,33 @@
1
+ require 'razrbit/http'
2
+
3
+ module Razrbit
4
+ class Wallet < HTTP
5
+ def create_new_address
6
+ uri = create_uri 'wallet/createNewAddress'
7
+ post(uri)
8
+ end
9
+
10
+ def send_amount(from_address_private_key: nil, to_address: nil, satoshi_amount: nil)
11
+ uri = create_uri 'wallet/sendAmount'
12
+
13
+ form_data = {
14
+ 'fromAddressPrivateKey' => from_address_private_key,
15
+ 'toAddress' => to_address,
16
+ 'satoshiAmount' => satoshi_amount
17
+ }
18
+
19
+ post(uri, form_data)
20
+ end
21
+
22
+ def balance_from_address(address: address)
23
+ uri = create_uri 'wallet/getBalanceFromAddress'
24
+
25
+ form_data = {
26
+ 'address' => address
27
+ }
28
+
29
+ post(uri, form_data)
30
+ end
31
+
32
+ end
33
+ end
data/lib/razrbit.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'razrbit/version'
2
+
3
+ require 'razrbit/wallet'
4
+ require 'razrbit/explorer'
5
+ require 'razrbit/network'
6
+ require 'razrbit/markets'
7
+ require 'razrbit/notifications'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: razrbit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - LUXSTACK
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: websocket-client-simple
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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:
84
+ email: devops@luxstack.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - README.md
90
+ - lib/razrbit.rb
91
+ - lib/razrbit/explorer.rb
92
+ - lib/razrbit/http.rb
93
+ - lib/razrbit/markets.rb
94
+ - lib/razrbit/network.rb
95
+ - lib/razrbit/notifications.rb
96
+ - lib/razrbit/version.rb
97
+ - lib/razrbit/wallet.rb
98
+ homepage: https://github.com/LUXSTACK/razrbit-sdk-ruby
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Razrbit
122
+ test_files: []