Class: DelayedSubscriberAdd

Inherits:
Struct
  • Object
show all
Defined in:
lib/delayed_subscriber_add.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#listObject

Returns the value of attribute list

Returns:

  • (Object)

    the current value of list



2
3
4
# File 'lib/delayed_subscriber_add.rb', line 2

def list
  @list
end

#opsObject

Returns the value of attribute ops

Returns:

  • (Object)

    the current value of ops



2
3
4
# File 'lib/delayed_subscriber_add.rb', line 2

def ops
  @ops
end

#store_codeObject

Returns the value of attribute store_code

Returns:

  • (Object)

    the current value of store_code



2
3
4
# File 'lib/delayed_subscriber_add.rb', line 2

def store_code
  @store_code
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



2
3
4
# File 'lib/delayed_subscriber_add.rb', line 2

def user
  @user
end

Instance Method Details

#performObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/delayed_subscriber_add.rb', line 3

def perform

  if list.nil? || !user
    subscriber_id = -1
  else
    begin
      token= Spree::BrontoConfiguration.[store_code]['token']
      if user.is_a? String
        email=user
      else
        email=user.email
      end

      contact = BrontoIntegration::Contact.new(token)
      contacts=contact.set_up(email,ops||{})
      subscriber_id= contacts[:id]

      communication = BrontoIntegration::Communication.new(token)
      communication.add_to_list(list.title,email)

    rescue => exception
        subscriber_id = -1
        #raise exception
    end
  end

  unless user.is_a? String
    begin
    user.bronto_lists << list
    user.save!
    rescue
    end
  end

end