Created
November 6, 2012 05:54
-
-
Save kfrancis/4022858 to your computer and use it in GitHub Desktop.
Get List of Subscription's with Coupons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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