Example #1
0
    def get_promotion(self, code):
        """
        Get the promotion with the specified coupon code.
        https://cheddargetter.com/developers#single-promotion
        """

        response = self.client.make_request(path="promotions/get", params={"code": code})
        promotion_parser = PromotionsParser()
        promotion_data = promotion_parser.parse_xml(response.content)

        return Promotion(**promotion_data[0])
Example #2
0
    def get_promotion(self, code):
        '''
        Get the promotion with the specified coupon code.
        https://cheddargetter.com/developers#single-promotion
        '''

        response = self.client.make_request(
            path='promotions/get',
            params={'code': code},
        )
        promotion_parser = PromotionsParser()
        promotion_data = promotion_parser.parse_xml(response.content)

        return Promotion(**promotion_data[0])
Example #3
0
    def test_promotions_parser(self):
        ''' Tests promotions parser. '''
        promotions_xml = self.load_file('promotions.xml')
        parser = PromotionsParser()

        expected = [
            {
                'description': 'Get your first year of unlimited, 10% off!',
                'created_datetime': datetime(2016, 3, 14, 16, 9, 15, tzinfo=tzutc()),
                'incentives': [{'created_datetime': None,
                                'percentage': '10',
                                'months': '1',
                                'type': 'percentage',
                                'id': '88350e9b-69f6-4ce8-a542-b82e03329cff'}],
                'name': '10% off initial yr UNLIMITED',
                'id': 'c14a8154-b007-409d-851a-1e9aac9da14b',
                'coupons': [{'created_datetime': datetime(2016, 3, 14, 16, 9, 15, tzinfo=tzutc()),
                             'expiration_datetime': datetime(2016, 3, 31, 0, 0, tzinfo=tzutc()),
                             'code': '10ANNUAL',
                             'id': '45c156c1-3149-4d6f-b4cf-9ad5ad8b6a5d',
                             'max_redemptions': '5'}],
                'plans': ['UNLIMITED_ANNUAL']
            },
            {
                'description': '',
                'created_datetime': datetime(2015, 11, 30, 21, 13, 14, tzinfo=tzutc()),
                'incentives': [{'created_datetime': None,
                                'percentage': '20',
                                'months': '0',
                                'type': 'percentage',
                                'id': 'd3f33004-4398-4a82-b354-c1ea8732c55d'}],
                'name': '20% off annual',
                'id': 'a0b3d969-028b-400d-a518-701c34354f6d',
                'coupons': [{'created_datetime': datetime(2015, 11, 30, 21, 13, 15, tzinfo=tzutc()),
                             'expiration_datetime': None,
                             'code': '20OFF',
                             'id': '7f1924b9-7d7f-4fd8-b751-8d0babf1431b',
                             'max_redemptions': '0'}],
                'plans': ['UNLIMITED_ANNUAL', 'BUSINESS_PLUS_ANNUAL', 'BUSINESS_ANNUAL']
            }
        ]

        result = parser.parse_xml(promotions_xml)
        import pprint
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(result)

        self.assertEquals(expected, result)
Example #4
0
    def get_all_promotions(self):
        '''
        Returns all promotions.
        https://cheddargetter.com/developers#promotions
        '''
        promotions = []

        try:
            response = self.client.make_request(path='promotions/get')
        except NotFound:
            response = None

        if response:
            promotions_parser = PromotionsParser()
            promotions_data = promotions_parser.parse_xml(response.content)
            promotions = [Promotion(**promotion_data) for promotion_data in promotions_data]

        return promotions
Example #5
0
    def get_all_promotions(self):
        """
        Returns all promotions.
        https://cheddargetter.com/developers#promotions
        """
        promotions = []

        try:
            response = self.client.make_request(path="promotions/get")
        except NotFound:
            response = None

        if response:
            promotions_parser = PromotionsParser()
            promotions_data = promotions_parser.parse_xml(response.content)
            promotions = [Promotion(**promotion_data) for promotion_data in promotions_data]

        return promotions