Class: SmartyStreets::StatusCodeSender
- Inherits:
-
Object
- Object
- SmartyStreets::StatusCodeSender
- Defined in:
- lib/smartystreets_ruby_sdk/status_code_sender.rb
Instance Method Summary collapse
- #assign_exception(response) ⇒ Object
-
#initialize(inner) ⇒ StatusCodeSender
constructor
A new instance of StatusCodeSender.
- #parse_rate_limit_response(response) ⇒ Object
- #send(request) ⇒ Object
Constructor Details
#initialize(inner) ⇒ StatusCodeSender
Returns a new instance of StatusCodeSender.
6 7 8 |
# File 'lib/smartystreets_ruby_sdk/status_code_sender.rb', line 6 def initialize(inner) @inner = inner end |
Instance Method Details
#assign_exception(response) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/smartystreets_ruby_sdk/status_code_sender.rb', line 36 def assign_exception(response) response.error = case response.status_code when '304' NotModifiedInfo.new(NOT_MODIFIED) when '401' BadCredentialsError.new(BAD_CREDENTIALS) when '402' PaymentRequiredError.new(PAYMENT_REQUIRED) when '413' RequestEntityTooLargeError.new(REQUEST_ENTITY_TOO_LARGE) when '400' BadRequestError.new(BAD_REQUEST) when '422' UnprocessableEntityError.new(UNPROCESSABLE_ENTITY) when '429' TooManyRequestsError.new(TOO_MANY_REQUESTS) when '500' InternalServerError.new(INTERNAL_SERVER_ERROR) when '503' ServiceUnavailableError.new(SERVICE_UNAVAILABLE) else nil end end |
#parse_rate_limit_response(response) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/smartystreets_ruby_sdk/status_code_sender.rb', line 21 def parse_rate_limit_response(response) = "" if !response.payload.nil? response_json = JSON.parse(response.payload) response_json["errors"].each do |error| += (" " + error["message"]) end .strip! end if == "" = TOO_MANY_REQUESTS end TooManyRequestsError.new() end |
#send(request) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/smartystreets_ruby_sdk/status_code_sender.rb', line 10 def send(request) response = @inner.send(request) if response.status_code == '429' response.error = parse_rate_limit_response(response) end assign_exception(response) if response.error == nil response end |