Class: ClearConnect::Client
- Inherits:
-
Object
- Object
- ClearConnect::Client
- Defined in:
- lib/clearconnect/client.rb
Overview
This class is the interface to the ClearConnect API.
Authentication can be managed via configuration (see the documentation for ClearConnect::Configuration) or by passing the username, password, and sitename for the Contingent Staffing user directly to the client on initialization.
example:
client = ClearConnect::Client.new('username', 'password', 'sitename')
client.get(action: 'getOrders') # => array of orders
Instance Method Summary collapse
-
#get(query) ⇒ Object
alias for ClearConnect::RestClient#get_request.
-
#get_session_key ⇒ Object
retrieves and sets session key for making requests, may raise exception if there is an error.
-
#initialize(username = ClearConnect.configuration.username, password = ClearConnect.configuration.password, site_name = ClearConnect.configuration.site_name, session = (ClearConnect.configuration and ClearConnect.configuration.session)) ⇒ Client
constructor
A new instance of Client.
-
#post(query) ⇒ Object
alias for ClearConnect::SoapClient#post_request.
- #rest_client ⇒ Object
- #soap_client ⇒ Object
Constructor Details
#initialize(username = ClearConnect.configuration.username, password = ClearConnect.configuration.password, site_name = ClearConnect.configuration.site_name, session = (ClearConnect.configuration and ClearConnect.configuration.session)) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/clearconnect/client.rb', line 13 def initialize(username = ClearConnect.configuration.username, password = ClearConnect.configuration.password, site_name = ClearConnect.configuration.site_name, session = (ClearConnect.configuration and ClearConnect.configuration.session)) # to ensure the endpoints are available if !ClearConnect.configuration ClearConnect.configure do |c| c.username = username c.password = password c.site_name = site_name c.session = session end end @username = username @password = password @session = session end |
Instance Method Details
#get(query) ⇒ Object
alias for ClearConnect::RestClient#get_request
42 43 44 |
# File 'lib/clearconnect/client.rb', line 42 def get(query) rest_client.get_request(query) end |
#get_session_key ⇒ Object
retrieves and sets session key for making requests, may raise exception if there is an error.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/clearconnect/client.rb', line 53 def get_session_key response = rest_client.get_no_session( action: 'getSessionKey').parsed_response[0] if response['success'] == "1" @sessionKey = response['sessionKey'] rest_client.set_session_key @sessionKey # TODO: Incorporate sessions into Savon client. #@soap_client.set_session_key @sessionKey if @soap_client elsif response['errorCode'] raise "Session key retrieval failed with code: #{response['errorCode']}." else raise "Session key retrieval failed for an unknown reason." end end |
#post(query) ⇒ Object
alias for ClearConnect::SoapClient#post_request
47 48 49 |
# File 'lib/clearconnect/client.rb', line 47 def post(query) soap_client.post_request(query) end |
#rest_client ⇒ Object
36 37 38 39 |
# File 'lib/clearconnect/client.rb', line 36 def rest_client @rest_client ||= RestClient.new(@username, @password) @rest_client end |
#soap_client ⇒ Object
31 32 33 34 |
# File 'lib/clearconnect/client.rb', line 31 def soap_client @soap_client ||= SoapClient.new(@username, @password) @soap_client end |