class Passety::Wrapper

Public Class Methods

new(token, options = {}) click to toggle source
# File lib/passety/wrapper.rb, line 3
def initialize(token, options = {})
  @token = token
  @raise_errors = options.fetch(:raise_errors, true)
end

Public Instance Methods

collections() click to toggle source
# File lib/passety/wrapper.rb, line 8
def collections
  @collections ||= Collection.new(self)
end
info() click to toggle source
# File lib/passety/wrapper.rb, line 24
def info
  perform_request { |c| c.get('/') }
end
perform_request() { |connection| ... } click to toggle source
# File lib/passety/wrapper.rb, line 28
def perform_request
  response = Response.new(yield(connection))

  if @raise_errors
    raise NotAuthorizedError.new if response.status == 401
    raise ReadOnlyError.new      if response.status == 403
    raise NotFoundError.new      if response.status == 404
  end

  response
end
things() click to toggle source
# File lib/passety/wrapper.rb, line 12
def things
  @things ||= Thing.new(self)
end
uploads() click to toggle source
# File lib/passety/wrapper.rb, line 16
def uploads
  @uploads ||= Upload.new(self)
end

Private Instance Methods

connection() click to toggle source
# File lib/passety/wrapper.rb, line 41
def connection
  @connection ||= Faraday.new(url: API_URL, headers: { 'Accept' => 'application/json; version=1', 'Authorization' => "Bearer #{@token}" }) do |f|
    f.request :multipart
    f.adapter Faraday.default_adapter
  end
end