clearconnect 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +81 -0
- data/Rakefile +1 -0
- data/clearconnect.gemspec +25 -0
- data/lib/clearconnect.rb +18 -0
- data/lib/clearconnect/client.rb +69 -0
- data/lib/clearconnect/configuration.rb +64 -0
- data/lib/clearconnect/rest_client.rb +49 -0
- data/lib/clearconnect/soap_client.rb +71 -0
- data/lib/clearconnect/version.rb +3 -0
- metadata +104 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
Usage
|
2
|
+
-----
|
3
|
+
|
4
|
+
The ClearConnect gem all starts with `ClearConnect::Client`. Initialize
|
5
|
+
a client and then you can access the ClearConnect API methods via
|
6
|
+
`Client#get` and `Client#post`. Pass all parameters to these methods
|
7
|
+
as hashes, and make sure to include the action parameter to specify the
|
8
|
+
API method to invoke. When a call is completed successfully, a plain
|
9
|
+
Ruby structure (Array/Hash) with the retrieved information (or
|
10
|
+
confirmation information) is returned.
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
client = ClearConnect::Client.new('myname', 'mypassword', 'sitename')
|
14
|
+
client.get(action: 'getTemps', tempIdIn: 1000)
|
15
|
+
# => [{"tempId"=>"1000", "homeRegion"=>"1", ...}]
|
16
|
+
```
|
17
|
+
|
18
|
+
Add/Update requests are no more difficult to execute than the get
|
19
|
+
request demonstrated above. The Ruby structure passed to the method is
|
20
|
+
converted directly to XML which is sent to the API endpoint. Take the
|
21
|
+
`insertWorkHistory` API method as an example. Since it requires a root
|
22
|
+
node of `workHistoryRecords` with multiple `workHistoryRecord`
|
23
|
+
sub-nodes, we would construct a call to this method as follows:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
data = {
|
27
|
+
workHistoryRecords: [
|
28
|
+
{ workHistoryRecord: {
|
29
|
+
tempId: 1000,
|
30
|
+
facility: 'Previous Employer 1',
|
31
|
+
startDate: '2013-04-09',
|
32
|
+
endDate: '2014-01-01'
|
33
|
+
}}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
client.post(action: 'insertWorkHistory', workHistoryRecords: data)
|
37
|
+
```
|
38
|
+
|
39
|
+
Configure
|
40
|
+
---------
|
41
|
+
|
42
|
+
The username, password, and sitename to use for authentication can be
|
43
|
+
configured in a few ways. When used in a larger project with
|
44
|
+
centralized configuration (e.g. a Rails application), the class method
|
45
|
+
`ClearConnect#configure` allows you to set the information that will be
|
46
|
+
used to authenticate the ClearConnect clients created. As an example,
|
47
|
+
you may create the file `config/initializers/clearconnect.rb` with the
|
48
|
+
content:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
ClearConnect.configure do |config|
|
52
|
+
config.username = ENV['cc_username']
|
53
|
+
config.password = ENV['cc_password']
|
54
|
+
config.site_name = ENV['cc_sitename']
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
In smaller applications or scripts, it may be easier to pass the info
|
59
|
+
via the constructor of the `ClearConnect::Client`, like so:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
client = ClearConnect::Client.new('username', 'password', 'sitename')
|
63
|
+
```
|
64
|
+
|
65
|
+
Notes
|
66
|
+
-----
|
67
|
+
|
68
|
+
The `#get` method of `ClearConnect::Client` uses the http client library
|
69
|
+
[HTTParty](https://github.com/jnunemaker/httparty). The `#post` method
|
70
|
+
uses the SOAP client [Savon](https://github.com/savonrb/savon). The
|
71
|
+
Savon client used internally is initialized when the first call is made
|
72
|
+
that requires it because the initialization can take some time, but
|
73
|
+
requests use the cached Savon client thereafter.
|
74
|
+
|
75
|
+
Issues
|
76
|
+
------
|
77
|
+
|
78
|
+
Since the endpoint for the ClearConnect API uses SSL (i.e. is accessed
|
79
|
+
via an https url), you may encounter the error `OpenSSL certificate
|
80
|
+
verify failed`. The solution for this is relatively simple, and can be
|
81
|
+
found [here](http://railsapps.github.io/openssl-certificate-verify-failed.html).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "clearconnect/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'clearconnect'
|
7
|
+
s.version = ClearConnect::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Christopher Hunt"]
|
10
|
+
s.email = 'chrahunt@gmail.com'
|
11
|
+
s.homepage = ''
|
12
|
+
s.summary = 'ClearConnect API Interface for Ruby'
|
13
|
+
s.description = ''
|
14
|
+
|
15
|
+
s.rubyforge_project = "clearconnect"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'httparty', '~> 0.10'
|
23
|
+
s.add_runtime_dependency 'savon', '~> 2.1.0'
|
24
|
+
s.add_runtime_dependency 'xml-simple', '~> 1.1.2'
|
25
|
+
end
|
data/lib/clearconnect.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'savon'
|
3
|
+
require 'xmlsimple'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# the clearconnect gem handles authentication and message passing between a
|
7
|
+
# Ruby/Rails application and the ClearConnect API offered by API Healthcare
|
8
|
+
# as a supplement to their Contingent Staffing software.
|
9
|
+
module ClearConnect
|
10
|
+
class NoFunctionError < StandardError; end
|
11
|
+
class AuthenticateError < StandardError; end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'clearconnect/client'
|
15
|
+
require 'clearconnect/configuration'
|
16
|
+
require 'clearconnect/rest_client'
|
17
|
+
require 'clearconnect/soap_client'
|
18
|
+
require 'clearconnect/version'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module ClearConnect
|
2
|
+
##
|
3
|
+
# This class is the interface to the ClearConnect API.
|
4
|
+
#
|
5
|
+
# Authentication can be managed via configuration (see the documentation for ClearConnect::Configuration)
|
6
|
+
# or by passing the username, password, and sitename for the Contingent Staffing user directly to the client
|
7
|
+
# on initialization.
|
8
|
+
#
|
9
|
+
# example:
|
10
|
+
# client = ClearConnect::Client.new('username', 'password', 'sitename')
|
11
|
+
# client.get(action: 'getOrders') # => array of orders
|
12
|
+
class Client
|
13
|
+
def initialize(username = ClearConnect.configuration.username,
|
14
|
+
password = ClearConnect.configuration.password,
|
15
|
+
site_name = ClearConnect.configuration.site_name,
|
16
|
+
session = (ClearConnect.configuration and ClearConnect.configuration.session))
|
17
|
+
# to ensure the endpoints are available
|
18
|
+
if !ClearConnect.configuration
|
19
|
+
ClearConnect.configure do |c|
|
20
|
+
c.username = username
|
21
|
+
c.password = password
|
22
|
+
c.site_name = site_name
|
23
|
+
c.session = session
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@username = username
|
27
|
+
@password = password
|
28
|
+
@session = session
|
29
|
+
end
|
30
|
+
|
31
|
+
def soap_client
|
32
|
+
@soap_client ||= SoapClient.new(@username, @password)
|
33
|
+
@soap_client
|
34
|
+
end
|
35
|
+
|
36
|
+
def rest_client
|
37
|
+
@rest_client ||= RestClient.new(@username, @password)
|
38
|
+
@rest_client
|
39
|
+
end
|
40
|
+
|
41
|
+
# alias for ClearConnect::RestClient#get_request
|
42
|
+
def get(query)
|
43
|
+
rest_client.get_request(query)
|
44
|
+
end
|
45
|
+
|
46
|
+
# alias for ClearConnect::SoapClient#post_request
|
47
|
+
def post(query)
|
48
|
+
soap_client.post_request(query)
|
49
|
+
end
|
50
|
+
|
51
|
+
# retrieves and sets session key for making requests, may raise
|
52
|
+
# exception if there is an error.
|
53
|
+
def get_session_key
|
54
|
+
response = rest_client.get_no_session(
|
55
|
+
action: 'getSessionKey').parsed_response[0]
|
56
|
+
|
57
|
+
if response['success'] == "1"
|
58
|
+
@sessionKey = response['sessionKey']
|
59
|
+
rest_client.set_session_key @sessionKey
|
60
|
+
# TODO: Incorporate sessions into Savon client.
|
61
|
+
#@soap_client.set_session_key @sessionKey if @soap_client
|
62
|
+
elsif response['errorCode']
|
63
|
+
raise "Session key retrieval failed with code: #{response['errorCode']}."
|
64
|
+
else
|
65
|
+
raise "Session key retrieval failed for an unknown reason."
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ClearConnect
|
2
|
+
class Configuration
|
3
|
+
attr_accessor \
|
4
|
+
:username,
|
5
|
+
:password,
|
6
|
+
:site_name,
|
7
|
+
:session,
|
8
|
+
:format
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@username = nil
|
12
|
+
@password = nil
|
13
|
+
@site_name = nil
|
14
|
+
@format = :json
|
15
|
+
@session = false
|
16
|
+
@endpoints = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def site_name=(site_name)
|
20
|
+
@site_name = site_name
|
21
|
+
end
|
22
|
+
|
23
|
+
#--
|
24
|
+
# do endpoints need to be set at any point?
|
25
|
+
#++
|
26
|
+
def endpoints
|
27
|
+
@endpoints ||= {
|
28
|
+
clearconnect: "https://agencystaffing.apihealthcare.com/#{@site_name}/clearConnect/2_0/index.cfm",
|
29
|
+
wsdl: "https://agencymedia001.apihealthcare.com/#{@site_name}/wsdl/staffingWebService.wsdl"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
#--
|
34
|
+
# I don't think this is necessary
|
35
|
+
#++
|
36
|
+
def endpoints=(options = {})
|
37
|
+
if options.nil?
|
38
|
+
@endpoints
|
39
|
+
end
|
40
|
+
@endpoints = options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class << self
|
45
|
+
attr_accessor :configuration
|
46
|
+
end
|
47
|
+
|
48
|
+
# Configure clearconnect someplace sensible,
|
49
|
+
# like config/initializers/clearconnect.rb
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# ClearConnect.configure do |c|
|
53
|
+
# c.username = 'username'
|
54
|
+
# c.password = 'password'
|
55
|
+
# c.sitename = 'sitename'
|
56
|
+
# end
|
57
|
+
|
58
|
+
def self.configure
|
59
|
+
self.configuration ||= Configuration.new
|
60
|
+
if block_given?
|
61
|
+
yield configuration
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class RestClient
|
2
|
+
include HTTParty
|
3
|
+
|
4
|
+
def initialize(username, password)
|
5
|
+
self.class.base_uri ClearConnect.configuration.endpoints[:clearconnect]
|
6
|
+
self.class.default_params :resultType => ClearConnect.configuration.format.to_s
|
7
|
+
self.class.format ClearConnect.configuration.format
|
8
|
+
@username = username
|
9
|
+
@password = password
|
10
|
+
@session = false
|
11
|
+
@sessionKey = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
# Takes a query of the format { key: 'value', key2: 'value' } where the keys are symbols corresponding
|
15
|
+
# to the parameters passed to the ClearConnect REST API
|
16
|
+
def get_request(query)
|
17
|
+
if @session and @sessionKey.nil?
|
18
|
+
raise "Invalid session key. You must first acquire a session key by calling 'get_session_key' before executing requests."
|
19
|
+
elsif not @session
|
20
|
+
query = normalize_query(query.merge(:sessionKey => @sessionKey))
|
21
|
+
options = { :query => query }
|
22
|
+
self.class.get("", options)
|
23
|
+
else
|
24
|
+
get_no_session(query)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_no_session(query)
|
29
|
+
query = normalize_query(query.merge(:username => @username, :password => @password))
|
30
|
+
options = { :query => query }
|
31
|
+
self.class.get("", options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_session_key(key)
|
35
|
+
puts "Setting session key: #{key}."
|
36
|
+
@session = true
|
37
|
+
@sessionKey = key
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
# Turns arguments that are arrays into comma-delimited strings
|
42
|
+
def normalize_query(query)
|
43
|
+
query.each_pair do |param, arg|
|
44
|
+
if arg.is_a? Array
|
45
|
+
query[param] = arg.join(',')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class SoapClient
|
2
|
+
def initialize(username, password, session)
|
3
|
+
wsdl = HTTParty.get(ClearConnect.configuration.endpoints[:wsdl], :format => 'xml').parsed_response
|
4
|
+
@client = Savon::Client.new(
|
5
|
+
wsdl: wsdl,
|
6
|
+
log_level: :info
|
7
|
+
)
|
8
|
+
@username = username
|
9
|
+
@password = password
|
10
|
+
@session = session
|
11
|
+
@default_params = {
|
12
|
+
:username => username,
|
13
|
+
:password => password,
|
14
|
+
:resultType => ClearConnect.configuration.format.to_s
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Encodes request, packages into required node, sends, decodes response
|
19
|
+
def generic_request(message)
|
20
|
+
request = "<requestXmlString>#{xml_encode(message)}</requestXmlString>"
|
21
|
+
response = @client.call(:tss_request, message: request)
|
22
|
+
# :tss_request_response => {:tss_request_return => [ugly value to be decoded]}
|
23
|
+
# response.body
|
24
|
+
JSON.parse(response.body[:tss_request_response][:tss_request_return])[0]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Takes a query of format { :key => 'value' } where :key is the properly formatted parameter and 'value' is the string value
|
28
|
+
# Parameters can be nested like so: { :tempRecords => { :tempRecord => [ { :key1 = 'value1', :key2 => 'value2' }, { :key1 => 'value3' } ] } }
|
29
|
+
# will produce <tempRecords><tempRecord><key1>value1</key1><key2>value2</key2></tempRecord><tempRecord><key1>value3</key1></tempRecord></tempRecords>
|
30
|
+
def post_request(query)
|
31
|
+
params = @default_params.merge(query)
|
32
|
+
post_data = XmlSimple.xml_out(params, RootName: 'clearviewRequest', NoAttr: true)
|
33
|
+
generic_request(post_data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def xml_encode(xml_string)
|
37
|
+
string = xml_string
|
38
|
+
characters = [
|
39
|
+
{ find: '&', replacement: '&' },
|
40
|
+
{ find: '"', replacement: '"' },
|
41
|
+
{ find: '<', replacement: '<' },
|
42
|
+
{ find: '>', replacement: '>' },
|
43
|
+
{ find: "'", replacement: ''' }
|
44
|
+
]
|
45
|
+
characters.each do |set|
|
46
|
+
new_string = string.gsub(set[:find], set[:replacement])
|
47
|
+
if not new_string.nil?
|
48
|
+
string = new_string
|
49
|
+
end
|
50
|
+
end
|
51
|
+
return string
|
52
|
+
end
|
53
|
+
|
54
|
+
def xml_decode(xml_string)
|
55
|
+
string = xml_string
|
56
|
+
characters = [
|
57
|
+
{ replacement: '&', find: '&' },
|
58
|
+
{ replacement: '"', find: '"' },
|
59
|
+
{ replacement: '<', find: '<' },
|
60
|
+
{ replacement: '>', find: '>' },
|
61
|
+
{ replacement: "'", find: ''' }
|
62
|
+
]
|
63
|
+
characters.each do |set|
|
64
|
+
new_string = string.gsub(set[:find], set[:replacement])
|
65
|
+
if not new_string.nil?
|
66
|
+
string = new_string
|
67
|
+
end
|
68
|
+
end
|
69
|
+
return string
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clearconnect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher Hunt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.10'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.10'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: savon
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.1.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.1.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: xml-simple
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.1.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.2
|
62
|
+
description: ''
|
63
|
+
email: chrahunt@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- Gemfile
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- clearconnect.gemspec
|
73
|
+
- lib/clearconnect.rb
|
74
|
+
- lib/clearconnect/client.rb
|
75
|
+
- lib/clearconnect/configuration.rb
|
76
|
+
- lib/clearconnect/rest_client.rb
|
77
|
+
- lib/clearconnect/soap_client.rb
|
78
|
+
- lib/clearconnect/version.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project: clearconnect
|
99
|
+
rubygems_version: 1.8.28
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: ClearConnect API Interface for Ruby
|
103
|
+
test_files: []
|
104
|
+
has_rdoc:
|