Ruby library to access the Spreedly API (all of it).
There are a few of these knocking about, but I couldn’t find one particular to my needs:
* Well covered with specs - currently 100% coverage * Covers the entire API, not just parts of it * Rubyish/ActiveRecord style access
It’s on Gemcutter, so as long as you’re setup to use that:
gem install rspreedly
Otherwise
gem install gemcutter gem tumble gem install rspreedly
Configure your API key and site name for your account:
RSpreedly::Config.setup do |config| config.api_key = "your-api-key" config.site_name = "your-site-name" end
List subscribers
RSpreedly::Subscriber.find(:all).each do |subscriber| # do something end
CRUD access to subscribers
sub = RSpreedly::Subscriber.new(:customer_id => 42, :email => "[email protected]") sub.token => nil sub.save sub.token => "6af9994a57e420345897b1abb4c27a9db27fa4d0" sub = RSpreedly::Subscriber.find(42) sub.email = "[email protected]" sub.save sub = RSpreedly::Subscriber.find(69) sub.destroy
Comp subscriptions
comp = RSpreedly::ComplimentarySubscription.new(:duration_quantity => 3, :duration_units => "months", :feature_level => "Pro") sub = RSpreedly::Subscriber.find(69) sub.comp_subscription(comp)
View all plans
plans = RSpreedly::SubscriptionPlan.find(:all)
Raise an invoice, and pay it
invoice = RSpreedly::Invoice.new(:subscription_plan_id => 5, :subscriber => sub) invoice.save payment = RSpreedly::PaymentMethod::CreditCard.new(:card_type => 'visa', :number => '123456', ...) invoice.pay(payment)
Error messages
invoice = RSpreedly::Invoice.new invoice.save => false invoice.errors => ["You must specify both the subscription plan id and subscriber information."]
See the specs and API docs at Spreedly for more details and the rest of the things it can do.
www.spreedly.com/manual/integration-reference/url-reference/
* Better specs for data we send to Spreedly. * Better docs.
I studied the other Spreedly APIs and there may well be a line or three this library has in common with:
* http://github.com/terralien/spreedly-gem * http://github.com/erbmicha/spreedly/
Copyright © 2009 Richard Livsey. See LICENSE for details.