Skip to content

Instantly share code, notes, and snippets.

@rdetert
Last active May 31, 2017 20:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rdetert/8111350 to your computer and use it in GitHub Desktop.
Save rdetert/8111350 to your computer and use it in GitHub Desktop.
Sync Shopify Customers who Accept Marketing with Sendy Using ActiveRecord 4
SHOPIFY_API_KEY = 'my-key'
SHOPIFY_PASSWORD = 'my-pass'
STORE_NAME = 'my-store'
# 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
adapter: mysql
host: localhost
username: user
password: pass
database: database_name
@athein
Copy link

athein commented May 31, 2017

Where do these files go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment