Last active
June 5, 2017 13:25
-
-
Save zedalaye/3307cca6a94de28f180570fccd55533f to your computer and use it in GitHub Desktop.
Test Mailjet Resource#save from Mailjet-Gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('[email protected]') | |
c = Mailjet::Contact.create(email: '[email protected]') 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('[email protected]') | |
c = Mailjet::Contact.create(email: '[email protected]') 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