Class: BillsPayment::BillsPaymentObject

Inherits:
Object
  • Object
show all
Defined in:
lib/bills-payment/bills_payment_object.rb

Direct Known Subclasses

Worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ BillsPaymentObject

Returns a new instance of BillsPaymentObject.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bills-payment/bills_payment_object.rb', line 6

def initialize(params)
  if params.is_a?(Hash)
    @params = params
    assign_attributes(@params)
  elsif params.is_a?(String)
    @params = { id: params }
    assign_attributes(@params)
  else
    @params = {}
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/bills-payment/bills_payment_object.rb', line 4

def id
  @id
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/bills-payment/bills_payment_object.rb', line 3

def params
  @params
end

Instance Method Details

#api_urlObject



53
54
55
# File 'lib/bills-payment/bills_payment_object.rb', line 53

def api_url
  "#{CGI.escape(class_name.downcase)}s"
end

#attributesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bills-payment/bills_payment_object.rb', line 24

def attributes
  attrs = {}
  instance_variables.reject { |var| var == '@params' }.each do |var|
    str = var.to_s.gsub(/^@/, '')
    next unless respond_to?("#{str}=")
    instance_var = instance_variable_get(var)
    if Util.object_classes[str]
      if instance_var.is_a?(BillsPaymentObject)
        attrs[Util.to_camel_case_lower(str).to_sym] = parse_bills_payment_obj(instance_var)
      elsif instance_var.is_a?(Array)
        objs = []
        instance_var.each do |object|
          objs << parse_billspayment_obj(object)
        end
        attrs[Util.to_camel_case_lower(str).to_sym] = objs
      else
        attrs[Util.to_camel_case_lower(str).to_sym] = instance_var
      end
    else
      attrs[Util.to_camel_case_lower(str).to_sym] = instance_var
    end
  end
  attrs
end

#class_nameObject



49
50
51
# File 'lib/bills-payment/bills_payment_object.rb', line 49

def class_name
  self.class.name.split('::').last
end

#parse_response(response) ⇒ Object



18
19
20
21
22
# File 'lib/bills-payment/bills_payment_object.rb', line 18

def parse_response(response)
  @params = response
  assign_attributes(response)
  self
end