Class: YouGotListed::Response
- Inherits:
-
Object
- Object
- YouGotListed::Response
- Defined in:
- lib/you_got_listed/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ygl_response ⇒ Object
Returns the value of attribute ygl_response.
Instance Method Summary collapse
-
#initialize(response, raise_error = true) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method_name, *args) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response, raise_error = true) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/you_got_listed/response.rb', line 6 def initialize(response, raise_error = true) begin if !response.respond_to?(:each_pair) self.ygl_response = nil raise Error.new('empty_response', 'Empty Response') if raise_error else rash = Hashie::Rash.new(response) self.ygl_response = rash.ygl_response if !success? && raise_error if self.ygl_response.respond_to?(:response_code) raise Error.new(self.ygl_response.response_code, self.ygl_response.error) else raise Error.new('empty_response', 'Empty Response') end end end rescue MultiXml::ParseError self.ygl_response = nil raise Error.new('parse_error', 'XML Parse Error') if raise_error end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/you_got_listed/response.rb', line 32 def method_missing(method_name, *args) if self.ygl_response.respond_to?(method_name) self.ygl_response.send(method_name) else super end end |
Instance Attribute Details
#ygl_response ⇒ Object
Returns the value of attribute ygl_response.
4 5 6 |
# File 'lib/you_got_listed/response.rb', line 4 def ygl_response @ygl_response end |
Instance Method Details
#success? ⇒ Boolean
28 29 30 |
# File 'lib/you_got_listed/response.rb', line 28 def success? self.ygl_response && self.ygl_response.respond_to?(:response_code) && self.ygl_response.response_code.to_i < 300 end |