Class: Emarsys::Response
- Inherits:
-
Object
- Object
- Emarsys::Response
- Defined in:
- lib/emarsys/response.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#data ⇒ Object
Returns the value of attribute data.
-
#status ⇒ Object
Returns the value of attribute status.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response) ⇒ 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 27 28 |
# File 'lib/emarsys/response.rb', line 6 def initialize(response) if response.headers[:content_type] == 'text/csv' self.code = 0 self.data = response.body else json = JSON.parse(response) self.code = json['replyCode'] self.text = json['replyText'] self.data = json['data'] end self.status = response.code if response.respond_to?(:code) if code != 0 if status == 401 raise Emarsys::Unauthorized.new(code, text, status) elsif status == 429 raise Emarsys::TooManyRequests.new(code, text, status) else raise Emarsys::BadRequest.new(code, text, status) end end end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/emarsys/response.rb', line 4 def code @code end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/emarsys/response.rb', line 4 def data @data end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/emarsys/response.rb', line 4 def status @status end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/emarsys/response.rb', line 4 def text @text end |