Sha256: abfa6c3057427d3d3524407fb17b70cf4cd31adae50046be392fddc8e708da25

Contents?: true

Size: 873 Bytes

Versions: 2

Compression:

Stored size: 873 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
          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.2.1 lib/acumatica/client.rb
acumatica-0.2.0 lib/acumatica/client.rb