Class: Bcoin::Client
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/bcoin/client.rb,
lib/bcoin/client/base.rb,
lib/bcoin/client/master.rb,
lib/bcoin/client/wallet.rb,
lib/bcoin/client/account.rb,
lib/bcoin/client/balance.rb,
lib/bcoin/client/version.rb,
lib/bcoin/client/wallets.rb,
lib/bcoin/client/accounts.rb,
lib/bcoin/client/collection.rb,
lib/bcoin/client/http_methods.rb
Defined Under Namespace
Modules: HttpMethods
Classes: Account, Accounts, Balance, Base, Collection, Master, Wallet, Wallets
Constant Summary
collapse
- VERSION =
"0.3.3"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
21
22
23
|
# File 'lib/bcoin/client.rb', line 21
def initialize(options = {})
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
17
18
19
|
# File 'lib/bcoin/client.rb', line 17
def options
@options
end
|
Instance Method Details
#base_uri ⇒ Object
41
42
43
|
# File 'lib/bcoin/client.rb', line 41
def base_uri
[host, port].join(':')
end
|
#basic_auth ⇒ Object
45
46
47
|
# File 'lib/bcoin/client.rb', line 45
def basic_auth
password.nil? ? nil : {username: username, password: password}
end
|
#default_options ⇒ Object
49
50
51
52
53
54
|
# File 'lib/bcoin/client.rb', line 49
def default_options
{
base_uri: base_uri,
basic_auth: basic_auth
}
end
|
#delete(path, options = {}) ⇒ Object
73
74
75
|
# File 'lib/bcoin/client.rb', line 73
def delete path, options = {}
request :delete, path, body: options.to_json
end
|
#fee(blocks = 1) ⇒ Float
Check the current rate for processing a transaction within x number of blocks.
86
87
88
89
|
# File 'lib/bcoin/client.rb', line 86
def fee blocks = 1
response = get '/fee', blocks: blocks
response['rate']
end
|
#get(path, options = {}) ⇒ Object
61
62
63
|
# File 'lib/bcoin/client.rb', line 61
def get path, options = {}
request :get, path, query: options
end
|
#host ⇒ Object
29
30
31
|
# File 'lib/bcoin/client.rb', line 29
def host
@options[:host] || "localhost"
end
|
#password ⇒ Object
37
38
39
|
# File 'lib/bcoin/client.rb', line 37
def password
@options[:password]
end
|
#port ⇒ Object
25
26
27
|
# File 'lib/bcoin/client.rb', line 25
def port
@options[:port] || 8332
end
|
#post(path, options = {}) ⇒ Object
65
66
67
|
# File 'lib/bcoin/client.rb', line 65
def post path, options = {}
request :post, path, body: options.to_json
end
|
#put(path, options = {}) ⇒ Object
69
70
71
|
# File 'lib/bcoin/client.rb', line 69
def put path, options = {}
request :put, path, body: options.to_json
end
|
#request(method, path, options = {}) ⇒ Object
56
57
58
59
|
# File 'lib/bcoin/client.rb', line 56
def request method, path, options = {}
options.merge! default_options
self.class.send(method, path, options).parsed_response
end
|
#username ⇒ Object
33
34
35
|
# File 'lib/bcoin/client.rb', line 33
def username
@options[:username]
end
|
#wallets ⇒ Object
77
78
79
|
# File 'lib/bcoin/client.rb', line 77
def wallets
@wallets ||= Wallets.new(self)
end
|