Sha256: bac457aa1ff0faa51b0cc89e913b87fdc5abc514d01cb9003fdfcc9f83c9becf

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

require 'lipseys/api'
require 'lipseys/items'
require 'lipseys/order'
require 'lipseys/shipping'

module Lipseys
  class Client < Base

    include Lipseys::API

    attr_accessor :access_token

    def initialize(options = {})
      requires!(options, :username, :password)
      @options = options

      authenticate!
    end

    def items
      @items ||= Lipseys::Items.new(self)
    end

    def order
      @order ||= Lipseys::Order.new(self)
    end

    def shipping
      @shipping ||= Lipseys::Shipping.new(self)
    end

    private

    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

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lipseys-6.2.1 lib/lipseys/client.rb
lipseys-6.2.0 lib/lipseys/client.rb
lipseys-6.1.1 lib/lipseys/client.rb
lipseys-6.1.0 lib/lipseys/client.rb