Class: Ovh::Http2sms::Response
- Inherits:
-
Object
- Object
- Ovh::Http2sms::Response
- Defined in:
- lib/ovh/http2sms/response.rb
Overview
Response object for OVH HTTP2SMS API responses
Parses responses in all supported formats: JSON, XML, HTML, and text/plain. Provides a unified interface for accessing response data.
Constant Summary collapse
- SUCCESS_CODES =
Success status codes
[100, 101].freeze
- ERROR_CODES =
Error status codes
{ 201 => :missing_parameter, 202 => :invalid_parameter, 241 => :sender_not_found, 401 => :authentication_error }.freeze
Instance Attribute Summary collapse
-
#content_type ⇒ String
readonly
Content type of the response.
-
#credits_remaining ⇒ Float?
readonly
Remaining SMS credits.
-
#error_message ⇒ String?
readonly
Error message if request failed.
-
#raw_response ⇒ String
readonly
Raw response body.
-
#sms_ids ⇒ Array<String>
readonly
SMS IDs for sent messages.
-
#status ⇒ Integer
readonly
API status code (100, 101 = success; 201, 202, 401 = error).
Class Method Summary collapse
-
.parse(body, content_type: "text/plain") ⇒ Response
Parse a raw API response.
Instance Method Summary collapse
-
#error_type ⇒ Symbol?
Get the error type based on status code.
-
#failure? ⇒ Boolean
Check if the request failed.
-
#initialize(status:, credits_remaining: nil, sms_ids: [], error_message: nil, raw_response: nil, content_type: nil) ⇒ Response
constructor
rubocop:disable Metrics/ParameterLists.
-
#success? ⇒ Boolean
Check if the request was successful.
Constructor Details
#initialize(status:, credits_remaining: nil, sms_ids: [], error_message: nil, raw_response: nil, content_type: nil) ⇒ Response
rubocop:disable Metrics/ParameterLists
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ovh/http2sms/response.rb', line 53 def initialize(status:, credits_remaining: nil, sms_ids: [], error_message: nil, raw_response: nil, content_type: nil) # rubocop:enable Metrics/ParameterLists @status = status @credits_remaining = credits_remaining @sms_ids = Array(sms_ids).map(&:to_s) = @raw_response = raw_response @content_type = content_type end |
Instance Attribute Details
#content_type ⇒ String (readonly)
Returns Content type of the response.
39 40 41 |
# File 'lib/ovh/http2sms/response.rb', line 39 def content_type @content_type end |
#credits_remaining ⇒ Float? (readonly)
Returns Remaining SMS credits.
27 28 29 |
# File 'lib/ovh/http2sms/response.rb', line 27 def credits_remaining @credits_remaining end |
#error_message ⇒ String? (readonly)
Returns Error message if request failed.
33 34 35 |
# File 'lib/ovh/http2sms/response.rb', line 33 def end |
#raw_response ⇒ String (readonly)
Returns Raw response body.
36 37 38 |
# File 'lib/ovh/http2sms/response.rb', line 36 def raw_response @raw_response end |
#sms_ids ⇒ Array<String> (readonly)
Returns SMS IDs for sent messages.
30 31 32 |
# File 'lib/ovh/http2sms/response.rb', line 30 def sms_ids @sms_ids end |
#status ⇒ Integer (readonly)
Returns API status code (100, 101 = success; 201, 202, 401 = error).
24 25 26 |
# File 'lib/ovh/http2sms/response.rb', line 24 def status @status end |
Class Method Details
.parse(body, content_type: "text/plain") ⇒ Response
Parse a raw API response
93 94 95 96 |
# File 'lib/ovh/http2sms/response.rb', line 93 def self.parse(body, content_type: "text/plain") parser = ResponseParser.new(body, content_type) parser.parse end |
Instance Method Details
#error_type ⇒ Symbol?
Get the error type based on status code
81 82 83 |
# File 'lib/ovh/http2sms/response.rb', line 81 def error_type ERROR_CODES[status] end |
#failure? ⇒ Boolean
Check if the request failed
74 75 76 |
# File 'lib/ovh/http2sms/response.rb', line 74 def failure? !success? end |
#success? ⇒ Boolean
Check if the request was successful
67 68 69 |
# File 'lib/ovh/http2sms/response.rb', line 67 def success? SUCCESS_CODES.include?(status) end |