Class: Acumatica::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/acumatica/client.rb

Constant Summary collapse

API_VERSION =
"6.00.001".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/acumatica/client.rb', line 7

def name
  @name
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/acumatica/client.rb', line 7

def password
  @password
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/acumatica/client.rb', line 7

def token
  @token
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/acumatica/client.rb', line 7

def url
  @url
end

Class Method Details

.configure {|instance| ... } ⇒ Object

Yields:

  • (instance)


9
10
11
12
# File 'lib/acumatica/client.rb', line 9

def self.configure
  yield(instance)
  instance
end

Instance Method Details

#connectionObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/acumatica/client.rb', line 14

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

#loginObject



29
30
31
32
33
34
35
# File 'lib/acumatica/client.rb', line 29

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

#logoutObject



37
38
39
# File 'lib/acumatica/client.rb', line 37

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

#stock_itemsObject



41
42
43
# File 'lib/acumatica/client.rb', line 41

def stock_items
  Acumatica::StockItem
end