Method: BitlyQuickly#response_to_json
- Defined in:
- lib/bitly_quickly.rb
#response_to_json(response) ⇒ Hash (private)
Check response code and raise an appropriate error. Otherwise return parsed JSON body.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/bitly_quickly.rb', line 143 def response_to_json(response) json_response = parse_json(response.body) case json_response[:status_code] when 200 return json_response when 403 fail Error::RateLimitExceeded, json_response[:status_txt] when 404 fail Error::NotFound, json_response[:status_txt] when 500 fail Error::InvalidRequestOrResponse, json_response[:status_txt] when 503 fail Error::TemporarilyUnavailable, json_response[:status_txt] else fail Error::UnknownError, json_response[:status_txt] end end |