Class: BtcPay::Client::Result

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



22
23
24
# File 'lib/btcpay/client/result.rb', line 22

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



22
23
24
# File 'lib/btcpay/client/result.rb', line 22

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



22
23
24
# File 'lib/btcpay/client/result.rb', line 22

def headers
  @headers
end

#rawObject (readonly)

Returns the value of attribute raw.



22
23
24
# File 'lib/btcpay/client/result.rb', line 22

def raw
  @raw
end

#statusObject (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

Returns:

  • (Boolean)


37
38
39
# File 'lib/btcpay/client/result.rb', line 37

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/btcpay/client/result.rb', line 33

def success?
  status == :success
end

#to_hObject 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