Class: Visitor

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email


3
4
5
# File 'app/models/visitor.rb', line 3

def email
  @email
end

#stringObject

Returns the value of attribute string


3
4
5
# File 'app/models/visitor.rb', line 3

def string
  @string
end

Instance Method Details

#subscribeObject


7
8
9
10
11
12
13
14
15
16
# File 'app/models/visitor.rb', line 7

def subscribe
  mailchimp = Gibbon::Request.new(api_key: Rails.application.secrets.mailchimp_api_key)
  list_id = Rails.application.secrets.mailchimp_list_id
  result = mailchimp.lists(list_id).members.create(
    body: {
      email_address: self.email,
      status: 'subscribed'
  })
  Rails.logger.info("Subscribed #{self.email} to MailChimp") if result
end