Class: Bitcoin::Request
- Inherits:
-
Object
- Object
- Bitcoin::Request
- Defined in:
- lib/bitcoin/request.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
Instance Method Summary collapse
-
#initialize(service_name, params = []) ⇒ Request
constructor
A new instance of Request.
- #to_hash ⇒ Object
- #to_post_data ⇒ Object
Constructor Details
#initialize(service_name, params = []) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bitcoin/request.rb', line 6 def initialize(service_name, params = []) @service_name = service_name @params = params.dup # bitcoin rejects null values even for optional params. Since # even params following those may have default non-nil values, # we'll assume the first non-nil value marks a set of optional # params, and drop it and everything following it. # # ex: # [nil] => [] # [1,nil,nil] => [1] # [1,nil,nil,1] => [1] if index = @params.index(nil) @params = @params[0...index] end end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/bitcoin/request.rb', line 4 def params @params end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
4 5 6 |
# File 'lib/bitcoin/request.rb', line 4 def service_name @service_name end |
Instance Method Details
#to_hash ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/bitcoin/request.rb', line 24 def to_hash { :method => service_name, :params => params, :id => "jsonrpc" } end |
#to_post_data ⇒ Object
32 33 34 |
# File 'lib/bitcoin/request.rb', line 32 def to_post_data to_hash.to_json end |