Class: FantasticstayApi::API

Inherits:
Object
  • Object
show all
Includes:
Dry::Configurable, ApiExceptions, Constants, HttpStatusCodes
Defined in:
lib/fantasticstay_api/api.rb

Overview

Core class responsible for api interface operations

Direct Known Subclasses

Client

Constant Summary collapse

HTTP_STATUS_MAPPING =
{
  HTTP_BAD_REQUEST_CODE => BadRequestError,
  HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
  HTTP_FORBIDDEN_CODE => ForbiddenError,
  HTTP_NOT_FOUND_CODE => NotFoundError,
  HTTP_UNPROCESSABLE_ENTITY_CODE => UnprocessableEntityError,
  'default' => ApiError
}.freeze
API_ENDPOINT =
'https://api.fsapp.io'
API_TIMEOUT =

API response timeout

5
API_STALE_VALIDITY =

604800 = 7 days - Maximum time to use old data

:forever
API_TOKEN =
'TESTING'

Constants included from HttpStatusCodes

HttpStatusCodes::HTTP_BAD_REQUEST_CODE, HttpStatusCodes::HTTP_FORBIDDEN_CODE, HttpStatusCodes::HTTP_NOT_FOUND_CODE, HttpStatusCodes::HTTP_OK_CODE, HttpStatusCodes::HTTP_UNAUTHORIZED_CODE, HttpStatusCodes::HTTP_UNPROCESSABLE_ENTITY_CODE

Constants included from Constants

Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_INCLUDE_RELATED, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::RATELIMIT_RESET, Constants::SERVER, Constants::USER_AGENT

Constants included from ApiExceptions

FantasticstayApi::ApiExceptions::APIExceptionError, FantasticstayApi::ApiExceptions::ApiError, FantasticstayApi::ApiExceptions::ApiRequestsQuotaReachedError, FantasticstayApi::ApiExceptions::BadRequestError, FantasticstayApi::ApiExceptions::ForbiddenError, FantasticstayApi::ApiExceptions::NotFoundError, FantasticstayApi::ApiExceptions::UnauthorizedError, FantasticstayApi::ApiExceptions::UnprocessableEntityError

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ API

Create new API



60
61
62
63
64
65
66
67
68
# File 'lib/fantasticstay_api/api.rb', line 60

def initialize(options = {}, &block)
  configure do |c|
    options.each_key do |key|
      c.send("#{key}=", options[key])
    end
  end

  yield_or_eval(&block) if block_given?
end

Instance Method Details

#yield_or_eval(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call block with argument



73
74
75
76
77
# File 'lib/fantasticstay_api/api.rb', line 73

def yield_or_eval(&block)
  return unless block

  block.arity.positive? ? yield(self) : instance_eval(&block)
end