sterling_api 1.0.4
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 +3 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +2 -0
- data/Rakefile +2 -0
- data/doc/AdminRequest.xsd +47 -0
- data/doc/AdminResponse.xsd +64 -0
- data/doc/CPBackgroundReports.xsd +55 -0
- data/doc/CPScreenings.xsd +1762 -0
- data/doc/admin.wsdl +57 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/sterling_api/background_check.rb +339 -0
- data/lib/sterling_api/password_change.rb +65 -0
- data/lib/sterling_api/remote_actions.rb +116 -0
- data/lib/sterling_api/version.rb +3 -0
- data/lib/sterling_api/xml_helper.rb +43 -0
- data/lib/sterling_api/xml_samples.rb +50 -0
- data/lib/sterling_api.rb +124 -0
- data/lib/tasks/sterling_api_tasks.rake +4 -0
- data/sterling_api.gemspec +27 -0
- data/test/background_check_test.rb +304 -0
- data/test/password_change_test.rb +32 -0
- data/test/remote_actions_test.rb +47 -0
- data/test/sterling_api_test.rb +70 -0
- data/test/test_helper.rb +143 -0
- data/uninstall.rb +1 -0
- metadata +139 -0
data/doc/admin.wsdl
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<wsdl:definitions
|
3
|
+
targetNamespace="http://www.cpscreen.com/schemas"
|
4
|
+
xmlns:tns="http://www.cpscreen.com/schemas"
|
5
|
+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
6
|
+
xmlns="http://schemas.xmlsoap.org/wsdl/"
|
7
|
+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
8
|
+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
9
|
+
<wsdl:types>
|
10
|
+
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.cpscreen.com/schemas">
|
11
|
+
<xs:include schemaLocation="AdminRequest.xsd"/>
|
12
|
+
<xs:include schemaLocation="AdminResponse.xsd"/>
|
13
|
+
</xs:schema>
|
14
|
+
</wsdl:types>
|
15
|
+
<wsdl:message name="AdminRequestMessage">
|
16
|
+
<wsdl:part name="Message" element="tns:ChoicePointAdminRequest"/>
|
17
|
+
</wsdl:message>
|
18
|
+
<wsdl:message name="AdminResponseMessage">
|
19
|
+
<wsdl:part name="Message" element="tns:ChoicePointAdminResponse"/>
|
20
|
+
</wsdl:message>
|
21
|
+
<wsdl:portType name="AdminInterface">
|
22
|
+
<wsdl:operation name="ChangePasswords">
|
23
|
+
<wsdl:input message="tns:AdminRequestMessage"/>
|
24
|
+
<wsdl:output message="tns:AdminResponseMessage"/>
|
25
|
+
</wsdl:operation>
|
26
|
+
<wsdl:operation name="GetPackages">
|
27
|
+
<wsdl:input message="tns:AdminRequestMessage"/>
|
28
|
+
<wsdl:output message="tns:AdminResponseMessage"/>
|
29
|
+
</wsdl:operation>
|
30
|
+
</wsdl:portType>
|
31
|
+
<wsdl:binding name="AdminSoapHttpBinding" type="tns:AdminInterface">
|
32
|
+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
33
|
+
<wsdl:operation name="ChangePasswords">
|
34
|
+
<soap:operation soapAction="http://www.cpscreen.com/pub/xchange/admin/ChangePasswords"/>
|
35
|
+
<wsdl:input>
|
36
|
+
<soap:body use="literal"/>
|
37
|
+
</wsdl:input>
|
38
|
+
<wsdl:output>
|
39
|
+
<soap:body use="literal"/>
|
40
|
+
</wsdl:output>
|
41
|
+
</wsdl:operation>
|
42
|
+
<wsdl:operation name="GetPackages">
|
43
|
+
<soap:operation soapAction="http://www.cpscreen.com/pub/xchange/admin/GetPackages"/>
|
44
|
+
<wsdl:input>
|
45
|
+
<soap:body use="literal"/>
|
46
|
+
</wsdl:input>
|
47
|
+
<wsdl:output>
|
48
|
+
<soap:body use="literal"/>
|
49
|
+
</wsdl:output>
|
50
|
+
</wsdl:operation>
|
51
|
+
</wsdl:binding>
|
52
|
+
<wsdl:service name="AdminService">
|
53
|
+
<wsdl:port name="AdminEndpoint" binding="tns:AdminSoapHttpBinding">
|
54
|
+
<soap:address location="https://www.cpscreen.com/pub/xchange/admin"/>
|
55
|
+
</wsdl:port>
|
56
|
+
</wsdl:service>
|
57
|
+
</wsdl:definitions>
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,339 @@
|
|
1
|
+
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module SterlingApi
|
5
|
+
|
6
|
+
class BackgroundCheck
|
7
|
+
extend XmlHelper
|
8
|
+
|
9
|
+
def self.all_ids(mode)
|
10
|
+
mode.to_s =~ /prod/ ? [25212, 25213, 25214, 25750, 25751, 25752, 25753, 25911] : [19432, 19439, 19440, 19442, 19443, 19444, 19445, 19437]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.mvr_ids(mode)
|
14
|
+
mode.to_s =~ /prod/ ? [25214, 25750] : [19440, 19442]
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# PRI-FAM:
|
19
|
+
# PRI-FFM:
|
20
|
+
# PRI-FIM:
|
21
|
+
# PRINCRF:
|
22
|
+
# PRINCRP:
|
23
|
+
# PersonalData/PersonName
|
24
|
+
# PersonalData/PostalAddress
|
25
|
+
#
|
26
|
+
# SSNV:
|
27
|
+
# PersonalData/DemographicDetail
|
28
|
+
#
|
29
|
+
# MVR:
|
30
|
+
# PersonalData/Licenses
|
31
|
+
#
|
32
|
+
|
33
|
+
|
34
|
+
# combos
|
35
|
+
# 19432 = Package 1 = PRI-FIM, PRINCRF, PRINCRP, SSNV
|
36
|
+
# 19439 = Package 2 = PRI-FAM, PRINCRP, SSNV
|
37
|
+
# 19440 = Package 3 = MVR, PRINCRP, SSNV
|
38
|
+
#
|
39
|
+
# ala carte
|
40
|
+
# 19442 = Package 5 = MVR only
|
41
|
+
# 19443 = Package 6 = PRINCRP
|
42
|
+
# 19444 = Package 7 = PRI-FFM, SSNV
|
43
|
+
# 19445 = Package 9 = PRI-FFM
|
44
|
+
# 19437 = Package 14 = PRI-FAM
|
45
|
+
#
|
46
|
+
#
|
47
|
+
# 2011-02-22:
|
48
|
+
# Package 1 can logically be ordered with 5,9 & 14
|
49
|
+
# Package 2 can logically be ordered with 5 & 9
|
50
|
+
# Package 3 can logically be ordered with 9 & 14
|
51
|
+
# Any combination of 5,6,7,9 & 14 could be ordered.
|
52
|
+
#
|
53
|
+
#
|
54
|
+
def self.for_package(package_id, options)
|
55
|
+
package_id = package_id.to_i
|
56
|
+
|
57
|
+
background_check = self.new(options.merge(:package_id => package_id))
|
58
|
+
|
59
|
+
background_check.add_ssnv # required for one-step orders
|
60
|
+
|
61
|
+
background_check.add_name_and_address if all_ids(options[:mode]).include?(package_id)
|
62
|
+
background_check.add_mvr if mvr_ids(options[:mode]).include?(package_id)
|
63
|
+
|
64
|
+
background_check
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(options={})
|
68
|
+
@options = options
|
69
|
+
@xml = create_root
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
# <BackgroundCheck
|
74
|
+
# userId="#{@order_as_user_id}"
|
75
|
+
# account="#{@account}"
|
76
|
+
# password="#{@password}">
|
77
|
+
# <BackgroundSearchPackage>
|
78
|
+
# <PersonalData>
|
79
|
+
# <ContactMethod>
|
80
|
+
# <InternetEmailAddress></InternetEmailAddress>
|
81
|
+
# </ContactMethod>
|
82
|
+
# </PersonalData>
|
83
|
+
# <Screenings>
|
84
|
+
# <PackageID>#{@package_id}</PackageID>
|
85
|
+
# <UserArea>
|
86
|
+
# <UserAreaContent>
|
87
|
+
# <PositionTitle>#{@position_applied_for}</PositionTitle>
|
88
|
+
# </UserAreaContent>
|
89
|
+
# </UserArea>
|
90
|
+
# (if non-MVR)
|
91
|
+
# <Screening type="abuse">
|
92
|
+
# (if MVR)
|
93
|
+
# <Screening type="license", qualifer="mvPersonal">
|
94
|
+
# </Screenings>
|
95
|
+
# </BackgroundSearchPackage>
|
96
|
+
# <UserArea>
|
97
|
+
# <UserAreaContent>
|
98
|
+
# <OnlineAddress>
|
99
|
+
# <InternetWebAddress>#{AppSettings[:sterling_return_url]}</InternetWebAddress>
|
100
|
+
# </OnlineAddress>
|
101
|
+
# <ReturnOrderNumber>Y</ReturnOrderNumber>
|
102
|
+
# <ResultStatusReturn>
|
103
|
+
# <RedStatusReturn>Ineligble</RedStatusReturn>
|
104
|
+
# <YellowStatusReturn>Decisional</YellowStatusReturn>
|
105
|
+
# <GreenStatusReturn>Eligible</GreenStatusReturn>
|
106
|
+
# </ResultStatusReturn>
|
107
|
+
# </UserAreaContent>
|
108
|
+
# </UserArea>
|
109
|
+
# </BackgroundCheck>
|
110
|
+
#
|
111
|
+
def create_root
|
112
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
113
|
+
xml.BackgroundCheck(
|
114
|
+
:userId => @options[:order_as_user_id],
|
115
|
+
:account => @options[:account],
|
116
|
+
:password => @options[:password]
|
117
|
+
){
|
118
|
+
xml.BackgroundSearchPackage{
|
119
|
+
xml.PersonalData{
|
120
|
+
xml.ContactMethod{
|
121
|
+
xml.InternetEmailAddress @options[:contact_email]
|
122
|
+
}
|
123
|
+
}
|
124
|
+
xml.Screenings{
|
125
|
+
xml.PackageID @options[:package_id]
|
126
|
+
xml.UserArea {
|
127
|
+
xml.userAreaContent{
|
128
|
+
xml.PositionTitle @options[:position_applied_for]
|
129
|
+
}
|
130
|
+
}
|
131
|
+
if MVR_IDS.include?(@options[:package_id])
|
132
|
+
xml.Screening(:type => "license", :qualifier => "mvPersonal")
|
133
|
+
else
|
134
|
+
xml.Screening(:type => "abuse")
|
135
|
+
end
|
136
|
+
}
|
137
|
+
}
|
138
|
+
xml.UserArea{
|
139
|
+
xml.UserAreaContent{
|
140
|
+
xml.OnlineAddress{
|
141
|
+
xml.InternetWebAddress AppSettings[:sterling_return_url]
|
142
|
+
}
|
143
|
+
xml.ReturnOrderNumber "Y"
|
144
|
+
xml.ResultStatusReturn {
|
145
|
+
xml.RedStatusReturn "Ineligible"
|
146
|
+
xml.YellowStatusReturn "Decisional"
|
147
|
+
xml.GreenStatusReturn "Eligible"
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
builder.to_xml
|
155
|
+
end
|
156
|
+
|
157
|
+
# Contains 0*
|
158
|
+
# //BackgroundCheck/BackgroundSearchPackage/Screenings/Screening/SearchLicense
|
159
|
+
#
|
160
|
+
# options should contain:
|
161
|
+
# licenses: an array of license info hashes
|
162
|
+
#
|
163
|
+
# license info hash:
|
164
|
+
# :license_number AN 1..20
|
165
|
+
# :license_region 2 char State/Region
|
166
|
+
#
|
167
|
+
def add_mvr
|
168
|
+
builder = Nokogiri::XML::Builder.with(screening_node) do |xml|
|
169
|
+
@options[:licenses].each do |hash|
|
170
|
+
# xml.SearchLicense(:validFrom => ymd(hash[:valid_from]), :validTo => ymd(hash[:valid_to])) {
|
171
|
+
xml.Region hash[:license_region] # State
|
172
|
+
xml.SearchLicense {
|
173
|
+
xml.License {
|
174
|
+
xml.LicenseNumber(hash[:license_number])
|
175
|
+
xml.LicenseName 'mvr'
|
176
|
+
xml.LicenseDescription 'mvr'
|
177
|
+
xml.LicensingAgency
|
178
|
+
}
|
179
|
+
}
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
@xml = builder.to_xml
|
184
|
+
end
|
185
|
+
|
186
|
+
#
|
187
|
+
# expects an array of :person_names in @options
|
188
|
+
# expects an array of :postal_addresses in @options
|
189
|
+
#
|
190
|
+
# <PersonName type="subject|alias">
|
191
|
+
# <GivenName>Kevin</GivenName>
|
192
|
+
# <MiddleName>Fred</MiddleName>
|
193
|
+
# <FamilyName>Test</FamilyName>
|
194
|
+
# </PersonName>
|
195
|
+
# <PostalAddress type="current|prior" validFrom="2009-01-01">
|
196
|
+
# <Municipality>Madison</Municipality>
|
197
|
+
# <Region>WI</Region>
|
198
|
+
# <PostalCode>53711</PostalCode>
|
199
|
+
# <CountryCode>US</CountryCode>
|
200
|
+
# <DeliveryAddress>
|
201
|
+
# <AddressLine>1234 Main Rd</AddressLine>
|
202
|
+
# </DeliveryAddress>
|
203
|
+
# </PostalAddress>
|
204
|
+
def add_name_and_address
|
205
|
+
builder = Nokogiri::XML::Builder.with(personal_data_node) do |xml|
|
206
|
+
@options[:person_names].each do |hash|
|
207
|
+
xml.PersonName(:type => hash[:type]){
|
208
|
+
xml.GivenName hash[:first_name]
|
209
|
+
xml.MiddleName hash[:middle_name]
|
210
|
+
xml.FamilyName hash[:last_name]
|
211
|
+
}
|
212
|
+
end if @options[:person_names]
|
213
|
+
|
214
|
+
@options[:postal_addresses].each do |hash|
|
215
|
+
xml.PostalAddress(:type => hash[:type], :validFrom => ymd(hash[:valid_from]), :validTo => ymd(hash[:valid_to])){
|
216
|
+
xml.Municipality hash[:municipality]
|
217
|
+
xml.Region hash[:region]
|
218
|
+
xml.PostalCode hash[:postal_code]
|
219
|
+
xml.CountryCode hash[:country_code]
|
220
|
+
xml.DeliveryAddress{
|
221
|
+
xml.AddressLine hash[:address1]
|
222
|
+
xml.AddressLine(hash[:address2]) if hash[:address2].present?
|
223
|
+
}
|
224
|
+
}
|
225
|
+
end if @options[:postal_addresses]
|
226
|
+
end
|
227
|
+
|
228
|
+
@xml = builder.to_xml
|
229
|
+
end
|
230
|
+
|
231
|
+
# <DemographicDetail>
|
232
|
+
# <GovernmentId issuingAuthority="SSN">123456789</GovernmentId>
|
233
|
+
# <DateOfBirth>1950-01-01</DateOfBirth>
|
234
|
+
# </DemographicDetail>
|
235
|
+
#
|
236
|
+
def add_ssnv
|
237
|
+
builder = Nokogiri::XML::Builder.with(personal_data_node) do |xml|
|
238
|
+
xml.DemographicDetail{
|
239
|
+
xml.GovernmentId(@options[:ssn], :issuingAuthority => 'SSN')
|
240
|
+
xml.DateOfBirth(ymd(@options[:date_of_birth]))
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
@xml = builder.to_xml
|
245
|
+
end
|
246
|
+
|
247
|
+
def to_xml
|
248
|
+
self.class.xml_rpc_wrapper(@xml)
|
249
|
+
end
|
250
|
+
|
251
|
+
protected
|
252
|
+
|
253
|
+
def doc
|
254
|
+
Nokogiri::XML(@xml)
|
255
|
+
end
|
256
|
+
|
257
|
+
def personal_data_node
|
258
|
+
doc.at('//BackgroundCheck/BackgroundSearchPackage/PersonalData')
|
259
|
+
end
|
260
|
+
|
261
|
+
def screening_node
|
262
|
+
doc.at('//BackgroundCheck/BackgroundSearchPackage/Screenings/Screening')
|
263
|
+
end
|
264
|
+
|
265
|
+
# expects a Time or DateTime
|
266
|
+
def ymd(date)
|
267
|
+
return date if date.is_a?(String)
|
268
|
+
date.strftime("%Y-%m-%d") if date
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
module XML
|
273
|
+
|
274
|
+
SAMPLE_ORDER_RESPONSE = %Q{<?xml version="1.0" encoding="UTF-8"?>
|
275
|
+
<soapenv:Envelope
|
276
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
277
|
+
xmlns:cp="http://www.cpscreen.com/schemas"
|
278
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
279
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
280
|
+
<soapenv:Body>
|
281
|
+
<BackgroundReports xmlns="http://www.cpscreen.com/schemas">
|
282
|
+
<BackgroundReportPackage type="report">
|
283
|
+
<ProviderReferenceId>WPS-6266154</ProviderReferenceId>
|
284
|
+
<PackageInformation>
|
285
|
+
<ClientReferences>
|
286
|
+
<ClientReference>Youth123456</ClientReference>
|
287
|
+
<ClientReference>CN=Youth Tester/O=Youth</ClientReference>
|
288
|
+
</ClientReferences>
|
289
|
+
<Quotebacks>
|
290
|
+
<Quoteback name="Youth-83SQ7J"/>
|
291
|
+
</Quotebacks>
|
292
|
+
</PackageInformation>
|
293
|
+
<PersonalData>
|
294
|
+
<PersonName type="subject">
|
295
|
+
<GivenName>Test</GivenName>
|
296
|
+
<FamilyName>Youth</FamilyName>
|
297
|
+
</PersonName>
|
298
|
+
<DemographicDetail>
|
299
|
+
<GovernmentId issuingAuthority="SSN">123456789</GovernmentId>
|
300
|
+
<DateOfBirth/>
|
301
|
+
<Gender>F</Gender>
|
302
|
+
</DemographicDetail>
|
303
|
+
</PersonalData>
|
304
|
+
<ScreeningStatus>
|
305
|
+
<OrderStatus>InProgress</OrderStatus>
|
306
|
+
</ScreeningStatus>
|
307
|
+
<ScreeningResults mediaType="html">
|
308
|
+
<InternetWebAddress>https://screentest.lexisnexis.com/pub/l/login/userLogin.do?referer=https://screentest.lexisnexis.com/pub/l/jsp/menu/orderViewingMenuFrameSet.jsp?key=123|ABCDEFG</InternetWebAddress>
|
309
|
+
</ScreeningResults>
|
310
|
+
</BackgroundReportPackage>
|
311
|
+
</BackgroundReports>
|
312
|
+
</soapenv:Body>
|
313
|
+
</soapenv:Envelope>
|
314
|
+
}
|
315
|
+
|
316
|
+
SAMPLE_USER_LOCKED_RESPONSE = %q[<?xml version="1.0" encoding="UTF-8"?>
|
317
|
+
<soapenv:Envelope
|
318
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
319
|
+
xmlns:cp="http://www.cpscreen.com/schemas"
|
320
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
321
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
322
|
+
<soapenv:Body>
|
323
|
+
<BackgroundReports xmlns="http://www.cpscreen.com/schemas">
|
324
|
+
<BackgroundReportPackage type="errors">
|
325
|
+
<ErrorReport>
|
326
|
+
<ErrorCode>210</ErrorCode>
|
327
|
+
<ErrorDescription>User is locked</ErrorDescription>
|
328
|
+
</ErrorReport>
|
329
|
+
</BackgroundReportPackage>
|
330
|
+
</BackgroundReports>
|
331
|
+
</soapenv:Body>
|
332
|
+
</soapenv:Envelope>
|
333
|
+
]
|
334
|
+
|
335
|
+
end # module XML
|
336
|
+
|
337
|
+
end # class BackgroundCheck
|
338
|
+
|
339
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module SterlingApi
|
5
|
+
|
6
|
+
class PasswordChange
|
7
|
+
extend XmlHelper
|
8
|
+
|
9
|
+
#
|
10
|
+
# options:
|
11
|
+
# :account
|
12
|
+
# :password
|
13
|
+
# :new_password
|
14
|
+
#
|
15
|
+
def initialize(account, password, new_password, subaccount=nil)
|
16
|
+
@account, @password, @new_password, @subaccount = account, password, new_password, subaccount
|
17
|
+
@xml = create_xml
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
%q[
|
22
|
+
<ChoicePointAdminRequest
|
23
|
+
xmlns="http://www.cpscreen.com/schemas"
|
24
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
25
|
+
xsi:schemaLocation="http://www.cpscreen.com/schemas AdminRequest.xsd"
|
26
|
+
userId="XCHANGE"
|
27
|
+
account="999999KLX"
|
28
|
+
password="XXXXXXXXX">
|
29
|
+
|
30
|
+
<ChangePassword>
|
31
|
+
<Account>999999KLX</Account>
|
32
|
+
<UserId>XCHANGE</UserId>
|
33
|
+
<Password>As@34Gsg!#</Password>
|
34
|
+
<NewPassword>the_new_password</NewPassword>
|
35
|
+
</ChangePassword>
|
36
|
+
|
37
|
+
</ChoicePointAdminRequest>
|
38
|
+
]
|
39
|
+
def create_xml
|
40
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
41
|
+
xml.ChoicePointAdminRequest(
|
42
|
+
:xmlns => 'http://www.cpscreen.com/schemas',
|
43
|
+
:userId => 'XCHANGE',
|
44
|
+
:account => "#{@account}#{@subaccount}",
|
45
|
+
:password => @password
|
46
|
+
){
|
47
|
+
xml.ChangePassword{
|
48
|
+
xml.Account "#{@account}#{@subaccount}"
|
49
|
+
xml.UserId 'XCHANGE'
|
50
|
+
xml.Password @password
|
51
|
+
xml.NewPassword @new_password
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
builder.to_xml
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_xml
|
60
|
+
self.class.soap_wrapper(@xml)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
module SterlingApi
|
5
|
+
|
6
|
+
module RemoteActions
|
7
|
+
|
8
|
+
class Response
|
9
|
+
attr_accessor :status
|
10
|
+
attr_accessor :body
|
11
|
+
attr_accessor :raw_response
|
12
|
+
|
13
|
+
def initialize(ret_val, resp)
|
14
|
+
self.status = ret_val
|
15
|
+
self.raw_response = resp
|
16
|
+
self.body = resp.body
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure?
|
20
|
+
!success?
|
21
|
+
end
|
22
|
+
|
23
|
+
def success?
|
24
|
+
(self.body =~ %r{<Error(Report)?>}m).nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors
|
28
|
+
error_code = self.body.match(%r{<ErrorCode>(.+)</ErrorCode>})[1] rescue '???'
|
29
|
+
error_description = self.body.match(%r{<ErrorDescription>(.+)</ErrorDescription>})[1] rescue '???'
|
30
|
+
{
|
31
|
+
:error_code => error_code,
|
32
|
+
:error_description => error_description
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# for use in tests
|
38
|
+
#
|
39
|
+
# options:
|
40
|
+
# :ret_val the Net::HTTP return value
|
41
|
+
# pass true for Net::HTTPSuccess, Net::HTTPRedirection
|
42
|
+
# pass false for all others
|
43
|
+
#
|
44
|
+
# :body the body 'returned' by the supposed Net::HTTP request
|
45
|
+
#
|
46
|
+
class MockResponse < Response
|
47
|
+
def initialize(options={})
|
48
|
+
Struct.new('MockHttpResponse', :body) unless defined?(Struct::MockHttpResponse)
|
49
|
+
mock_http_response = Struct::MockHttpResponse.new(options[:body])
|
50
|
+
super(options[:ret_val], mock_http_response)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Request
|
55
|
+
attr_accessor :headers
|
56
|
+
attr_accessor :proxy
|
57
|
+
attr_accessor :proxy_port
|
58
|
+
attr_accessor :body
|
59
|
+
attr_accessor :http_process
|
60
|
+
attr_accessor :url
|
61
|
+
|
62
|
+
def initialize(options={})
|
63
|
+
default_options = {
|
64
|
+
:body => nil,
|
65
|
+
:headers => {'Content-Type' => 'application/xml', 'Accept' => 'application/xml'},
|
66
|
+
:proxy => nil,
|
67
|
+
:proxy_port => nil,
|
68
|
+
}
|
69
|
+
default_options.merge!(options)
|
70
|
+
|
71
|
+
self.proxy = default_options[:proxy]
|
72
|
+
self.proxy_port = default_options[:proxy_port]
|
73
|
+
self.headers = default_options[:headers]
|
74
|
+
self.body = default_options[:body]
|
75
|
+
self.url = default_options[:url]
|
76
|
+
end
|
77
|
+
|
78
|
+
def host_from_url
|
79
|
+
self.url.match(%r{(?:https?://)?([^/]+)})[1].gsub(/:\d+$/, "") rescue nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def is_ssl?
|
83
|
+
!!(self.url =~ /^https:/i)
|
84
|
+
end
|
85
|
+
|
86
|
+
def port_from_url
|
87
|
+
if m = self.url.match(%r{(?:(http|https)://)[^:]+:(\d+)/?})
|
88
|
+
return m[2].to_i
|
89
|
+
elsif self.url =~ /^https:/i
|
90
|
+
return 443
|
91
|
+
else
|
92
|
+
80
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def send_request
|
97
|
+
self.http_process = Net::HTTP.new( host_from_url, port_from_url, self.proxy, self.proxy_port )
|
98
|
+
self.http_process.use_ssl = is_ssl?
|
99
|
+
|
100
|
+
http_process.start
|
101
|
+
resp = http_process.post(self.url, self.body, self.headers)
|
102
|
+
ret_val = false
|
103
|
+
case resp
|
104
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
105
|
+
ret_val = true
|
106
|
+
else
|
107
|
+
ret_val = false
|
108
|
+
end
|
109
|
+
return SterlingApi::RemoteActions::Response.new(ret_val, resp)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
module SterlingApi
|
3
|
+
|
4
|
+
module XmlHelper
|
5
|
+
|
6
|
+
def soap_wrapper(xml)
|
7
|
+
%Q{<?xml version="1.0"?>
|
8
|
+
<soapenv:Envelope
|
9
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
10
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
11
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
12
|
+
<soapenv:Body>
|
13
|
+
#{strip_instruct(xml)}
|
14
|
+
</soapenv:Body>
|
15
|
+
</soapenv:Envelope>
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def xml_rpc_wrapper(xml)
|
20
|
+
%Q{<?xml version="1.0"?>
|
21
|
+
<methodCall>
|
22
|
+
<methodName>webhuckXMLrequest</methodName>
|
23
|
+
<params>
|
24
|
+
<param>
|
25
|
+
<value>
|
26
|
+
<struct>
|
27
|
+
#{strip_instruct(xml)}
|
28
|
+
</struct>
|
29
|
+
</value>
|
30
|
+
</param>
|
31
|
+
</params>
|
32
|
+
</methodCall>
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def strip_instruct(xml)
|
37
|
+
xml.gsub!(%r{<\?xml\s+version=['"]1.0['"]\s*\?>}, '')
|
38
|
+
xml
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SterlingApi
|
2
|
+
|
3
|
+
module XmlSamples
|
4
|
+
|
5
|
+
CHANGE_PASSWORD_COMPLETE_RESPONSE = %q[<?xml version="1.0" encoding="UTF-8"?>
|
6
|
+
<soapenv:Envelope
|
7
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
8
|
+
xmlns:cp="http://www.cpscreen.com/schemas"
|
9
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
10
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
11
|
+
<soapenv:Body>
|
12
|
+
<ChoicePointAdminResponse xmlns="http://www.cpscreen.com/schemas">
|
13
|
+
<ChangePassword>
|
14
|
+
<Status>Complete</Status>
|
15
|
+
<Account>036483</Account>
|
16
|
+
<UserId>XCHANGE</UserId>
|
17
|
+
<Password>This should be right</Password>
|
18
|
+
<NewPassword>hC0^eL0@sK9@aN7^mV4#iT6(cM0!vG1(cH8#aO8@</NewPassword>
|
19
|
+
</ChangePassword>
|
20
|
+
</ChoicePointAdminResponse>
|
21
|
+
</soapenv:Body>
|
22
|
+
</soapenv:Envelope>
|
23
|
+
]
|
24
|
+
|
25
|
+
CHANGE_PASSWORD_FAIL_RESPONSE = %q[<?xml version="1.0" encoding="UTF-8"?>
|
26
|
+
<soapenv:Envelope
|
27
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
28
|
+
xmlns:cp="http://www.cpscreen.com/schemas"
|
29
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
30
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
31
|
+
<soapenv:Body>
|
32
|
+
<ChoicePointAdminResponse xmlns="http://www.cpscreen.com/schemas">
|
33
|
+
<ChangePassword>
|
34
|
+
<Status>Fail</Status>
|
35
|
+
<Account>036483</Account>
|
36
|
+
<UserId>XCHANGE</UserId>
|
37
|
+
<Password>This should be wrong</Password>
|
38
|
+
<NewPassword>hC0^eL0@sK9@aN7^mV4#iT6(cM0!vG1(cH8#aO8@</NewPassword>
|
39
|
+
<Error>
|
40
|
+
<ErrorCode>250</ErrorCode>
|
41
|
+
<ErrorDescription>Invalid old password</ErrorDescription>
|
42
|
+
</Error>
|
43
|
+
</ChangePassword>
|
44
|
+
</ChoicePointAdminResponse>
|
45
|
+
</soapenv:Body>
|
46
|
+
</soapenv:Envelope>
|
47
|
+
]
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|