Class: RepsClient::Contact

Inherits:
Modelish::Base
  • Object
show all
Defined in:
lib/reps_client/lead.rb

Overview

The person who is the primary contact for a lead.

Minimally, a Contact is required to have a first name, last name, and some means of contacting them (email, phone, or mailing address). All other attributes are optional.

Examples:

Creating a valid contact with an email address

contact = RepsClient::Contact.new(:first_name => 'Alice',
                                  :last_name => 'Aardvark',
                                  :email => '[email protected]')

Creating a valid contact with a phone number

contact = RepsClient::Contact.new(:first_name => 'Bob',
                                  :last_name => 'Builder',
                                  :phone => '5551234567')

Creating a valid contact with a mailing address

contact = RepsClient::Contact.new(:first_name => 'Charleston',
                                  :last_name => 'Chew',
                                  :address1 => '123 Gumdrop Ct',
                                  :city => 'Candyland',
                                  :state => 'CA',
                                  :zip_code => '12345')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#address1String

Note:

This attribute is only required when there is no phone or email.

Returns the first line of the contact’s street address.

Returns:

  • (String)

    the first line of the contact’s street address



56
# File 'lib/reps_client/lead.rb', line 56

property :address1, :type => String, :max_length => 100

#address2String

Returns the second line of the contact’s street address.

Returns:

  • (String)

    the second line of the contact’s street address



60
# File 'lib/reps_client/lead.rb', line 60

property :address2, :type => String, :max_length => 100

#cityString

Returns the city for the contact’s mailing address.

Returns:

  • (String)

    the city for the contact’s mailing address



64
# File 'lib/reps_client/lead.rb', line 64

property :city, :type => String, :max_length => 50

#countryString

Returns the country from the contact’s mailing address.

Returns:

  • (String)

    the country from the contact’s mailing address



76
# File 'lib/reps_client/lead.rb', line 76

property :country, :type => String

#emailString

Returns the contact’s email address.

Returns:

  • (String)

    the contact’s email address



88
# File 'lib/reps_client/lead.rb', line 88

property :email, :type => String, :max_length => 100

#first_nameString

Note:

This attribute is required on initialization.

Returns the contact’s first name.

Returns:

  • (String)

    the contact’s first name



36
# File 'lib/reps_client/lead.rb', line 36

property :first_name, :type => String, :required => true, :max_length => 30

#include_in_emailingstrue, false

Returns contact opted in to mailings (defaults to false).

Returns:

  • (true, false)

    contact opted in to mailings (defaults to false)



109
# File 'lib/reps_client/lead.rb', line 109

property :include_in_emailings, :default => false, :type => lambda { |v| !!v }

#include_in_mailingstrue, false

Returns contact opted in to mailings (defaults to false).

Returns:

  • (true, false)

    contact opted in to mailings (defaults to false)



105
# File 'lib/reps_client/lead.rb', line 105

property :include_in_mailings, :default => false, :type => lambda { |v| !!v }

#last_nameString

Note:

This attribute is required on initialization.

Returns the contact’s last name.

Returns:

  • (String)

    the contact’s last name



45
# File 'lib/reps_client/lead.rb', line 45

property :last_name, :type => String, :required => true, :max_length => 30

#middle_nameString

Returns the contact’s middle name or initial.

Returns:

  • (String)

    the contact’s middle name or initial



40
# File 'lib/reps_client/lead.rb', line 40

property :middle_name, :type => String, :max_length => 30

#phoneString

Returns the contact’s phone number.

Returns:

  • (String)

    the contact’s phone number



80
# File 'lib/reps_client/lead.rb', line 80

property :phone, :type => String, :max_length => 20

#phone_extensionString

Returns the contact’s phone number extension.

Returns:

  • (String)

    the contact’s phone number extension



84
# File 'lib/reps_client/lead.rb', line 84

property :phone_extension, :type => String, :max_length => 5

#prefixString

Returns the contact’s salutation (e.g. “Mr.”, “Ms.”, “Dr.”, etc.).

Returns:

  • (String)

    the contact’s salutation (e.g. “Mr.”, “Ms.”, “Dr.”, etc.)

See Also:



31
# File 'lib/reps_client/lead.rb', line 31

property :prefix, :type => String, :max_length => 30

#relationship_to_prospect_idint

Note:

REPS requires the “direction” of the relationship type to be the opposite of what most users expect.

The relationship type is determined based on the contact’s answer to the question “What is your relationship to the prospect?” For instance, if a contact was acting on behalf of their mother, the relationship type name might be “Child” or “Son” or “Daughter” (but definitely not “Mother” or “Parent”). Valid relationship types are available from the remote service.

Returns:

  • (int)

    the relationship type id describing the relationship of the contact to the prospect

See Also:



101
# File 'lib/reps_client/lead.rb', line 101

property :relationship_to_prospect_id, :type => Integer

#source_idint

Note:

This attribute is required on initialization.

Returns the identifier for the lead source in REPS.

Returns:

  • (int)

    the identifier for the lead source in REPS

See Also:



115
# File 'lib/reps_client/lead.rb', line 115

property :source_id, :type => Integer, :required => true, :validate_type => true

#stateString

Returns the state code for the contact’s mailing address.

Returns:

  • (String)

    the state code for the contact’s mailing address



68
# File 'lib/reps_client/lead.rb', line 68

property :state, :type => String, :max_length => 2

#suffixString

Returns the contact’s name suffix (e.g. ‘Jr.’, ‘M.D.’, etc.).

Returns:

  • (String)

    the contact’s name suffix (e.g. ‘Jr.’, ‘M.D.’, etc.)

See Also:



51
# File 'lib/reps_client/lead.rb', line 51

property :suffix, :type => String, :max_length => 30

#zip_codeString

Returns the zip code for the contact’s mailing address.

Returns:

  • (String)

    the zip code for the contact’s mailing address



72
# File 'lib/reps_client/lead.rb', line 72

property :zip_code, :type => String, :max_length => 10

Instance Method Details

#has_contact_method?true, false

Checks that at least one contact method has been supplied. Possible contact methods include email, phone, and mailing address.

Returns:

  • (true, false)

    true if there is at least one contact method; false otherwise



139
140
141
# File 'lib/reps_client/lead.rb', line 139

def has_contact_method?
  !(phone.blank? && email.blank? && (address1.blank? || city.blank? || state.blank? || zip_code.blank?))
end

#to_soap_hashObject

Wrangle the model into a format that the service will accept



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/reps_client/lead.rb', line 145

def to_soap_hash
  hash = {:order! => []}

  [:prefix, :first_name, :middle_name, :last_name, :suffix,
   :address1, :address2, :city, :state, :zip_code, :country,
   :phone, :phone_extension, :email, :relationship_to_prospect_id,
   :include_in_mailings, :include_in_emailings, :source_id].each do |prop|
    val = self.send(prop)

    unless val.nil?
      key = prop == :source_id ? 'SourceIDY' : prop.to_s.camelcase
      hash[key] = val
      hash[:order!] << key
    end
  end

  hash
end

#validateObject

Validates attributes (including contact method), returning errors.



119
120
121
122
123
124
125
126
# File 'lib/reps_client/lead.rb', line 119

def validate
  errors = super
  [:phone, :email, :address1, :city, :state, :zip_code].each do |k|
    errors[k] ||= []
    errors[k] << contact_method_error
  end unless has_contact_method?
  errors
end

#validate!Object

Validates attributes (including contact method), raising errors.



130
131
132
133
# File 'lib/reps_client/lead.rb', line 130

def validate!
  super
  raise contact_method_error unless has_contact_method?
end