Skip to content

Instantly share code, notes, and snippets.

@kfrancis
Created November 6, 2012 05:54
Show Gist options
  • Save kfrancis/4022858 to your computer and use it in GitHub Desktop.
Save kfrancis/4022858 to your computer and use it in GitHub Desktop.
Get List of Subscription's with Coupons
require 'rubygems'
require 'chargify_api_ares'
require 'csv'
Chargify.configure do |c|
c.subdomain = ''
c.api_key = ''
end
CSV.open('subscription_coupons.csv', 'wb') do |csv|
csv << ['SubscriptionID', 'ProductID', 'CouponCode']
page = 1
while (ss = Chargify::Subscription.find(:all, :params => {:page => page, :per_page => 100})).size > 0 do
puts "Page #{page}"
ss.each do |t|
if s.coupon_code?
csv << [s.subscription_id, s.product.id, s.coupon_code]
end
end
page += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment