Class: BtcPay::Client::Result
- Inherits:
-
Object
- Object
- BtcPay::Client::Result
- Defined in:
- lib/btcpay/client/result.rb
Overview
Status object to capture result from an HTTP request
Gives callers context of the result and allows them to implement successful strategies to handle success/failure
Defined Under Namespace
Classes: ResponseBodyParseError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #failure? ⇒ Boolean
-
#initialize(status, response) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
- #to_h ⇒ Object (also: #to_hash)
Constructor Details
#initialize(status, response) ⇒ Result
Returns a new instance of Result.
24 25 26 27 28 29 30 31 |
# File 'lib/btcpay/client/result.rb', line 24 def initialize(status, response) @code = response.code @headers = response.headers # e.g. "Content-Type" will become :content_type. @status = status @raw = raw_parse(response.body) @body = rubify_body end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object (private)
54 55 56 |
# File 'lib/btcpay/client/result.rb', line 54 def method_missing(method, *args, &blk) to_h.send(method, *args, &blk) || super end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
22 23 24 |
# File 'lib/btcpay/client/result.rb', line 22 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
22 23 24 |
# File 'lib/btcpay/client/result.rb', line 22 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
22 23 24 |
# File 'lib/btcpay/client/result.rb', line 22 def headers @headers end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
22 23 24 |
# File 'lib/btcpay/client/result.rb', line 22 def raw @raw end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
22 23 24 |
# File 'lib/btcpay/client/result.rb', line 22 def status @status end |
Class Method Details
.failed(response) ⇒ Object
18 19 20 |
# File 'lib/btcpay/client/result.rb', line 18 def self.failed(response) new(:failed, response) end |
.success(response) ⇒ Object
14 15 16 |
# File 'lib/btcpay/client/result.rb', line 14 def self.success(response) new(:success, response) end |
Instance Method Details
#failure? ⇒ Boolean
37 38 39 |
# File 'lib/btcpay/client/result.rb', line 37 def failure? !success? end |
#success? ⇒ Boolean
33 34 35 |
# File 'lib/btcpay/client/result.rb', line 33 def success? status == :success end |
#to_h ⇒ Object Also known as: to_hash
41 42 43 44 45 46 47 48 |
# File 'lib/btcpay/client/result.rb', line 41 def to_h { status: status, headers: headers, code: code, body: body } end |