Class: BaseApiClient
- Inherits:
-
Object
- Object
- BaseApiClient
- Defined in:
- lib/dynalist/base_api_client.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ApiError, Error, InvalidError, InvalidTokenError, LockFailError, TooManyRequestsError
Constant Summary collapse
- ApiErrors =
{ Invalid: InvalidError, InvalidToken: InvalidTokenError, TooManyRequests: TooManyRequestsError, LockFail: LockFailError }.freeze
Instance Method Summary collapse
- #check_response!(response) ⇒ Object
-
#initialize(token = nil) ⇒ BaseApiClient
constructor
A new instance of BaseApiClient.
Constructor Details
#initialize(token = nil) ⇒ BaseApiClient
Returns a new instance of BaseApiClient.
5 6 7 8 9 |
# File 'lib/dynalist/base_api_client.rb', line 5 def initialize(token = nil) @conn = Faraday.new(:url => 'https://dynalist.io/') @base = 'api/v1/' @token = token || ENV['DYNALIST_TOKEN'] end |
Instance Method Details
#check_response!(response) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/dynalist/base_api_client.rb', line 38 def check_response!(response) res = JSON.parse(response.body, symbolize_names: true) return true if res[:_code] == 'Ok' error = ApiErrors.fetch(res[:_code].to_sym, ApiError) raise error, res end |