Class: Workarea::Emarsys::Contact

Inherits:
Object
  • Object
show all
Defined in:
app/services/emarsys/contact.rb,
app/services/emarsys/contact/user.rb,
app/services/emarsys/contact/order.rb

Defined Under Namespace

Classes: Order, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ Contact

Returns a new instance of Contact.



6
7
8
9
# File 'app/services/emarsys/contact.rb', line 6

def initialize(model, options = {})
  @model = model
  @options = options
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'app/services/emarsys/contact.rb', line 4

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'app/services/emarsys/contact.rb', line 4

def options
  @options
end

Instance Method Details

#to_hObject

Returns Hash.

Returns:

  • Hash



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/emarsys/contact.rb', line 12

def to_h
  user_data = {
    "1" => contact_model.first_name,
    "2" => contact_model.last_name,
    "3" => contact_model.email
  }

  if address.present?
    address_data = {
      "10" => address.street,
      "11" => address.city,
      "12" => address.region,
      "13" => address.postal_code,
      "14" => ::Emarsys::Country.new.find_code(address.country.to_s),
      "15" => address.phone_number
    }

    user_data.merge!(address_data)
  end

  user_data
end