Sha256: 5762c7af2ce8f2c796efd2461ba34c7106df2b4a80de3acd3b68b6a1718308dc

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

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

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

    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

1 entries across 1 versions & 1 rubygems

Version Path
lipseys-6.0.2 lib/lipseys/client.rb