Skip to content

Instantly share code, notes, and snippets.

@tedtieken
Forked from rdetert/shopify_api.conf
Created May 31, 2016 19:54
Show Gist options
  • Select an option

  • Save tedtieken/bbaa451b5d61b515d2e274b473d69e3e to your computer and use it in GitHub Desktop.

Select an option

Save tedtieken/bbaa451b5d61b515d2e274b473d69e3e 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment