API

api API

class pyspreedly.api.Client(token, site_name)[source]
class Client(token, site_name)

Create an object to manage queries for a Client on a given site.

Parameters:
  • token – API access token for authorization.
  • site_name – the site_name registered with spreedly.
Client.add_fee(subscriber_id, name, description, group, amount)[source]
add_fee(subscriber_id, name, description, group, amount)[source]

Add a fee to a user with subscriber_id :param subscriber_id: the id of the subscriber :param name: the name of the fee (eg - Excess Bandwidth Charge) :param description: a description of the charge :param group: a group to add this charge too :param amount: the amount the charge is for :returns: the response object

Client.allow_free_trial(subscriber_id)[source]
allow_free_trial(subscriber_id)[source]

programatically allow for a new free trial :param subscriber_id: the id of the subscriber :returns: subscriber data as dictionary if all good, :raises: HTTPError if not so good (non-200)

Client.change_plan(subscriber_id, plan_id)[source]
change_plan(subscriber_id, plan_id)[source]

Change a subscription to a new plan, needs the user to be activated

subscribe a user to a free trial plan. :param subscriber_id: ID of the subscriber :parma plan_id: subscription plan ID to change to :returns: status code :raises: HTTPError if response status not 200

Client.cleanup()[source]
cleanup()[source]

Removes ALL subscribers. NEVER USE IN PRODUCTION! (should only Remove test users...) :returns: status code

Client.complimentary_time_extensions(subscriber_id, duration, duration_units)[source]
complimentary_time_extension(subscriber_id, duration, duration_units)

corrisponds to adding complimentary time extension to a subscriber

Client.create_complimentary_subscription(subscriber_id, duration, duration_units, feature_level, start_time=None, amount=None)[source]
create_complimentary_subscription(subscriber_id, duration, duration_units, feature_level[, start_time=None, amount=None])[source]

corrisponds to adding corrisponding subscription to a subscriber :param subscriber_id: Subscriber ID :param duration: Duration (unitless) :param duration_units: Unit for above (days, weeks, months i think) :param feature_level string: what feature level this is at :param start_time: If assgining a value for pro-rating purpose, you need this start datetime :type start_time: datetime.datetime or None :param amount: How much this comp is worth :type amount: float or None

Client.create_subscriber(customer_id, screen_name)[source]

Creates a subscription :param customer_id: Customer ID :param screen_name: Customer’s screen name :returns: Data for created customer :raises: HTTPError if response code isn’t 201

Client.delete_subscriber(id)[source]
delete_subscriber(id)[source]

delete a test subscriber :param id: user id :returns: status code

Client.get_info(subscriber_id)[source]
get_info(subscriber_id)[source]
Parameters:subscriber_id – Id of subscriber to fetch
Returns:Data as dictionary
Raises:HTTPError if not 200
Client.get_or_create_subscriber(subscriber_id, screen_name)[source]
get_or_create_subscriber(subscriber_id, screen_name)[source]

Tries to get info for a subscriber, else creates a new subscriber

Client.get_plans()[source]

get subscription plans for the configured site :returns: data as dict :raises: HTTPError if response is not 200

Client.get_signup_url(subscriber_id, plan_id, screen_name, token=None)[source]
get_signup_url(subscriber_id, plan_id, screen_name, token=None)[source]

Subscribe a user to the site plan on a free trial

subscribe a user to a plan, either trial or not :param subscriber_id: ID of the subscriber :param plan_id: subscription plan ID :param screen_name: user screen name :param token: customer token or None - if passed use the token version

of the url
Returns:url for subscription
Client.query(url, data=None, action='get')[source]
query(url[, data=None, put='get'])[source]

which has the problem that it doesn’t check if there is data for PUT, and is hard to read.

status_codes are not checked here, and should be handled by the caller.

Delete is only supported on test users

Parameters:
  • url – the api url you wish to reach (not incuding site/version)
  • data (UTF-8 encoded XML or None) – the data to send in the request. Default to None
  • action – one of ‘get’, ‘post’, ‘put’ and ‘delete’. Case insensitive, Default ‘get’
Returns:

response object

Return type:

requests response object

Client.set_info(subscriber_id, **kw)[source]

this corrisponds to the update-subscriber action. passed kw args are placed into the xml data (not sure how the -/_ are dealt with though)

There is a design flaw atm where sclient.set_info(sclient.get_info(123)) will not work at all as the keys are all different

Client.subscribe(subscriber_id, plan_id=None)[source]
subscribe(subscriber_id, plan_id)[source]

Subscribe a user to the site plan on a free trial

subscribe a user to a free trial plan. :param subscriber_id: ID of the subscriber :parma plan_id: subscription plan ID :returns: dictionary with xml data if all is good :raises: HTTPError if response status not 200