Class: Flutterwave::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



5
6
7
# File 'lib/flutterwave/response.rb', line 5

def initialize(response)
  @response = response ? OpenStruct.new(response['data']) : OpenStruct.new({})
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



17
18
19
20
# File 'lib/flutterwave/response.rb', line 17

def method_missing(method_name, *args)
  return response.send(method_name, *args) if response.respond_to?(method_name)
  super
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/flutterwave/response.rb', line 3

def response
  @response
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/flutterwave/response.rb', line 13

def failed?
  !successful?
end

#successful?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/flutterwave/response.rb', line 9

def successful?
  (try('responseCode') || try('responsecode')) == '00'
end

#try(method_name) ⇒ Object



22
23
24
25
26
# File 'lib/flutterwave/response.rb', line 22

def try(method_name)
  instance_eval method_name
rescue NameError
  nil
end