Class: Twinfield::Api::OAuthSession
- Inherits:
-
Object
- Object
- Twinfield::Api::OAuthSession
- Defined in:
- lib/twinfield/api/o_auth_session.rb
Constant Summary collapse
- HEADER_TEMPLATE =
{ "Header" => {}, :attributes! => { "Header" => {xmlns: "http://www.twinfield.com/"} } }
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#cluster ⇒ Object
Returns the value of attribute cluster.
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Returns true or false if current session has a session_id and cluster from twinfield.
- #header ⇒ Object
-
#initialize ⇒ OAuthSession
constructor
sets up a new savon client which will be used for current Session.
-
#logon(relog = false) ⇒ Object
retrieve a session_id and cluster from twinfield relog is by default set to false so when logon is called on your current session, you wont lose your session_id.
-
#relog ⇒ Object
call logon method with relog set to true this wil destroy the current session and cluster.
-
#status ⇒ Object
after a logon try you can ask the current status.
Constructor Details
#initialize ⇒ OAuthSession
sets up a new savon client which will be used for current Session
14 15 16 17 |
# File 'lib/twinfield/api/o_auth_session.rb', line 14 def initialize @cluster = Twinfield.configuration.cluster @access_token = Twinfield.configuration.access_token end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
11 12 13 |
# File 'lib/twinfield/api/o_auth_session.rb', line 11 def access_token @access_token end |
#cluster ⇒ Object
Returns the value of attribute cluster.
11 12 13 |
# File 'lib/twinfield/api/o_auth_session.rb', line 11 def cluster @cluster end |
Instance Method Details
#connected? ⇒ Boolean
Returns true or false if current session has a session_id and cluster from twinfield
43 44 45 |
# File 'lib/twinfield/api/o_auth_session.rb', line 43 def connected? !!@access_token && !!@cluster end |
#header ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/twinfield/api/o_auth_session.rb', line 47 def header soap_header = HEADER_TEMPLATE header_contents = {} header_contents["AccessToken"] = access_token if access_token header_contents["CompanyCode"] = Twinfield.configuration.company if Twinfield.configuration.company soap_header.merge({"Header" => header_contents}) end |
#logon(relog = false) ⇒ Object
retrieve a session_id and cluster from twinfield relog is by default set to false so when logon is called on your current session, you wont lose your session_id
22 23 24 |
# File 'lib/twinfield/api/o_auth_session.rb', line 22 def logon(relog = false) # no need to logon with OAuth end |
#relog ⇒ Object
call logon method with relog set to true this wil destroy the current session and cluster
28 29 30 |
# File 'lib/twinfield/api/o_auth_session.rb', line 28 def relog logon(true) end |
#status ⇒ Object
after a logon try you can ask the current status
33 34 35 36 37 38 39 |
# File 'lib/twinfield/api/o_auth_session.rb', line 33 def status if connected? "Ok" else "No access token" end end |