Class: BluelineServices::Request

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/blueline_services/request.rb

Constant Summary collapse

ADDITIONAL_ITEMS =
[:postback_url, :postback_username,
:postback_password, :embed_credentials, :ordernotes,
:interface, :monthly_income, :monthly_rent]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#alias, #person_name, #screen

Constructor Details

#initialize(h = {}) {|_self| ... } ⇒ Request

Returns a new instance of Request.

Yields:

  • (_self)

Yield Parameters:



54
55
56
57
58
59
60
# File 'lib/blueline_services/request.rb', line 54

def initialize(h={})
  init_defaults
  h.each do |k,v|
    send("#{k}=", v) if respond_to?("#{k}=")
  end
  yield self if block_given?
end

Instance Attribute Details

#actionObject

BackgroundSearchPackage



16
17
18
# File 'lib/blueline_services/request.rb', line 16

def action
  @action
end

#address_lineObject

PostalAddress



38
39
40
# File 'lib/blueline_services/request.rb', line 38

def address_line
  @address_line
end

#affixObject

PersonName



26
27
28
# File 'lib/blueline_services/request.rb', line 26

def affix
  @affix
end

#aliasesObject (readonly)

Returns the value of attribute aliases.



52
53
54
# File 'lib/blueline_services/request.rb', line 52

def aliases
  @aliases
end

#base_uriObject

BackgroundCheck



10
11
12
# File 'lib/blueline_services/request.rb', line 10

def base_uri
  @base_uri
end

#configObject

BackgroundCheck



10
11
12
# File 'lib/blueline_services/request.rb', line 10

def config
  @config
end

#country_codeObject

PostalAddress



38
39
40
# File 'lib/blueline_services/request.rb', line 38

def country_code
  @country_code
end

#date_of_birthObject

DemographicDetail



32
33
34
# File 'lib/blueline_services/request.rb', line 32

def date_of_birth
  @date_of_birth
end

#email_addressObject

PersonalData



22
23
24
# File 'lib/blueline_services/request.rb', line 22

def email_address
  @email_address
end

#family_nameObject

PersonName



26
27
28
# File 'lib/blueline_services/request.rb', line 26

def family_name
  @family_name
end

#given_nameObject

PersonName



26
27
28
# File 'lib/blueline_services/request.rb', line 26

def given_name
  @given_name
end

#government_idObject

DemographicDetail



32
33
34
# File 'lib/blueline_services/request.rb', line 32

def government_id
  @government_id
end

#issuing_authorityObject

DemographicDetail



32
33
34
# File 'lib/blueline_services/request.rb', line 32

def issuing_authority
  @issuing_authority
end

#middle_nameObject

PersonName



26
27
28
# File 'lib/blueline_services/request.rb', line 26

def middle_name
  @middle_name
end

#municipalityObject

PostalAddress



38
39
40
# File 'lib/blueline_services/request.rb', line 38

def municipality
  @municipality
end

#passwordObject

BackgroundCheck



10
11
12
# File 'lib/blueline_services/request.rb', line 10

def password
  @password
end

#postal_codeObject

PostalAddress



38
39
40
# File 'lib/blueline_services/request.rb', line 38

def postal_code
  @postal_code
end

#referenceObject

BackgroundSearchPackage



16
17
18
# File 'lib/blueline_services/request.rb', line 16

def reference
  @reference
end

#reference_idObject

BackgroundSearchPackage



16
17
18
# File 'lib/blueline_services/request.rb', line 16

def reference_id
  @reference_id
end

#regionObject

PostalAddress



38
39
40
# File 'lib/blueline_services/request.rb', line 38

def region
  @region
end

#screeningsObject (readonly)

Screenings



46
47
48
# File 'lib/blueline_services/request.rb', line 46

def screenings
  @screenings
end

#ssn_country_codeObject

DemographicDetail



32
33
34
# File 'lib/blueline_services/request.rb', line 32

def ssn_country_code
  @ssn_country_code
end

#street_nameObject

PostalAddress



38
39
40
# File 'lib/blueline_services/request.rb', line 38

def street_name
  @street_name
end

#telephoneObject

PersonalData



22
23
24
# File 'lib/blueline_services/request.rb', line 22

def telephone
  @telephone
end

#typeObject

BackgroundSearchPackage



16
17
18
# File 'lib/blueline_services/request.rb', line 16

def type
  @type
end

#use_defaultsObject

Returns the value of attribute use_defaults.



47
48
49
# File 'lib/blueline_services/request.rb', line 47

def use_defaults
  @use_defaults
end

#user_nameObject

BackgroundCheck



10
11
12
# File 'lib/blueline_services/request.rb', line 10

def user_name
  @user_name
end

Instance Method Details

#additional_itemsObject



62
63
64
65
66
67
68
# File 'lib/blueline_services/request.rb', line 62

def additional_items
  ADDITIONAL_ITEMS.inject({}) do |h,a|
    v = send(a)
    h[a] = send(a) unless v.nil?
    h
  end
end

#as_xmlObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/blueline_services/request.rb', line 85

def as_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.BackgroundCheck(:userId => user_name, :password => password) {
      xml.BackgroundSearchPackage(:type => type, :action => action) {
        xml.ReferenceId reference_id
        xml.Reference reference
        xml.PersonalData {
          xml.EmailAddress email_address
          xml.Telephone telephone
          xml.parent << name.as_xml
          if aliases.any?
            xml.Aliases {
              aliases.each do |a|
                xml.parent << a.as_xml
              end
            }
          end
          xml.DemographicDetail {
            xml.GovernmentId(government_id,
                  :countryCode => ssn_country_code,
                  :issuingAuthority => issuing_authority)
            xml.DateOfBirth date_of_birth
          } # DemographicDetail
          xml.PostalAddress {
            xml.CountryCode country_code == "Canada" ? "CA" : "US"
            xml.PostalCode postal_code
            xml.Region region
            xml.Municipality municipality
            xml.DeliveryAddress {
              xml.AddressLine address_line
              xml.StreetName street_name
            } # DeliveryAddress
          } # PostalAddress
        } # PersonalData
        xml.Screenings(:useConfigurationDefaults => yes_or_no(use_defaults)) {
          screenings.each do |s|
            xml.parent << s.as_xml
          end
          additional_items.each do |k,v|
            xml.AdditionalItems(:type => "x:#{k}") {
              xml.Text v
            }
          end
        } # Screenings
      } # BackgroundSearchPackage
    } # BackgroundCheck
  end
end

#build_requestObject



145
146
147
# File 'lib/blueline_services/request.rb', line 145

def build_request
  HTTParty::Request.new(Net::HTTP::Post, base_uri, request_options)
end

#nameObject



76
77
78
79
80
81
82
83
# File 'lib/blueline_services/request.rb', line 76

def name
  person_name do |p|
    p.given_name = given_name
    p.middle_name = middle_name
    p.family_name = family_name
    p.affix = affix
  end
end

#postback_passwordObject



179
180
181
# File 'lib/blueline_services/request.rb', line 179

def postback_password
  @postback_password || config.postback_password
end

#postback_urlObject



171
172
173
# File 'lib/blueline_services/request.rb', line 171

def postback_url
  @postback_url || config.postback_url
end

#postback_usernameObject



175
176
177
# File 'lib/blueline_services/request.rb', line 175

def postback_username
  @postback_username || config.postback_username
end

#request_optionsObject



138
139
140
141
142
143
# File 'lib/blueline_services/request.rb', line 138

def request_options
  {
    body: { request: to_xml },
    basic_auth: { username: user_name, password: password }
  }
end

#ssn=(new_ssn) ⇒ Object



70
71
72
73
74
# File 'lib/blueline_services/request.rb', line 70

def ssn=(new_ssn)
  @government_id = new_ssn
  @ssn_country_code = "US"
  @issuing_authority = "SSN"
end

#submitObject



149
150
151
152
153
# File 'lib/blueline_services/request.rb', line 149

def submit
  response = build_request.perform
  data = response.parsed_response
  BluelineServices::Response.new(data)
end

#to_xmlObject



134
135
136
# File 'lib/blueline_services/request.rb', line 134

def to_xml
  as_xml.to_xml
end