class Lipseys::Client

Attributes

access_token[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/lipseys/client.rb, line 13
def initialize(options = {})
  requires!(options, :username, :password)
  @options = options

  authenticate!
end

Public Instance Methods

items() click to toggle source
# File lib/lipseys/client.rb, line 20
def items
  @items ||= Lipseys::Items.new(self)
end
order() click to toggle source
# File lib/lipseys/client.rb, line 24
def order
  @order ||= Lipseys::Order.new(self)
end
shipping() click to toggle source
# File lib/lipseys/client.rb, line 28
def shipping
  @shipping ||= Lipseys::Shipping.new(self)
end

Private Instance Methods

authenticate!() click to toggle source
# File lib/lipseys/client.rb, line 34
def authenticate!
  response = post_request(
    'authentication/login',
    { email: @options[:username], password: @options[:password] },
    content_type_header('application/json')
  )

  if response[:token].present?
    self.access_token = response[:token]
  else
    raise Lipseys::Error::NotAuthorized.new(response.body)
  end
end