def get(self, **kwargs): """ Args: campaign (list of int) language (str) order_by (str) limit (int) offset (int) """ ordering = { 'order_by': kwargs.get('order_by', None), 'available': self.ORDERING } filtering = { 'filter_by': kwargs, 'available': { 'campaign': lambda x: Item.sanitize_integer_array(x, 'campaign', True), 'language': lambda x: Item.sanitize_string_value(x, 'language', 2, 2, True), } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_ordering(ordering) \ .set_filtering(filtering) \ .request(url=self.URL)
def get(self, **kwargs): """ Args: campaign (int) website (int) limit (int) offset (int) order_by (list of str) """ ordering = { 'order_by': kwargs.get('order_by', []), 'available': self.ORDERING } filtering = { 'filter_by': kwargs, 'available': { 'campaign': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True), 'website': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True), } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_ordering(ordering) \ .set_filtering(filtering) \ .request(url=self.URL)
def update(self, optcode_id, **kwargs): data = Item.sanitize_fields(self.UPDATE_FIELDS, **kwargs) request_data = { 'url': self.UPDATE_URL, 'optcode_id': Item.sanitize_id(optcode_id), } return self.transport.post().set_data(data).request(**request_data)
def test_sanitize_float_value(self): self.assertEqual(Item.sanitize_float_value(1, '', False), 1) self.assertEqual(Item.sanitize_float_value(0, '', False), 0) self.assertEqual(Item.sanitize_float_value('12', '', False), '12') self.assertEqual(Item.sanitize_float_value('3.14', '', False), '3.14') self.assertEqual(Item.sanitize_float_value(3.14, '', False), 3.14) self.assertEqual(Item.sanitize_float_value(None, '', True), None) with self.assertRaises(ValueError): Item.sanitize_float_value(None, '', False) Item.sanitize_float_value('foo', '', False)
def test_sanitize_long_date(self): self.assertEqual(Item.sanitize_long_date(None, '', True), None) self.assertEqual(Item.sanitize_long_date(datetime(2020, 1, 1, 11, 20, 36), '', False), '01.01.2020 11:20:36') self.assertEqual(Item.sanitize_long_date('01.01.2020 11:20:36', '', False), '01.01.2020 11:20:36') with self.assertRaises(ValueError): Item.sanitize_long_date(None, '', False) Item.sanitize_long_date('01/01/2020', '', True) Item.sanitize_long_date('01.01.2020 11/22/22', '', False)
def comment(self, ticket_id, **kwargs): """ Args: ticket_id (int) text (str) """ request_data = { 'url': self.COMMENT_URL, 'ticket_id': Item.sanitize_id(ticket_id) } data = Item.sanitize_fields(self.COMMENT_FIELDS, **kwargs) return self.transport.post().set_data(data).request(**request_data)
def getOne(self, _id, c_id, **kwargs): """ Here _id is a website id and c_id is a campaign id Args: _id (int) c_id (int) """ request_data = { 'url': self.SINGLE_URL, 'website_id': Item.sanitize_id(_id), 'campaign_id': Item.sanitize_id(c_id) } return self.transport.get().request(**request_data)
class StatisticWebsites(StatisticBase): """ Statistics by websites """ SCOPE = 'statistics' URL = Item.prepare_url('statistics/websites') def get(self, **kwargs): """ Args: date_start (date) date_end (date) website (int) campaign (int) subid (str) total (int) limit (int) offset (int) order_by (list of str) """ return super(StatisticWebsites, self).get(self.URL, **kwargs)
def get(self, _id, **kwargs): """ Here _id is a websites id Args: _id (int) campaign (list of int) campaign_category (list of int) category (list of int) type (str) limit (int) offset (int) order_by (str) """ request_data = { 'url': self.URL, 'website_id': Item.sanitize_id(_id) } filtering = { 'filter_by': kwargs, 'available': self.FILTERING } ordering = { 'order_by': kwargs.get('order_by', None), 'available': self.ORDERING } return self.transport.get() \ .set_pagination(**kwargs) \ .set_ordering(ordering) \ .set_filtering(filtering) \ .request(**request_data)
def get(self, campaign_id, website_id, **kwargs): """ Args: campaign_id (int) website_id (int) limit (int) offset (int) """ request_data = { 'url': self.URL, 'campaign_id': Item.sanitize_id(campaign_id), 'website_id': Item.sanitize_id(website_id), } return self.transport.get().set_pagination(**kwargs).request(**request_data)
def test_sanitize_date(self): self.assertEqual(Item.sanitize_date(None, '', True), None) self.assertEqual(Item.sanitize_date(datetime(2020, 1, 1), '', False), '01.01.2020') self.assertEqual(Item.sanitize_date(date(2020, 1, 1), '', False), '01.01.2020') self.assertEqual(Item.sanitize_date('01.01.2020', '', False), '01.01.2020') with self.assertRaises(ValueError): Item.sanitize_date(None, '', False) Item.sanitize_date('01/01/2020', '', True)
def disconnect(self, c_id, w_id, **kwargs): """ Disconnect an advertising campaign from a website Here w_id is a website id and c_id is a campaign id Args: c_id (int) w_id (int) """ request_data = { 'url': self.DISCONNECT_URL, 'campaign_id': Item.sanitize_id(c_id), 'website_id': Item.sanitize_id(w_id) } return self.transport.post().request(**request_data)
def create(self, attachments, **kwargs): """ Args: attachments (list of str) campaign (int) website (int) order_id (str) order_date (date) order_price (float) appeal_id (str) comment (str) """ data = Item.sanitize_fields(self.CREATE_FIELDS, **kwargs) files = [('attachment', open(item, 'rb')) for item in Item.sanitize_string_array(attachments, 'attachments')] return self.transport.post().set_data(data).set_files(files).request(url=self.CREATE_URL)
def get(self, campaign_id, website_id, **kwargs): """ Args: campaign_id (int) website_id (int) limit (int) offset (int) """ request_data = { 'url': self.URL, 'campaign_id': Item.sanitize_id(campaign_id), 'website_id': Item.sanitize_id(website_id), } return self.transport.get().set_pagination(**kwargs).request( **request_data)
class Referrals(Item): """ List of referrals """ SCOPE = 'referrals' URL = Item.prepare_url('referrals') SINGLE_URL = Item.prepare_url('referrals/%(referral_id)s') def get(self, **kwargs): """ Args: date_start (date) date_end (date) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'date_start': lambda x: Item.sanitize_date(x, 'date_start', True), 'date_end': lambda x: Item.sanitize_date(x, 'date_end', True) } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_filtering(filtering) \ .request(url=self.URL) def getOne(self, _id, **kwargs): """ Args: _id (int) """ request_data = { 'url': self.SINGLE_URL, 'referral_id': Item.sanitize_id(_id) } return self.transport.get().request(**request_data)
def get(self, **kwargs): """ Args: campaign (id) website (id) status (string) start_date (date) end_date (date) appeal_id (string) appeal_status (string) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'campaign': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True), 'website': lambda x: Item.sanitize_integer_value(x, 'website', blank=True), 'status': lambda x: Item.sanitize_string_value(x, 'status', blank=True), 'start_date': lambda x: Item.sanitize_string_value(x, 'start_date', blank=True), 'end_date': lambda x: Item.sanitize_string_value(x, 'end_date', blank=True), 'appeal_id': lambda x: Item.sanitize_string_value(x, 'appeal_id', blank=True), 'appeal_status': lambda x: Item.sanitize_string_value(x, 'appeal_status', blank=True), } } return self.transport.get() \ .set_filtering(filtering) \ .set_pagination(**kwargs) \ .request(url=self.URL)
class Payments(Item): """ List of webmaster payments """ SCOPE = 'payments' URL = Item.prepare_url('payments') SINGLE_URL = Item.prepare_url('payments/%(payment_id)s') def get(self, **kwargs): """ Args: has_statement (bool) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'has_statement': lambda x: Item.sanitize_bool_integer_value( x, 'has_statement', blank=True) } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_filtering(filtering) \ .request(url=self.URL) def getOne(self, _id, **kwargs): """ Args: _id (int) """ request_data = { 'url': self.SINGLE_URL, 'payment_id': Item.sanitize_id(_id) } return self.transport.get().request(**request_data)
def create(self, website_id, campaign_id, **kwargs): """ Args: website_id (int) campaign_id (int) ulp (list of str) subid (str) """ data = Item.sanitize_fields(self.CREATE_FIELDS, **kwargs) request_data = { 'url': self.CREATE_URL, 'website_id': Item.sanitize_id(website_id), 'campaign_id': Item.sanitize_id(campaign_id), } return self.transport.get().set_data(data).request(**request_data)
def update(self, retag_id, **kwargs): """ Args: retag_id (int) level (int) active (bool) script (str) comment (str) """ request_data = { 'url': self.UPDATE_URL, 'retag_id': Item.sanitize_id(retag_id) } data = Item.sanitize_fields(self.UPDATE_FIELDS, **kwargs) return self.transport.post().set_data(data).request(**request_data)
def get(self, link, **kwargs): """ Args: link (str) """ data = Item.sanitize_fields(self.GET_FIELDS, link=link) return self.transport.get().set_data(data).request(url=self.URL)
class CampaignsForWebsite(Item): """ List of advertising campaigns for a website """ SCOPE = 'advcampaigns_for_website' URL = Item.prepare_url('advcampaigns/website/%(website_id)s') SINGLE_URL = Item.prepare_url( 'advcampaigns/%(campaign_id)s/website/%(website_id)s') def get(self, _id, **kwargs): """ Here _id is a website id Args: _id (int) limit (int) offset (int) """ request_data = {'url': self.URL, 'website_id': Item.sanitize_id(_id)} return self.transport.get().set_pagination(**kwargs).request( **request_data) def getOne(self, _id, c_id, **kwargs): """ Here _id is a website id and c_id is a campaign id Args: _id (int) c_id (int) """ request_data = { 'url': self.SINGLE_URL, 'website_id': Item.sanitize_id(_id), 'campaign_id': Item.sanitize_id(c_id) } return self.transport.get().request(**request_data)
class LinksValidator(Item): SCOPE = 'validate_links' URL = Item.prepare_url('validate_links') GET_FIELDS = { 'link': lambda x: Item.sanitize_string_value(x, 'link'), } def get(self, link, **kwargs): """ Args: link (str) """ data = Item.sanitize_fields(self.GET_FIELDS, link=link) return self.transport.get().set_data(data).request(url=self.URL)
class Tickets(Item): SCOPE = 'tickets' URL = Item.prepare_url('tickets') SINGLE_URL = Item.prepare_url('tickets/%(ticket_id)s') def get(self, **kwargs): """ Args: date_start (date) date_end (date) status (int) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'date_start': lambda x: Item.sanitize_date(x, 'date_start', True), 'date_end': lambda x: Item.sanitize_date(x, 'date_end', True), 'status': lambda x: Item.sanitize_integer_value(x, 'status', True), } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_filtering(filtering) \ .request(url=self.URL) def getOne(self, ticket_id): """ Args: ticket_id (int) """ request_data = { 'url': self.SINGLE_URL, 'ticket_id': Item.sanitize_id(ticket_id) } return self.transport.get().request(**request_data)
def get(self, currency=None): """ Args: currency (str) """ request_data = { 'currency': Item.sanitize_currency_value(currency, blank=True), 'url': self.CURRENCY_URL if currency else self.URL } return self.transport.get().request(**request_data)
def get(self, **kwargs): """ Args: website (int) active (bool) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'website': lambda x: Item.sanitize_integer_value(x, 'website', True), 'active': lambda x: Item.sanitize_bool_integer_value(x, 'active', True) } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_filtering(filtering) \ .request(url=self.URL)
def delete(self, _id): """ Args: _id (int) """ request_data = { 'url': self.DELETE_URL, 'website_id': Item.sanitize_id(_id) } return self.transport.post().request(**request_data)
def getOne(self, retag_id): """ Args: retag_id (int) """ request_data = { 'url': self.SINGLE_URL, 'retag_id': Item.sanitize_id(retag_id) } return self.transport.get().request(**request_data)
def getOne(self, broken_link_id): """ Args: broken_link_id (int) """ request_data = { 'url': self.SINGLE_URL, 'broken_link_id': Item.sanitize_id(broken_link_id) } return self.transport.get().request(**request_data)
def getOne(self, coupon_category_id): """ Args: coupon_category_id (int) """ request_data = { 'url': self.SINGLE_URL, 'coupon_category_id': Item.sanitize_id(coupon_category_id) } return self.transport.get().request(**request_data)
def getLevelsForCampaign(self, campaign_id): """ Args: capaign_id (int) """ request_data = { 'url': self.LEVELS_FOR_CAMPAIGN_URL, 'campaign_id': Item.sanitize_id(campaign_id) } return self.transport.get().request(**request_data)
def getLevelsForWebsite(self, website_id): """ Args: website_id (int) """ request_data = { 'url': self.LEVELS_FOR_WEBSITE_URL, 'website_id': Item.sanitize_id(website_id) } return self.transport.get().request(**request_data)
def delete(self, lost_order_id): """ Args: lost_order_id (int) """ request_data = { 'url': self.DELETE_URL, 'lost_order_id': Item.sanitize_id(lost_order_id), } return self.transport.delete().request(**request_data)
def verify(self, _id): """ Args: _id (int) """ request_data = { 'url': self.VERIFY_URL, 'website_id': Item.sanitize_id(_id) } return self.transport.post().request(**request_data)
def getOne(self, _id, **kwargs): """ Args: _id (int) """ request_data = { 'url': self.SINGLE_URL, 'payment_id': Item.sanitize_id(_id) } return self.transport.get().request(**request_data)
def getOne(self, lost_order_id): """ Args: lost_order_id (int) """ request_data = { 'url': self.SINGLE_URL, 'lost_order_id': Item.sanitize_id(lost_order_id) } return self.transport.get().request(**request_data)
def getOne(self, _id, **kwargs): """ Args: _id (int) """ request_data = { 'url': self.SINGLE_URL, 'referral_id': Item.sanitize_id(_id) } return self.transport.get().request(**request_data)
def get(self, **kwargs): """ Args: date_start (date) date_end (date) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'date_start': lambda x: Item.sanitize_date(x, 'date_start', True), 'date_end': lambda x: Item.sanitize_date(x, 'date_end', True) } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_filtering(filtering) \ .request(url=self.URL)
def get(self, **kwargs): """ Args: website (list of int) campaign (list of int) search (str) reason (int) date_start (date) date_end (date) limit (int) offset (int) """ filtering = { 'filter_by': kwargs, 'available': { 'website': lambda x: Item.sanitize_integer_array(x, 'website', blank=True), 'campaign': lambda x: Item.sanitize_integer_array(x, 'campaign', blank=True), 'search': lambda x: Item.sanitize_string_value(x, 'search', blank=True), 'reason': lambda x: Item.sanitize_integer_value(x, 'reason', blank=True), 'date_start': lambda x: Item.sanitize_date(x, 'date_start', blank=True), 'date_end': lambda x: Item.sanitize_date(x, 'date_end', blank=True), } } return self.transport.get() \ .set_pagination(**kwargs) \ .set_filtering(filtering) \ .request(url=self.URL)
def create(self, **kwargs): """ Args: website (int) level (int) active (bool) script (str) comment (str) """ data = Item.sanitize_fields(self.CREATE_FIELDS, **kwargs) return self.transport.post().set_data(data).request(url=self.CREATE_URL)
def getOne(self, code='ru'): """ Args: code (str) """ request_data = { 'url': self.SINGLE_URL, 'code': Item.sanitize_string_value(code, 'code', 2, 2, False) } return self.transport.get().request(**request_data)