Skip to content

Commit c378e25

Browse files
Merge pull request #37 from blockcypher/formatting
Formatting
2 parents 4f01692 + a973ef5 commit c378e25

File tree

6 files changed

+146
-143
lines changed

6 files changed

+146
-143
lines changed

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
begin
24
require 'rspec/core/rake_task'
35
RSpec::Core::RakeTask.new(:spec)

blockcypher-ruby.gemspec

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
# frozen_string_literal: true
2+
13
Gem::Specification.new do |s|
24
s.name = 'blockcypher-ruby'
35
s.summary = 'Blockcypher Ruby SDK'
46
s.version = '0.2.6'
57
s.licenses = ['Apache 2.0']
6-
s.description = "Ruby library to help you build your crypto application on BlockCypher"
7-
s.summary = "Ruby library to help you build your crypto application on BlockCypher"
8-
s.authors = ["CoinHako", "BlockCypher", "meXBT", 'Gem']
8+
s.description = 'Ruby library to help you build your crypto application on BlockCypher'
9+
s.summary = 'Ruby library to help you build your crypto application on BlockCypher'
10+
s.authors = %w[CoinHako BlockCypher meXBT Gem]
911
s.email = 'contact@blockcypher.com'
10-
s.files = Dir["{spec,lib}/**/*"] + %w(LICENSE README.md)
12+
s.files = Dir['{spec,lib}/**/*'] + %w[LICENSE README.md]
1113
s.homepage = 'http://www.blockcypher.com'
1214

13-
s.add_runtime_dependency "bitcoin-ruby", ["~> 0.0.5"]
14-
s.add_runtime_dependency "ffi"
15-
s.add_development_dependency "bundler", "~> 1.6"
16-
s.add_development_dependency "rake"
17-
s.add_development_dependency "rspec"
18-
s.add_development_dependency "pry"
19-
s.add_development_dependency "activesupport"
20-
s.add_development_dependency "vcr"
21-
s.add_development_dependency "webmock"
15+
s.add_runtime_dependency 'bitcoin-ruby', ['~> 0.0.5']
16+
s.add_runtime_dependency 'ffi'
17+
s.add_development_dependency 'activesupport'
18+
s.add_development_dependency 'bundler', '~> 1.6'
19+
s.add_development_dependency 'pry'
20+
s.add_development_dependency 'rake'
21+
s.add_development_dependency 'rspec'
22+
s.add_development_dependency 'vcr'
23+
s.add_development_dependency 'webmock'
2224
end

lib/blockcypher/api.rb

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
module BlockCypher
1+
# frozen_string_literal: true
22

3+
module BlockCypher
34
V1 = 'v1'
45

56
BTC = 'btc'
@@ -13,8 +14,7 @@ module BlockCypher
1314
TEST_NET_3 = 'test3'
1415

1516
class Api
16-
17-
class Error < RuntimeError ; end
17+
class Error < RuntimeError; end
1818

1919
attr_reader :api_token
2020

@@ -59,7 +59,7 @@ def faucet(address, amount)
5959
##################
6060

6161
def decode_hex(hex)
62-
payload = { 'tx' => hex}
62+
payload = { 'tx' => hex }
6363
api_http_post('/txs/decode', json_payload: payload)
6464
end
6565

@@ -69,10 +69,7 @@ def push_hex(hex)
6969
end
7070

7171
def send_money(from_address, to_address, satoshi_amount, private_key)
72-
73-
unless to_address.kind_of? Array
74-
to_address = [to_address]
75-
end
72+
to_address = [to_address] unless to_address.is_a? Array
7673

7774
tx_new = transaction_new([from_address], to_address, satoshi_amount)
7875

@@ -115,13 +112,13 @@ def signer(private_key, tosign)
115112
signatures = []
116113

117114
tosign.each do |to_sign_hex|
118-
to_sign_binary = [to_sign_hex].pack("H*")
115+
to_sign_binary = [to_sign_hex].pack('H*')
119116
sig_binary = key.sign(to_sign_binary)
120-
sig_hex = sig_binary.unpack("H*").first
117+
sig_hex = sig_binary.unpack1('H*')
121118
signatures << sig_hex
122119
end
123120

124-
return signatures
121+
signatures
125122
end
126123

127124
def transaction_new_custom(payload)
@@ -175,23 +172,23 @@ def address_generate
175172
end
176173

177174
def address_generate_multi(pubkeys, script_type)
178-
payload = { 'pubkeys' => pubkeys, 'script_type' => script_type}
175+
payload = { 'pubkeys' => pubkeys, 'script_type' => script_type }
179176
api_http_post('/addrs', json_payload: payload)
180177
end
181178

182179
def address_details(address, unspent_only: false, limit: 50,
183180
before: nil, after: nil, confirmations: nil,
184-
omit_wallet_addresses: false, include_confidence:false)
181+
omit_wallet_addresses: false, include_confidence: false)
185182
query = {
186183
unspentOnly: unspent_only,
187184
limit: limit,
188185
omitWalletAddresses: omit_wallet_addresses,
189-
includeConfidence: include_confidence
186+
includeConfidence: include_confidence
190187
}
191188
query[:before] = before if before
192-
query[:after] = after if after
189+
query[:after] = after if after
193190

194-
api_http_get('/addrs/' + address, query: query )
191+
api_http_get('/addrs/' + address, query: query)
195192
end
196193

197194
def address_balance(address, omit_wallet_addresses: false)
@@ -206,12 +203,12 @@ def address_final_balance(address, omit_wallet_addresses: false)
206203
end
207204

208205
def address_full_txs(address, limit: 10, before: nil, after: nil,
209-
include_hex: false, omit_wallet_addresses: false, include_confidence:false)
206+
include_hex: false, omit_wallet_addresses: false, include_confidence: false)
210207
query = {
211208
limit: limit,
212209
includeHex: include_hex,
213210
omitWalletAddresses: omit_wallet_addresses,
214-
includeConfidence: include_confidence
211+
includeConfidence: include_confidence
215212
}
216213
query[:before] = before if before
217214
query[:after] = after if after
@@ -224,7 +221,7 @@ def address_full_txs(address, limit: 10, before: nil, after: nil,
224221
##################
225222

226223
def wallet_create(name, addresses)
227-
payload = { 'name' => name, 'addresses' => Array(addresses)}
224+
payload = { 'name' => name, 'addresses' => Array(addresses) }
228225
api_http_post('/wallets', json_payload: payload)
229226
end
230227

@@ -244,8 +241,8 @@ def wallet_get_addr(name)
244241
end
245242

246243
def wallet_delete_addr(name, addresses)
247-
addrjoin = addresses.join(";")
248-
api_http_delete('/wallets/' + name + '/addresses', query: { address: addrjoin})
244+
addrjoin = addresses.join(';')
245+
api_http_delete('/wallets/' + name + '/addresses', query: { address: addrjoin })
249246
end
250247

251248
def wallet_gen_addr(name)
@@ -263,7 +260,7 @@ def wallet_delete(name)
263260
def event_webhook_subscribe(url, event, options = {})
264261
payload = {
265262
url: url,
266-
event: event,
263+
event: event
267264
}.merge(options)
268265

269266
api_http_post('/hooks', json_payload: payload)
@@ -295,44 +292,43 @@ def create_forwarding_address(
295292
destination: destination,
296293
callback_url: callback_url,
297294
enable_confirmations: enable_confirmations,
298-
mining_fees_satoshis: mining_fees_satoshis,
295+
mining_fees_satoshis: mining_fees_satoshis
299296
}
300297
api_http_post('/payments', json_payload: payload)
301298
end
302299

303-
alias :create_payments_forwarding :create_forwarding_address
300+
alias create_payments_forwarding create_forwarding_address
304301

305302
def list_forwarding_addresses
306-
api_http_get("/payments")
303+
api_http_get('/payments')
307304
end
308305

309306
def delete_forwarding_address(id)
310-
api_http_delete("/payments/" + id)
307+
api_http_delete('/payments/' + id)
311308
end
312309

313-
314310
#############
315311
# Asset API #
316312
#############
317313

318314
def generate_asset_address
319-
api_http_post("/oap/addrs")
315+
api_http_post('/oap/addrs')
320316
end
321317

322318
def issue_asset(from_private, to_address, amount)
323-
api_http_post("/oap/issue", json_payload: {
324-
from_private: from_private,
325-
to_address: to_address,
326-
amount: amount
327-
})
319+
api_http_post('/oap/issue', json_payload: {
320+
from_private: from_private,
321+
to_address: to_address,
322+
amount: amount
323+
})
328324
end
329325

330326
def transfer_asset(asset_id, from_private, to_address, amount)
331327
api_http_post("/oap/#{asset_id}/transfer", json_payload: {
332-
from_private: from_private,
333-
to_address: to_address,
334-
amount: amount
335-
})
328+
from_private: from_private,
329+
to_address: to_address,
330+
amount: amount
331+
})
336332
end
337333

338334
def asset_txs(asset_id)
@@ -349,7 +345,7 @@ def api_http_call(http_method, api_path, query, json_payload: nil)
349345
uri = endpoint_uri(api_path, query)
350346

351347
# Build the connection
352-
http = Net::HTTP.new(uri.host, uri.port)
348+
http = Net::HTTP.new(uri.host, uri.port)
353349
http.use_ssl = true
354350

355351
# Build the Request
@@ -373,16 +369,16 @@ def api_http_call(http_method, api_path, query, json_payload: nil)
373369

374370
# Detect errors/return 204 empty body
375371
if response_code >= 400
376-
raise Error.new(uri.to_s + ' Response:' + response.body)
372+
raise Error, uri.to_s + ' Response:' + response.body
377373
elsif response_code == 204
378374
return nil
379375
end
380376

381377
# Process the response
382378
begin
383379
json_response = JSON.parse(response.body)
384-
return json_response
385-
rescue => e
380+
json_response
381+
rescue StandardError => e
386382
raise "Unable to parse JSON response #{e.inspect}, #{response.body}"
387383
end
388384
end

0 commit comments

Comments
 (0)