Class: SterlingApi::BackgroundCheck

Inherits:
Object
  • Object
show all
Extended by:
XmlHelper
Defined in:
lib/sterling_api/background_check.rb

Defined Under Namespace

Modules: XML

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlHelper

soap_wrapper, strip_instruct, xml_rpc_wrapper

Constructor Details

#initialize(options = {}) ⇒ BackgroundCheck

Returns a new instance of BackgroundCheck.



67
68
69
70
71
# File 'lib/sterling_api/background_check.rb', line 67

def initialize(options={})
  @options = options
  @xml = create_root
  self
end

Class Method Details

.all_ids(mode) ⇒ Object



9
10
11
# File 'lib/sterling_api/background_check.rb', line 9

def self.all_ids(mode)
  mode.to_s =~ /prod/ ? [25212, 25213, 25214, 25750, 25751, 25752, 25753, 25911] : [19432, 19439, 19440, 19442, 19443, 19444, 19445, 19437]
end

.for_package(package_id, options) ⇒ Object

combos

19432 = Package 1 = PRI-FIM, PRINCRF, PRINCRP, SSNV
19439 = Package 2 = PRI-FAM, PRINCRP, SSNV
19440 = Package 3 = MVR, PRINCRP, SSNV

ala carte

19442 = Package 5 = MVR only
19443 = Package 6 = PRINCRP
19444 = Package 7 = PRI-FFM, SSNV
19445 = Package 9 = PRI-FFM
19437 = Package 14 = PRI-FAM

2011-02-22:
Package 1 can logically be ordered with 5,9 & 14
Package 2 can logically be ordered with 5 & 9
Package 3 can logically be ordered with 9 & 14
Any combination of 5,6,7,9 & 14 could be ordered.


54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sterling_api/background_check.rb', line 54

def self.for_package(package_id, options)
  package_id = package_id.to_i
  
  background_check = self.new(options.merge(:package_id => package_id))

  background_check.add_ssnv # required for one-step orders

  background_check.add_name_and_address if all_ids(options[:mode]).include?(package_id)
  background_check.add_mvr              if mvr_ids(options[:mode]).include?(package_id)
  
  background_check
end

.mvr_ids(mode) ⇒ Object



13
14
15
# File 'lib/sterling_api/background_check.rb', line 13

def self.mvr_ids(mode)
  mode.to_s =~ /prod/ ? [25214, 25750] : [19440, 19442]
end

Instance Method Details

#add_mvrObject

Contains 0* //BackgroundCheck/BackgroundSearchPackage/Screenings/Screening/SearchLicense

options should contain:

licenses:  an array of license info hashes

license info hash:

:license_number  AN 1..20
:license_region  2 char State/Region


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/sterling_api/background_check.rb', line 167

def add_mvr
  builder = Nokogiri::XML::Builder.with(screening_node) do |xml|
    @options[:licenses].each do |hash|
      # xml.SearchLicense(:validFrom => ymd(hash[:valid_from]), :validTo => ymd(hash[:valid_to])) {
      xml.Region hash[:license_region] # State
      xml.SearchLicense {
        xml.License {
          xml.LicenseNumber(hash[:license_number])
          xml.LicenseName 'mvr'
          xml.LicenseDescription 'mvr'
          xml.LicensingAgency
        }
      }
    end
  end

  @xml = builder.to_xml
end

#add_name_and_addressObject

expects an array of :person_names in @options expects an array of :postal_addresses in @options

<PersonName type="subject|alias">
  <GivenName>Kevin</GivenName>
  <MiddleName>Fred</MiddleName>
  <FamilyName>Test</FamilyName>
</PersonName>
<PostalAddress type="current|prior" validFrom="2009-01-01">
  <Municipality>Madison</Municipality>
  <Region>WI</Region>
  <PostalCode>53711</PostalCode>
  <CountryCode>US</CountryCode>
  <DeliveryAddress>
    <AddressLine>1234 Main Rd</AddressLine>
  </DeliveryAddress>
</PostalAddress>


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/sterling_api/background_check.rb', line 204

def add_name_and_address
  builder = Nokogiri::XML::Builder.with(personal_data_node) do |xml|
    @options[:person_names].each do |hash|
      xml.PersonName(:type => hash[:type]){
        xml.GivenName hash[:first_name]
        xml.MiddleName hash[:middle_name]
        xml.FamilyName hash[:last_name]
      }
    end if @options[:person_names]

    @options[:postal_addresses].each do |hash|
      xml.PostalAddress(:type => hash[:type], :validFrom => ymd(hash[:valid_from]), :validTo => ymd(hash[:valid_to])){
        xml.Municipality hash[:municipality]
        xml.Region hash[:region]
        xml.PostalCode hash[:postal_code]
        xml.CountryCode hash[:country_code]
        xml.DeliveryAddress{
          xml.AddressLine hash[:address1]
          xml.AddressLine(hash[:address2]) if hash[:address2].present?
        }
      }
    end if @options[:postal_addresses]
  end

  @xml = builder.to_xml
end

#add_ssnvObject

<DemographicDetail>

  <GovernmentId issuingAuthority="SSN">123456789</GovernmentId>
  <DateOfBirth>1950-01-01</DateOfBirth>
</DemographicDetail>


236
237
238
239
240
241
242
243
244
245
# File 'lib/sterling_api/background_check.rb', line 236

def add_ssnv
  builder = Nokogiri::XML::Builder.with(personal_data_node) do |xml|
    xml.DemographicDetail{
      xml.GovernmentId(@options[:ssn], :issuingAuthority => 'SSN')
      xml.DateOfBirth(ymd(@options[:date_of_birth]))
    }
  end

  @xml = builder.to_xml
end

#create_rootObject

<BackgroundCheck

    userId="#{@order_as_user_id}"
    account="#{@account}"
    password="#{@password}">
  <BackgroundSearchPackage>
    <PersonalData>
      <ContactMethod>
        <InternetEmailAddress></InternetEmailAddress>
      </ContactMethod>
    </PersonalData>
    <Screenings>
      <PackageID>#{@package_id}</PackageID>
      <UserArea>
        <UserAreaContent>
          <PositionTitle>#{@position_applied_for}</PositionTitle>
        </UserAreaContent>
      </UserArea>
      (if non-MVR)
        <Screening type="abuse">
      (if MVR)
        <Screening type="license", qualifer="mvPersonal">
    </Screenings>
  </BackgroundSearchPackage>
  <UserArea>
    <UserAreaContent>
      <OnlineAddress>
        <InternetWebAddress>#{AppSettings[:sterling_return_url]}</InternetWebAddress>
      </OnlineAddress>
      <ReturnOrderNumber>Y</ReturnOrderNumber>
      <ResultStatusReturn>
        <RedStatusReturn>Ineligble</RedStatusReturn>
        <YellowStatusReturn>Decisional</YellowStatusReturn>
        <GreenStatusReturn>Eligible</GreenStatusReturn>
      </ResultStatusReturn>
    </UserAreaContent>
  </UserArea>
</BackgroundCheck>


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/sterling_api/background_check.rb', line 111

def create_root
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.BackgroundCheck(
      :userId => @options[:order_as_user_id],
      :account => @options[:account],
      :password => @options[:password]
    ){
      xml.BackgroundSearchPackage{
        xml.PersonalData{
          xml.ContactMethod{
            xml.InternetEmailAddress @options[:contact_email]
          }
        }
        xml.Screenings{
          xml.PackageID @options[:package_id]
          xml.UserArea {
            xml.userAreaContent{
              xml.PositionTitle @options[:position_applied_for]
            }
          }
          if self.class.mvr_ids(@options[:mode]).include?(@options[:package_id])
            xml.Screening(:type =>  "license", :qualifier => "mvPersonal")
          else
            xml.Screening(:type =>  "abuse")
          end
        }
      }
      xml.UserArea{
        xml.UserAreaContent{
          xml.OnlineAddress{
            xml.InternetWebAddress AppSettings[:sterling_return_url]
          }
          xml.ReturnOrderNumber "Y"
          xml.ResultStatusReturn {
            xml.RedStatusReturn "Ineligible"
            xml.YellowStatusReturn "Decisional"
            xml.GreenStatusReturn "Eligible"
          }
        }
      }
    }
  end

  builder.to_xml
end

#to_xmlObject



247
248
249
# File 'lib/sterling_api/background_check.rb', line 247

def to_xml
  self.class.xml_rpc_wrapper(@xml)
end