Class: PaylineSDK::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/payline_sdk/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Request

Returns a new instance of Request.



4
5
6
7
8
# File 'lib/payline_sdk/request.rb', line 4

def initialize(opts = {})
  define_accessors
  set_attributes(opts)
  self.version = 3
end

Instance Method Details

#set_attributes(attributes) ⇒ Object



10
11
12
13
14
# File 'lib/payline_sdk/request.rb', line 10

def set_attributes(attributes)
  attributes.each do |k,v|
    instance_variable_set("@#{k}", v)
  end
end

#to_requestable_attribute(obj) ⇒ Object

Recursive method to transform the following objects to Hash (Search in depth):

- PaylineSDK::Object::Base
- Un objet definissant la methode :to_payline_sdk_obj


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/payline_sdk/request.rb', line 19

def to_requestable_attribute(obj)
  if obj.is_a?(Hash)
    obj.each do |k,v|
      obj[k] = to_requestable_attribute(v)
    end
  elsif obj.is_a?(PaylineSDK::Object::Base)
    obj = to_requestable_attribute(obj.to_h)
  elsif obj.class.method_defined?(:to_payline_sdk_obj)
    obj = to_requestable_attribute(obj.to_payline_sdk_obj.to_h)
  end
  return obj
end

#to_requestable_hash(allowed_keys) ⇒ Object

Transform current Request object to hash



33
34
35
# File 'lib/payline_sdk/request.rb', line 33

def to_requestable_hash(allowed_keys)
  Hash[allowed_keys.zip(allowed_keys.map {|key| to_requestable_attribute(eval("@#{key.to_s}"))})]
end