Class: Linguin::BaseResponse
- Inherits:
-
Object
- Object
- Linguin::BaseResponse
- Defined in:
- lib/linguin/base_response.rb
Overview
Linguin::BaseResponse
Base class for Linguin::Detection && Linguin::Status
Direct Known Subclasses
BulkProfanityDetection, LanguageDetection, Languages, ProfanityDetection, Status
Constant Summary collapse
- CODE_MAP =
{ 400 => InputError, 401 => AuthenticationError, 404 => NotFoundError, 422 => InputError, 429 => RateLimitError, 500 => InternalError, 503 => InternalError }.freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ BaseResponse
constructor
A new instance of BaseResponse.
- #raise_on_error! ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ BaseResponse
Returns a new instance of BaseResponse.
19 20 21 |
# File 'lib/linguin/base_response.rb', line 19 def initialize yield self end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
17 18 19 |
# File 'lib/linguin/base_response.rb', line 17 def error @error end |
Class Method Details
.from_httparty(response:) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/linguin/base_response.rb', line 24 def from_httparty(response:) if response.code == 200 response = JSON.parse response, symbolize_names: true success(response) else error(response.code, response.body) end end |