Class: Economic::Session

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/economic/session.rb

Overview

The Economic::Session contains details and behaviors for a current connection to the API endpoint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|endpoint| ... } ⇒ Session

Returns a new instance of Session.

Yields:



15
16
17
# File 'lib/economic/session.rb', line 15

def initialize
  yield endpoint if block_given?
end

Instance Attribute Details

#authentication_cookiesObject (readonly)

Returns the value of attribute authentication_cookies.



13
14
15
# File 'lib/economic/session.rb', line 13

def authentication_cookies
  @authentication_cookies
end

Instance Method Details

#accountsObject



77
78
79
# File 'lib/economic/session.rb', line 77

def accounts
  @accounts ||= AccountProxy.new(self)
end

#cash_book_entriesObject



73
74
75
# File 'lib/economic/session.rb', line 73

def cash_book_entries
  @cash_book_entries ||= CashBookEntryProxy.new(self)
end

#cash_booksObject



69
70
71
# File 'lib/economic/session.rb', line 69

def cash_books
  @cash_books ||= CashBookProxy.new(self)
end

#companyObject



98
99
100
# File 'lib/economic/session.rb', line 98

def company
  @company ||= CompanyProxy.new(self)
end

#connect_with_token(private_app_id, access_id) ⇒ Object

Connect/authenticate with an API token and app id

Reference: techtalk.e-conomic.com/why-were-implementing-a-new-api-connection-model/

Attributes

  • private_app_id - The App ID created in your developer agreement

  • access_id - The Access ID or token for your App ID



28
29
30
31
32
33
34
35
36
# File 'lib/economic/session.rb', line 28

def connect_with_token(private_app_id, access_id)
  endpoint.call(
    :connect_with_token,
    :token => access_id,
    :appToken => private_app_id
  ) do |response|
    store_authentication_cookies(response)
  end
end

#contactsObject

Provides access to the DebtorContacts



39
40
41
# File 'lib/economic/session.rb', line 39

def contacts
  @contacts ||= DebtorContactProxy.new(self)
end

#creditor_entriesObject



85
86
87
# File 'lib/economic/session.rb', line 85

def creditor_entries
  @creditor_entries ||= CreditorEntryProxy.new(self)
end

#creditorsObject

Provides access to creditors



65
66
67
# File 'lib/economic/session.rb', line 65

def creditors
  @creditors ||= CreditorProxy.new(self)
end

#current_invoicesObject

Provides access to the current invoices - ie invoices that haven’t yet been booked



45
46
47
# File 'lib/economic/session.rb', line 45

def current_invoices
  @current_invoices ||= CurrentInvoiceProxy.new(self)
end

#debtor_entriesObject



81
82
83
# File 'lib/economic/session.rb', line 81

def debtor_entries
  @debtor_entries ||= DebtorEntryProxy.new(self)
end

#debtorsObject

Provides access to the debtors



60
61
62
# File 'lib/economic/session.rb', line 60

def debtors
  @debtors ||= DebtorProxy.new(self)
end

#endpointObject

Returns the SOAP endpoint to connect to



113
114
115
# File 'lib/economic/session.rb', line 113

def endpoint
  @endpoint ||= Economic::Endpoint.new
end

#entriesObject



89
90
91
# File 'lib/economic/session.rb', line 89

def entries
  @entries ||= EntryProxy.new(self)
end

#invoicesObject

Provides access to the invoices



50
51
52
# File 'lib/economic/session.rb', line 50

def invoices
  @invoices ||= InvoiceProxy.new(self)
end

#ordersObject

Provides access to the orders



55
56
57
# File 'lib/economic/session.rb', line 55

def orders
  @orders ||= OrderProxy.new(self)
end

#productsObject

Provides access to products



94
95
96
# File 'lib/economic/session.rb', line 94

def products
  @products ||= ProductProxy.new(self)
end

#request(soap_action, data = nil) ⇒ Object

Requests an action from the API endpoint



103
104
105
# File 'lib/economic/session.rb', line 103

def request(soap_action, data = nil)
  endpoint.call(soap_action, data, authentication_cookies)
end

#sessionObject

Returns self - used by proxies to access the session of their owner



108
109
110
# File 'lib/economic/session.rb', line 108

def session
  self
end