Class: Lightrail::Contact

Inherits:
LightrailObject show all
Defined in:
lib/lightrail_client/contact.rb

Class Method Summary collapse

Methods inherited from LightrailObject

#initialize

Constructor Details

This class inherits a constructor from Lightrail::LightrailObject

Class Method Details

.create(create_params) ⇒ Object



4
5
6
7
8
9
# File 'lib/lightrail_client/contact.rb', line 4

def self.create(create_params)
  params_with_user_supplied_id = self.set_user_supplied_id_for_contact_create(create_params)
  params_with_name_if_present = self.set_name_if_present(params_with_user_supplied_id)
  response = Lightrail::Connection.send :make_post_request_and_parse_response, "contacts", params_with_name_if_present
  response['contact']
end

.get_contact_id_from_id_or_shopper_id(charge_params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lightrail_client/contact.rb', line 31

def self.get_contact_id_from_id_or_shopper_id(charge_params)
  if Lightrail::Validator.has_valid_contact_id?(charge_params)
    return Lightrail::Validator.get_contact_id(charge_params)
  end

  if Lightrail::Validator.has_valid_shopper_id?(charge_params)
    shopper_id = Lightrail::Validator.get_shopper_id(charge_params)
    contact = self.get_by_shopper_id(shopper_id)
    if (!contact.nil? && !contact.empty? && contact['contactId'])
      return contact['contactId']
    else
      return nil
    end
  end

  return nil
end

.retrieve_by_contact_id(contact_id) ⇒ Object



16
17
18
19
# File 'lib/lightrail_client/contact.rb', line 16

def self.retrieve_by_contact_id(contact_id)
  response = Lightrail::Connection.send :make_get_request_and_parse_response, "contacts/#{CGI::escape(contact_id)}"
  response['contact']
end

.retrieve_by_shopper_id(shopper_id) ⇒ Object



11
12
13
14
# File 'lib/lightrail_client/contact.rb', line 11

def self.retrieve_by_shopper_id(shopper_id)
  response = Lightrail::Connection.send :make_get_request_and_parse_response, "contacts?userSuppliedId=#{CGI::escape(shopper_id)}"
  response['contacts'][0]
end

.retrieve_or_create_by_shopper_id(shopper_id) ⇒ Object

Utility methods



23
24
25
26
27
28
29
# File 'lib/lightrail_client/contact.rb', line 23

def self.retrieve_or_create_by_shopper_id(shopper_id)
  contact = self.retrieve_by_shopper_id(shopper_id)
  if !contact
    contact = self.create({shopper_id: shopper_id})
  end
  contact
end