Class: Centaman::Service::CreateCustomer
- Inherits:
-
Centaman::Service
- Object
- Wrapper
- Centaman::Service
- Centaman::Service::CreateCustomer
- Includes:
- JsonWrapper
- Defined in:
- lib/centaman/service/create_customer.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary
Constants inherited from Wrapper
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#attendees ⇒ Object
Returns the value of attribute attendees.
-
#email ⇒ Object
Returns the value of attribute email.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#phone ⇒ Object
Returns the value of attribute phone.
Attributes inherited from Wrapper
#api_password, #api_token, #api_url, #api_username, #proxie_host, #proxie_password, #proxie_port, #proxie_user
Instance Method Summary collapse
- #after_init(args) ⇒ Object
- #build_address ⇒ Object
- #build_booking_attendees ⇒ Object
- #endpoint ⇒ Object
- #object_class ⇒ Object
- #options_hash ⇒ Object
- #random_email(attendee) ⇒ Object
Methods included from JsonWrapper
#additional_hash_to_serialize_after_response, #build_object, #build_objects, #final_object_class, #objects
Methods inherited from Centaman::Service
#after_post, #fetch_all, #post, #put
Methods inherited from Wrapper
#generate_token, #headers, #initialize, #options, #payload, #payload_key, #proxy_hash, #wrap_request_in_case_of_timeout
Constructor Details
This class inherits a constructor from Centaman::Wrapper
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/centaman/service/create_customer.rb', line 5 def address @address end |
#attendees ⇒ Object
Returns the value of attribute attendees.
5 6 7 |
# File 'lib/centaman/service/create_customer.rb', line 5 def attendees @attendees end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/centaman/service/create_customer.rb', line 5 def email @email end |
#first_name ⇒ Object
Returns the value of attribute first_name.
5 6 7 |
# File 'lib/centaman/service/create_customer.rb', line 5 def first_name @first_name end |
#last_name ⇒ Object
Returns the value of attribute last_name.
5 6 7 |
# File 'lib/centaman/service/create_customer.rb', line 5 def last_name @last_name end |
#phone ⇒ Object
Returns the value of attribute phone.
5 6 7 |
# File 'lib/centaman/service/create_customer.rb', line 5 def phone @phone end |
Instance Method Details
#after_init(args) ⇒ Object
7 8 9 10 11 12 13 14 |
# 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 ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/centaman/service/create_customer.rb', line 16 def endpoint '/ticket_services/TimedTicket' end |
#object_class ⇒ Object
20 21 22 |
# File 'lib/centaman/service/create_customer.rb', line 20 def object_class Centaman::Object::Customer end |
#options_hash ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/centaman/service/create_customer.rb', line 58 def { 'FirstName' => first_name || '', 'LastName' => last_name || '', 'Email' => email, 'Address' => build_address, 'BookingAttendee': build_booking_attendees }.compact.to_json end |
#random_email(attendee) ⇒ Object
50 51 52 53 54 55 56 |
# 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 |