Class: DineroMail::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr = {}) ⇒ Response

Returns a new instance of Response.



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

def initialize(attr = {})
  @attributes = attr
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/dinero_mail/response.rb', line 9

def method_missing(name, *args, &block)
  nested_value  = nested_hash_value(@attributes, name)
  if args.empty? && block.nil? && !nested_value.nil?
    nested_value
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/dinero_mail/response.rb', line 30

def completed?
  self.status == "COMPLETED" or self.status == "OK"
end

#denied?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dinero_mail/response.rb', line 26

def denied?
  self.status == "DENIED"
end

#error?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dinero_mail/response.rb', line 22

def error?
  self.status == "ERROR"
end

#nested_hash_value(obj, key) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/dinero_mail/response.rb', line 42

def nested_hash_value(obj,key)
  if obj.respond_to?(:key?) && obj.key?(key)
    obj[key]
  elsif obj.respond_to?(:each)
    r = nil
    obj.find{ |*a| r=nested_hash_value(a.last,key)  }
    r
  end
end

#pending?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dinero_mail/response.rb', line 34

def pending?
  self.status == "PENDING"
end

#procesing?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dinero_mail/response.rb', line 38

def procesing?
  self.status == "PROCESING" 
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  self.status == "OK" or self.status == "COMPLETED"
end