class Centaman::Service::CreateCustomer

Attributes

address[RW]
attendees[RW]
email[RW]
first_name[RW]
last_name[RW]
phone[RW]

Public Instance Methods

after_init(args) click to toggle source
# File lib/centaman/service/create_customer.rb, line 7
def after_init(args)
  @first_name = args.fetch(:first_name, nil)
  @last_name = args.fetch(:last_name, nil)
  @email = args.fetch(:email, nil)
  @phone = args.fetch(:phone, nil)
  @address = args.fetch(:address, nil) || {}
  @attendees = args.fetch(:attendees, nil) || []
end
build_address() click to toggle source
# File lib/centaman/service/create_customer.rb, line 24
def build_address
  {
    'Street1' => address[:street_address1] || '',
    'Street2' => address[:street_address2] || '',
    'City' => address[:city] || '',
    'State' => address[:state] || '',
    'Postalcode' => address[:zip] || '',
    'Country' => address[:country] || '',
    'HomePhone' => phone || '',
    'WorkPhone' => '',
    'MobilePhone' => ''
  }
end
build_booking_attendees() click to toggle source
# File lib/centaman/service/create_customer.rb, line 38
def build_booking_attendees
  attendees.map do |attendee|
    udfs = attendee.try(:attendee_udfs)
    attendee_email = udfs && udfs.detect { |u| u.try(:is_email) && u.try(:value).present? }.try(:value)
    {
      'FirstName': attendee.first_name,
      'LastName': attendee.last_name,
      'Email': attendee.email.present? ? attendee.email : (attendee_email || random_email(attendee))
    }
  end
end
endpoint() click to toggle source
# File lib/centaman/service/create_customer.rb, line 16
def endpoint
  '/ticket_services/TimedTicket'
end
object_class() click to toggle source
# File lib/centaman/service/create_customer.rb, line 20
def object_class
  Centaman::Object::Customer
end
options_hash() click to toggle source
# File lib/centaman/service/create_customer.rb, line 58
def options_hash
  {
    'FirstName' => first_name || '',
    'LastName' => last_name || '',
    'Email' => email,
    'Address' => build_address,
    'BookingAttendee': build_booking_attendees
  }.compact.to_json
end
random_email(attendee) click to toggle source
# File lib/centaman/service/create_customer.rb, line 50
def random_email(attendee)
  # force creation of new member by setting new email
  [attendee.first_name.try(:squish), attendee.last_name.try(:squish), SecureRandom.hex(2)]
    .reject { |obj| obj.blank? }
    .join('.') + '@example.com'
    .squish
end