Last active
May 31, 2017 20:12
-
-
Save rdetert/8111350 to your computer and use it in GitHub Desktop.
Sync Shopify Customers who Accept Marketing with Sendy Using ActiveRecord 4
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
SHOPIFY_API_KEY = 'my-key' | |
SHOPIFY_PASSWORD = 'my-pass' | |
STORE_NAME = 'my-store' |
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
# Sync Shopify Customers that Accept Marketing with Sendy | |
require 'rubygems' | |
require 'active_record' | |
require 'protected_attributes' | |
require 'shopify_api' | |
require 'yaml' | |
dbconfig = YAML::load(File.open('sync_shopify.yml')) | |
ActiveRecord::Base.establish_connection(dbconfig) | |
eval File.open('shopify_api.conf').read | |
shop_url = "https://#{SHOPIFY_API_KEY}:#{SHOPIFY_PASSWORD}@#{STORE_NAME}.myshopify.com/admin" | |
ShopifyAPI::Base.site = shop_url | |
class Subscriber < ActiveRecord::Base | |
attr_accessible :name, :email, :join_date, :timestamp, :list, :last_campaign, :userID, :custom_fields | |
validates_uniqueness_of :email | |
end | |
SENDY_LIST_ID = 11 # Change This! | |
ShopifyAPI::Customer.all( from: :search, params: {q: "accepts_marketing:true", limit:250}).each do |customer| | |
name = "#{customer.first_name} #{customer.last_name}" | |
subscriber = Subscriber.new :name => name, :email => customer.email, :join_date => customer.created_at, :timestamp => customer.created_at | |
email_with_name = "#{name} <#{customer.email}>" | |
subscriber = Subscriber.new :name => name, | |
:email => customer.email, | |
:userID => 1, | |
:custom_fields => "", | |
:list => SENDY_LIST_ID, | |
:join_date => DateTime.parse(customer.created_at), | |
:timestamp => DateTime.parse(customer.created_at) | |
subscriber.save | |
end |
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
adapter: mysql | |
host: localhost | |
username: user | |
password: pass | |
database: database_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where do these files go?