Class: MoloniApi::API

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

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

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::API_CLIENT_ID, Constants::API_CLIENT_SECRET, Constants::API_ENDPOINT, 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

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

Instance Method Summary collapse

Constructor Details

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

Create new API



52
53
54
55
56
57
58
59
60
# File 'lib/moloni_api/api.rb', line 52

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



65
66
67
68
69
# File 'lib/moloni_api/api.rb', line 65

def yield_or_eval(&block)
  return unless block

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