Sha256: 2c10792e65efe288e166198a7cf067cd359c4901ffa18cb8d59d563f360127c6

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 Bytes

Contents

module Acumatica
  class Client
    include Singleton

    API_VERSION = "6.00.001".freeze

    attr_accessor :url, :name, :password, :token

    def self.configure
      yield(instance)
      instance
    end

    def connection
      @connection ||= Faraday.new do |conn|
        conn.request :json

        if token.present?
          conn.request :oauth2, token
        else
          conn.use :cookie_jar
        end

        conn.response :json
        conn.adapter Faraday.default_adapter
      end
    end

    def login
      response = connection.post do |req|
        req.url URI.join(@url, "/entity/auth/login")
        req.body = { name: @name, password: @password }
      end
      response.success?
    end

    def logout
      connection.post(URI.join(@url, "/entity/auth/logout")).success?
    end

    def stock_items
      Acumatica::StockItem
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acumatica-0.1.3 lib/acumatica/client.rb
acumatica-0.1.2 lib/acumatica/client.rb