Skip to content

Instantly share code, notes, and snippets.

@rdetert
Last active May 31, 2017 20:12
Show Gist options
  • Select an option

  • Save rdetert/8111350 to your computer and use it in GitHub Desktop.

Select an option

Save rdetert/8111350 to your computer and use it in GitHub Desktop.

Revisions

  1. rdetert revised this gist Dec 24, 2013. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions sync_shopify.rb
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ class Subscriber < ActiveRecord::Base
    end



    SENDY_LIST_ID = 11 # Change This!

    ShopifyAPI::Customer.all( from: :search, params: {q: "accepts_marketing:true", limit:250}).each do |customer|

    @@ -35,11 +35,10 @@ class Subscriber < ActiveRecord::Base
    :email => customer.email,
    :userID => 1,
    :custom_fields => "",
    :list => 11,
    :list => SENDY_LIST_ID,
    :join_date => DateTime.parse(customer.created_at),
    :timestamp => DateTime.parse(customer.created_at)

    subscriber.save

    end

    end
  2. rdetert created this gist Dec 24, 2013.
    3 changes: 3 additions & 0 deletions shopify_api.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    SHOPIFY_API_KEY = 'my-key'
    SHOPIFY_PASSWORD = 'my-pass'
    STORE_NAME = 'my-store'
    45 changes: 45 additions & 0 deletions sync_shopify.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # 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




    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 => 11,
    :join_date => DateTime.parse(customer.created_at),
    :timestamp => DateTime.parse(customer.created_at)

    subscriber.save

    end

    5 changes: 5 additions & 0 deletions sync_shopify.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    adapter: mysql
    host: localhost
    username: user
    password: pass
    database: database_name