Skip to content

Instantly share code, notes, and snippets.

@zedalaye
Last active Jun 5, 2017
Embed
What would you like to do?
Test Mailjet Resource#save from Mailjet-Gem
source 'https://rubygems.org'
ruby '2.4.1'
gem 'mail'
gem 'mailjet', git: 'https://github.com/mailjet/mailjet-gem.git', branch: 'prerelease/v1.5.2'
gem 'activesupport', :require => 'active_support/all'
require 'bundler/setup'
Bundler.require
Mailjet.configure do |config|
config.api_key = 'my_api_key'
config.secret_key = 'my_secret_key'
end
RestClient.log = Logger.new(STDOUT)
l = Mailjet::Contactslist.first(name: 'Newsletter')
l = Mailjet::Contactslist.create(name: 'Newsletter') if l.nil?
c = Mailjet::Contact.find('pierre.y+test@gmail.com')
c = Mailjet::Contact.create(email: 'pierre.y+test@gmail.com') if c.nil?
lr = Mailjet::Listrecipient.first(:contacts_list => l.id, :contact => c.id)
lr = Mailjet::Listrecipient.create('ListID' => l.id, 'ContactID' => c.id, is_active: true) if lr.nil?
if lr.is_unsubscribed
puts "Unsubscribed : Subscribe !"
lr.is_active = true
lr.is_unsubscribed = false
else
puts "Subscribed : Unsubscribe !"
lr.is_active = false
lr.is_unsubscribed = true
end
lr.save!
require 'bundler/setup'
Bundler.require
Mailjet.configure do |config|
config.api_key = 'my_api_key'
config.secret_key = 'my_secret_key'
end
RestClient.log = Logger.new(STDOUT)
l = Mailjet::Contactslist.first(name: 'Newsletter')
l = Mailjet::Contactslist.create(name: 'Newsletter') if l.nil?
c = Mailjet::Contact.find('pierre.y+test@gmail.com')
c = Mailjet::Contact.create(email: 'pierre.y+test@gmail.com') if c.nil?
lr = Mailjet::Listrecipient.first(:contacts_list => l.id, :contact => c.id)
lr = Mailjet::Listrecipient.create('ListID' => l.id, 'ContactID' => c.id, is_active: true) if lr.nil?
if lr.is_unsubscribed
puts "Unsubscribed : Subscribe !"
else
puts "Subscribed : Unsubscribe !"
end
lr.update_attributes(is_unsubscribed: !lr.is_unsubscribed, is_active: !lr.is_active)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment