Class: TFSO::Authentication
- Inherits:
-
Object
- Object
- TFSO::Authentication
show all
- Includes:
- Helpers
- Defined in:
- lib/tfso/authentication.rb
Constant Summary
collapse
- URL =
'https://api.24sevenoffice.com/authenticate/v001/authenticate.asmx?wsdl'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#ensure_authenticated, #intialize_savon_client, #savon_client, #session_id, #session_id=
Constructor Details
#initialize(application_id) ⇒ Authentication
Returns a new instance of Authentication.
11
12
13
14
|
# File 'lib/tfso/authentication.rb', line 11
def initialize(application_id)
@application_id = application_id
intialize_savon_client
end
|
Instance Attribute Details
#application_id ⇒ Object
Returns the value of attribute application_id.
9
10
11
|
# File 'lib/tfso/authentication.rb', line 9
def application_id
@application_id
end
|
Instance Method Details
#authenticate(username, password, identity_id = nil) ⇒ Object
22
23
24
25
26
|
# File 'lib/tfso/authentication.rb', line 22
def authenticate(username, password, identity_id = nil)
response = savon_client.call(:login, message: { credential: {Username: username, Password: password, IdentityId: identity_id, ApplicationId: application_id}})
raise Errors::Authentication, 'Incorrect credentials' if response.body[:login_response][:login_result].blank?
self.session_id = response.body[:login_response][:login_result]
end
|
#authenticated? ⇒ Boolean
16
17
18
19
20
|
# File 'lib/tfso/authentication.rb', line 16
def authenticated?
response = savon_client.call(:has_session, cookies: @cookies)
raise Errors::Authentication, 'Not authenticated' if !response.body[:has_session_response][:has_session_result]
response.body[:has_session_response][:has_session_result]
end
|
#identities ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/tfso/authentication.rb', line 28
def identities
response = savon_client.call(:get_identities, cookies: @cookies)
list = response.body[:get_identities_response][:get_identities_result][:identity]
if list.is_a?(Hash)
[list]
else
list
end
end
|
#identity_id ⇒ Object
38
39
40
41
|
# File 'lib/tfso/authentication.rb', line 38
def identity_id
response = savon_client.call(:get_identity, cookies: @cookies)
response.body[:get_identity_response][:get_identity_result][:id]
end
|
#identity_id=(identity_id) ⇒ Object
43
44
45
46
|
# File 'lib/tfso/authentication.rb', line 43
def identity_id=(identity_id)
savon_client.call(:set_identity_by_id, message: {identityId: identity_id}, cookies: @cookies)
@identity_id = identity_id
end
|