Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby library for the Spreedly API

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rspreedly.gemspec
README.rdoc

RSpreedly

Ruby library to access the Spreedly API (all of it).

Why another one?

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

Installation

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

Usage

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 => "somewhere@example.com")
sub.token => nil
sub.save 
sub.token => "6af9994a57e420345897b1abb4c27a9db27fa4d0"

sub = RSpreedly::Subscriber.find(42)
sub.email = "new-email@example.com"
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/

Todo

* Better specs for data we send to Spreedly.
* Better docs.

Thanks

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

Copyright © 2009 Richard Livsey. See LICENSE for details.

Something went wrong with that request. Please try again.