Class: Paystack::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/paystack/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
19
# File 'lib/paystack/response.rb', line 10

def initialize(http_response)
  @http_status = http_response.code.to_i
  body = http_response.body.to_s
  parsed = body.empty? ? {} : JSON.parse(body, symbolize_names: true)
  @status = parsed[:status]
  @message = parsed[:message]
  @data = parsed[:data]
  @meta = parsed[:meta]
  raise_error! unless success?
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/paystack/response.rb', line 8

def data
  @data
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



8
9
10
# File 'lib/paystack/response.rb', line 8

def http_status
  @http_status
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/paystack/response.rb', line 8

def message
  @message
end

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/paystack/response.rb', line 8

def meta
  @meta
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/paystack/response.rb', line 8

def status
  @status
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/paystack/response.rb', line 21

def success?
  (200..299).cover?(@http_status) && @status != false
end