Module: Postio

Defined in:
lib/postio.rb,
lib/postio/client.rb,
lib/postio/errors.rb,
lib/postio/models.rb,
lib/postio/version.rb

Overview

Top-level Postio module. Use Postio::Client to construct the API client.

client = Postio::Client.new(api_key: "pk_live_...")
client.address.search("downing street")

Defined Under Namespace

Modules: Models Classes: AddressResource, Client, ConnectionError, EmailResource, Error, ForbiddenError, InvalidKeyError, NotFoundError, OutOfCreditError, PhoneResource, RateLimitError, ServerError, TimeoutError, ValidationError

Constant Summary collapse

STATUS_ERRORS =

Map an HTTP status to the typed error class.

{
  400 => ValidationError,
  401 => InvalidKeyError,
  402 => OutOfCreditError,
  403 => ForbiddenError,
  404 => NotFoundError,
  422 => ValidationError,
  429 => RateLimitError
}.freeze
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.error_class_for(status) ⇒ Object



53
54
55
56
57
58
# File 'lib/postio/errors.rb', line 53

def self.error_class_for(status)
  return STATUS_ERRORS[status] if STATUS_ERRORS.key?(status)
  return ServerError if status >= 500

  Error
end