Class: Smsc::Response
- Inherits:
-
Object
- Object
- Smsc::Response
- Defined in:
- lib/smsc/response.rb
Overview
Response parse
Class Method Summary collapse
-
.parse(body, parse_configuration) ⇒ Object
Parse and wrap response in models, raise errors.
-
.raise_client_errors(json, error_map) ⇒ Object
Raise errors if response contain error code.
Class Method Details
.parse(body, parse_configuration) ⇒ Object
Parse and wrap response in models, raise errors
14 15 16 17 18 19 |
# File 'lib/smsc/response.rb', line 14 def parse(body, parse_configuration) json = JSON.parse(body, symbolize_names: true) raise_client_errors(json, parse_configuration[:errors] || {}) parse_configuration[:model].new(json) end |
.raise_client_errors(json, error_map) ⇒ Object
Raise errors if response contain error code
24 25 26 27 28 29 30 31 32 |
# File 'lib/smsc/response.rb', line 24 def raise_client_errors(json, error_map) error_code = json[:error_code] = json[:error] return if error_code.nil? error_class = error_map[error_code.to_i] raise error_class, unless error_class.nil? raise Smsc::ClientError, end |