Skip to content

Instantly share code, notes, and snippets.

@resistorsoftware
Created July 17, 2010 15:38
Show Gist options
  • Save resistorsoftware/479584 to your computer and use it in GitHub Desktop.
Save resistorsoftware/479584 to your computer and use it in GitHub Desktop.
Discount Coupons
require 'rubygems'
require 'mechanize'
BASE = 'http://manure.myshopify.com/admin'
LOGIN = '/auth/login'
USER = '[email protected]'
PWD = 'moo-moo'
agent = Mechanize.new
page = agent.get(BASE+LOGIN)
form = page.forms.first
form.login = USER
form.password = PWD
agent.submit(page.forms.first)
codes = %w(COW-0 COW-1 COW-2 COW-3 COW-4 COW-5) # make a million codes if you dare
page = agent.get(BASE+'/marketing')
form = page.forms.each {|e| e['id'] == 'new-code-form'}
form = page.forms.first
codes.each do |code|
form["discount[code]"] = code
form["discount[value]"] = '1'
form["discount[starts_at]"] = Date.today.strftime('%F')
form["discount[ends_at]"] = Date.today.+(10).strftime('%F')
form["discount[minimum_order_amount]"] = '0.0'
form["discount[usage_limit]"] = '1'
form["type"] = 'percentage'
form["commit"] = 'Create Discount'
r = agent.submit(page.forms.first)
pp r
end
@rapind
Copy link

rapind commented Sep 27, 2011

Thanks for this.

@resistorsoftware
Copy link
Author

resistorsoftware commented Sep 27, 2011 via email

@rapind
Copy link

rapind commented Sep 27, 2011

Seems like a good starting point, and that's enough for me.

@rapind
Copy link

rapind commented Oct 3, 2011

By the way, here's a working script to load in a bunch of groupon codes.
https://gist.github.com/1246051

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