Class: Sendgrid::Web::Response
- Inherits:
-
Object
- Object
- Sendgrid::Web::Response
- Defined in:
- lib/sendgrid/web/response.rb
Instance Attribute Summary collapse
-
#parsed_body ⇒ Object
readonly
Returns the value of attribute parsed_body.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#error_messages ⇒ Array<String>
Fetches an array of error messages from the response.
-
#errors? ⇒ bool
Checks if the Sengrid response contained errors.
-
#initialize(status_code, body) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status_code, body) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 |
# File 'lib/sendgrid/web/response.rb', line 5 def initialize(status_code, body) @status_code = status_code.to_i @raw_body = body.to_s @parsed_body = ::Oj.safe_load(raw_body) end |
Instance Attribute Details
#parsed_body ⇒ Object (readonly)
Returns the value of attribute parsed_body.
3 4 5 |
# File 'lib/sendgrid/web/response.rb', line 3 def parsed_body @parsed_body end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
3 4 5 |
# File 'lib/sendgrid/web/response.rb', line 3 def raw_body @raw_body end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
3 4 5 |
# File 'lib/sendgrid/web/response.rb', line 3 def status_code @status_code end |
Instance Method Details
#error_messages ⇒ Array<String>
Fetches an array of error messages from the response.
23 24 25 |
# File 'lib/sendgrid/web/response.rb', line 23 def errors? ? parsed_body['errors'] : [] end |
#errors? ⇒ bool
Checks if the Sengrid response contained errors.
14 15 16 17 18 |
# File 'lib/sendgrid/web/response.rb', line 14 def errors? !parsed_body.nil? && parsed_body.is_a?(Hash) && parsed_body.has_key?('errors') end |