示例#1
0
    def create_subscriber(self, customer_id, screen_name):
        ''' .. py:method::create_subscriber(customer_id, screen_name)
        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
        '''
        data = '''
        <subscriber>
            <customer-id>{id}</customer-id>
            <screen-name>{name}</screen-name>
        </subscriber>
        '''.format(id=customer_id, name=screen_name)

        response = self.query(url='subscribers.xml',data=data, action='post')

        # Parse
        if not response.status_code == 201:
            if response.status_code == 403 and _user_exists_re.search(response.text):
                return self.get_info(customer_id)
            e = requests.HTTPError(
                    "status code: {0}, text: {1}".format(
                        response.status_code, response.text))
            e.response = response
            raise e
        return objectify_spreedly(response.text)
示例#2
0
    def allow_free_trial(self, subscriber_id):
        """ .. py:method:: allow_free_trial(subscriber_id)

        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)
        """
        url = 'subscribers/{id}/allow_free_trial.xml'.format(id=subscriber_id)
        response = self.query(url,'', action='post')
        if response.status_code is not 200:
            raise requests.HTTPError('status; {0}, text {1}'.format(
                response.status_code, response.text))
        else:
            return objectify_spreedly(response.text)
示例#3
0
    def get_plans(self):
        """ .. py:method::get_plans()
        get subscription plans for the configured site
        :returns: data as dict
        :raises: :py:exc:`HTTPError` if response is not 200
        """
        response = self.query('subscription_plans.xml', action='get')

        if response.status_code != 200:
            e = requests.HTTPError()
            e.code = response.status_code
            raise e

        # Parse
        result = objectify_spreedly(response.text)
        return result
示例#4
0
    def get_info(self, subscriber_id):
        """ .. py:method:: get_info(subscriber_id)

        :param subscriber_id: Id of subscriber to fetch
        :returns: Data as dictionary
        :raises: HTTPError if not 200
        """
        url = 'subscribers/{id}.xml'.format(id=subscriber_id)
        response = self.query(url, action='get')
        if response.status_code != 200:
            e = requests.HTTPError()
            e.code = response.status_code
            raise e

        # Parse
        return objectify_spreedly(response.text)
示例#5
0
    def subscribe(self, subscriber_id, plan_id=None):
        ''' .. py:method:: subscribe(subscriber_id, plan_id)
        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
        '''
        #TODO - This lacks subscription for a site to a plan_id.
        data = '''
        <subscription_plan>
            <id>{plan_id}</id>
        </subscription_plan>'''.format(plan_id=plan_id)

        url = 'subscribers/{id}/subscribe_to_free_trial.xml'.format(id=subscriber_id)
        response = self.query(url, data, action='post')

        if response.status_code != 200:
            raise requests.HTTPError("status code: {0}, text: {1}".format(response.status_code, response.text))

        # Parse
        return objectify_spreedly(response.text)