Module: Spreedly
- Includes:
- HTTParty
- Defined in:
- lib/spreedly.rb,
lib/spreedly/mock.rb,
lib/spreedly/common.rb,
lib/spreedly/version.rb,
lib/spreedly/test_hacks.rb
Overview
Provides a convenient wrapper around the spreedly.com API. Instead of mucking around with http you can just Spreedly.configure and Spreedly::Subscriber.find. Much of the functionality is hung off of the Spreedly::Subscriber class, and there’s also a Spreedly::SubscriptionPlan class.
One of the goals of this wrapper is to keep your tests fast while also keeping your app working. It does this by providing a drop-in replacement for the real Spreedly functionality that skips the network and gives you a simple (some might call it stupid) implementation that will work for 90% of your tests. At least we hope so.
Help us make the mock work better by telling us when it doesn’t work so we can improve it. Thanks!
Example mock usage:
if ENV["SPREEDLY"] == "REAL"
require 'spreedly'
else
require 'spreedly/mock'
end
Defined Under Namespace
Classes: Resource, Subscriber, SubscriptionPlan
Constant Summary collapse
- REAL =
:nodoc:
"real"
- MOCK =
"mock"
- VERSION =
"1.3.1"
Class Method Summary collapse
-
.configure(name, token) ⇒ Object
Call this before you start using the API to set things up.
-
.edit_subscriber_url(token) ⇒ Object
Generates an edit subscriber for the given subscriber token.
-
.site_name ⇒ Object
:nodoc:.
-
.subscribe_url(id, plan, screen_name = nil) ⇒ Object
Generates a subscribe url for the given user id and plan.
-
.to_xml_params(hash) ⇒ Object
:nodoc:.
Class Method Details
.configure(name, token) ⇒ Object
Call this before you start using the API to set things up.
41 42 43 44 45 |
# File 'lib/spreedly.rb', line 41 def self.configure(site_name, token) base_uri "https://spreedly.com/api/v4/#{site_name}" basic_auth token, 'X' @site_name = site_name end |
.edit_subscriber_url(token) ⇒ Object
Generates an edit subscriber for the given subscriber token. The token is returned with the subscriber info (i.e. by Subscriber.find).
21 22 23 |
# File 'lib/spreedly/common.rb', line 21 def self.edit_subscriber_url(token) "https://spreedly.com/#{site_name}/subscriber_accounts/#{token}" end |
.site_name ⇒ Object
:nodoc:
47 48 49 |
# File 'lib/spreedly.rb', line 47 def self.site_name # :nodoc: @site_name end |
.subscribe_url(id, plan, screen_name = nil) ⇒ Object
Generates a subscribe url for the given user id and plan.
13 14 15 16 |
# File 'lib/spreedly/common.rb', line 13 def self.subscribe_url(id, plan, screen_name=nil) screen_name = (screen_name ? URI.escape(screen_name) : "") "https://spreedly.com/#{site_name}/subscribers/#{id}/subscribe/#{plan}/#{screen_name}" end |
.to_xml_params(hash) ⇒ Object
:nodoc:
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/spreedly.rb', line 51 def self.to_xml_params(hash) # :nodoc: hash.collect do |key, value| tag = key.to_s.tr('_', '-') result = "<#{tag}>" if value.is_a?(Hash) result << to_xml_params(value) else result << value.to_s end result << "</#{tag}>" result end.join('') end |