In Files

Files

Class Index [+]

Quicksearch

Spreedly::Subscriber

Public Class Methods

all() click to toggle source

Returns all the subscribers in your site.

     # File lib/spreedly.rb, line 135
135:     def self.all
136:       Spreedly.get('/subscribers.xml')['subscribers'].collect{|data| new(data)}
137:     end
create!(id, *args) click to toggle source

Creates a new subscriber on Spreedly. The subscriber will NOT be active - they have to pay or you have to comp them for that to happen.

Usage:

  Spreedly.Subscriber.create!(id, email)
  Spreedly.Subscriber.create!(id, email, screen_name)
  Spreedly.Subscriber.create!(id, :email => email, :screen_name => screen_name)
  Spreedly.Subscriber.create!(id, email, screen_name, :billing_first_name => first_name)
     # File lib/spreedly.rb, line 110
110:     def self.create!(id, *args)      
111:       optional_attrs = args.last.is_a?(::Hash) ? args.pop : {}
112:       email, screen_name = args
113:       subscriber = {:customer_id => id, :email => email, :screen_name => screen_name}.merge(optional_attrs)
114:       result = Spreedly.post('/subscribers.xml', :body => Spreedly.to_xml_params(:subscriber => subscriber))
115:       case result.code.to_s
116:       when /2../
117:         new(result['subscriber'])
118:       when '403'
119:         raise "Could not create subscriber: already exists."
120:       when '422'
121:         errors = [*result['errors']].collect{|e| e.last}
122:         raise "Could not create subscriber: #{errors.join(', ')}"
123:       else
124:         raise "Could not create subscriber: result code #{result.code}."
125:       end
126:     end
delete!(id) click to toggle source

This will DELETE individual subscribers from the site. Pass in the customer_id.

Only works for test sites (enforced on the Spreedly side).

    # File lib/spreedly.rb, line 97
97:     def self.delete!(id)
98:       Spreedly.delete("/subscribers/#{id}.xml")
99:     end
find(id) click to toggle source

Looks a subscriber up by id.

     # File lib/spreedly.rb, line 129
129:     def self.find(id)
130:       xml = Spreedly.get("/subscribers/#{id}.xml")
131:       (xml.nil? || xml.empty? ? nil : new(xml['subscriber']))
132:     end
wipe!() click to toggle source

This will DELETE all the subscribers from the site.

Only works for test sites (enforced on the Spreedly side).

    # File lib/spreedly.rb, line 90
90:     def self.wipe!
91:       Spreedly.delete('/subscribers.xml')
92:     end

Public Instance Methods

activate_free_trial(plan_id) click to toggle source

Activates a free trial on the subscriber. Requires plan_id of the free trial plan

     # File lib/spreedly.rb, line 173
173:     def activate_free_trial(plan_id)
174:       result = Spreedly.post("/subscribers/#{id}/subscribe_to_free_trial.xml", :body => 
175:         Spreedly.to_xml_params(:subscription_plan => {:id => plan_id}))
176:       case result.code.to_s
177:       when /2../
178:       when '404'
179:         raise "Could not active free trial for subscriber: subscriber or subscription plan no longer exists."
180:       when '422'
181:         raise "Could not activate free trial for subscriber: validation failed. missing subscription plan id"
182:       when '403'
183:         raise "Could not activate free trial for subscriber: subscription plan either 1) isn't a free trial, 2) the subscriber is not eligible for a free trial, or 3) the subscription plan is not enabled."
184:       else
185:         raise "Could not activate free trial for subscriber: result code #{result.code}."
186:       end
187:     end
add_fee(args) click to toggle source

Add a Fee to a Subscriber usage: @subscriber.add_fee(:amount => amount, :group => group_name, :description => description, :name => name)

     # File lib/spreedly.rb, line 236
236:     def add_fee(args)
237:       result = Spreedly.post("/subscribers/#{id}/fees.xml", :body => Spreedly.to_xml_params(:fee => args))
238: 
239:       case result.code.to_s
240:       when /2../
241:       when '404'
242:         raise "Not Found"
243:       when '422'
244:         raise "Unprocessable Entity - #{result.body}"
245:       else
246:         raise "Could not add fee to subscriber: result code #{result.code}."
247:       end
248:     end
allow_free_trial() click to toggle source
 Allow Another Free Trial

usage: @subscriber.allow_free_trial

     # File lib/spreedly.rb, line 223
223:     def allow_free_trial
224:       result = Spreedly.post("/subscribers/#{id}/allow_free_trial.xml")
225: 
226:       case result.code.to_s
227:       when /2../
228:       else
229:         raise "Could not allow subscriber to another trial: result code #{result.code}."
230:       end
231:     end
comp(quantity, units, feature_level=nil) click to toggle source

Allows you to give a complimentary subscription (if the subscriber is inactive) or a complimentary time extension (if the subscriber is active). Automatically figures out which to do.

Note: units must be one of “days” or “months” (Spreedly enforced).

     # File lib/spreedly.rb, line 152
152:     def comp(quantity, units, feature_level=nil)
153:       params = {:duration_quantity => quantity, :duration_units => units}
154:       params[:feature_level] = feature_level if feature_level
155:       raise "Feature level is required to comp an inactive subscriber" if !active? and !feature_level
156:       endpoint = (active? ? "complimentary_time_extensions" : "complimentary_subscriptions")
157:       result = Spreedly.post("/subscribers/#{id}/#{endpoint}.xml", :body => Spreedly.to_xml_params(endpoint[0..2] => params))
158:       case result.code.to_s
159:       when /2../
160:       when '404'
161:         raise "Could not comp subscriber: no longer exists."
162:       when '422'
163:         raise "Could not comp subscriber: validation failed (#{result.body})."
164:       when '403'
165:         raise "Could not comp subscriber: invalid comp type (#{endpoint})."
166:       else
167:         raise "Could not comp subscriber: result code #{result.code}."
168:       end
169:     end
id() click to toggle source

Spreedly calls your id for the user the “customer id”. This gives you a handy alias so you can just call it “id”.

     # File lib/spreedly.rb, line 141
141:     def id
142:       customer_id
143:     end
stop_auto_renew() click to toggle source

Stop the auto renew of the subscriber such that their recurring subscription will no longer be renewed. usage: @subscriber.stop_auto_renew

     # File lib/spreedly.rb, line 191
191:     def stop_auto_renew
192:       result = Spreedly.post("/subscribers/#{id}/stop_auto_renew.xml")
193:       case result.code.to_s
194:       when /2../
195:       when '404'
196:         raise "Could not stop auto renew for subscriber: subscriber does not exist."
197:       else
198:         raise "Could not stop auto renew for subscriber: result code #{result.code}."
199:       end
200:     end
update(args) click to toggle source

Update a Subscriber usage: @subscriber.update(:email => email, :screen_name => screen_name)

     # File lib/spreedly.rb, line 206
206:     def update(args)
207:       result = Spreedly.put("/subscribers/#{id}.xml", :body => Spreedly.to_xml_params(:subscriber => args))
208: 
209:       case result.code.to_s
210:       when /2../
211:       when '403'
212:         raise "Could not update subscriber: new-customer-id is already in use."
213:       when '404'
214:         raise "Could not update subscriber: subscriber not found"
215:       else
216:         raise "Could not update subscriber: result code #{result.code}."
217:       end
218:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.