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(agreement_number = nil, user_name = nil, password = nil, app_identifier = nil) {|endpoint| ... } ⇒ Session

Returns a new instance of Session.

Yields:



14
15
16
17
18
19
20
# File 'lib/economic/session.rb', line 14

def initialize(agreement_number = nil, user_name = nil, password = nil, app_identifier = nil)
  self.agreement_number = agreement_number
  self.user_name = user_name
  self.password = password
  self.app_identifier = app_identifier
  yield endpoint if block_given?
end

Instance Attribute Details

#agreement_numberObject

Returns the value of attribute agreement_number.



11
12
13
# File 'lib/economic/session.rb', line 11

def agreement_number
  @agreement_number
end

#app_identifierObject

Returns the value of attribute app_identifier.



11
12
13
# File 'lib/economic/session.rb', line 11

def app_identifier
  @app_identifier
end

#authentication_cookiesObject (readonly)

Returns the value of attribute authentication_cookies.



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

def authentication_cookies
  @authentication_cookies
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/economic/session.rb', line 11

def password
  @password
end

#user_nameObject

Returns the value of attribute user_name.



11
12
13
# File 'lib/economic/session.rb', line 11

def user_name
  @user_name
end

Instance Method Details

#accountsObject



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

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

#cash_book_entriesObject



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

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

#cash_booksObject



100
101
102
# File 'lib/economic/session.rb', line 100

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

#companyObject



129
130
131
# File 'lib/economic/session.rb', line 129

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

#connectObject

Authenticates with E-conomic using credentials Assumes ::new was called with credentials as arguments.



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

def connect
  connect_with_credentials(agreement_number, user_name, password, app_identifier)
end

#connect_with_credentials(agreement_number, user_name, password, app_identifier = nil) ⇒ Object

Connect/authenticate with credentials

Attributes



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/economic/session.rb', line 50

def connect_with_credentials(agreement_number, user_name, password, app_identifier = nil)
  self.app_identifier = app_identifier if app_identifier

  endpoint.call(
    :connect,
    :agreementNumber => agreement_number,
    :userName => user_name,
    :password => password
  ) do |response|
    store_authentication_cookies(response)
  end
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



31
32
33
34
35
36
37
38
39
# File 'lib/economic/session.rb', line 31

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



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

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

#creditor_entriesObject



116
117
118
# File 'lib/economic/session.rb', line 116

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

#creditorsObject

Provides access to creditors



96
97
98
# File 'lib/economic/session.rb', line 96

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

#current_invoicesObject

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



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

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

#debtor_entriesObject



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

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

#debtorsObject

Provides access to the debtors



91
92
93
# File 'lib/economic/session.rb', line 91

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

#endpointObject

Returns the SOAP endpoint to connect to



144
145
146
# File 'lib/economic/session.rb', line 144

def endpoint
  @endpoint ||= Economic::Endpoint.new(app_identifier)
end

#entriesObject



120
121
122
# File 'lib/economic/session.rb', line 120

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

#invoicesObject

Provides access to the invoices



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

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

#ordersObject

Provides access to the orders



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

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

#productsObject

Provides access to products



125
126
127
# File 'lib/economic/session.rb', line 125

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

#request(soap_action, data = nil) ⇒ Object

Requests an action from the API endpoint



134
135
136
# File 'lib/economic/session.rb', line 134

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



139
140
141
# File 'lib/economic/session.rb', line 139

def session
  self
end