Skip to content

Commit

Permalink
Support findAllAffiliateApprovals for Offer model (#75)
Browse files Browse the repository at this point in the history
* Isort code in tests

* Support offer files

* Isort

* Isort

* Isort code in tests

* Isort!!

* Isort

* Isort!!

* Support findAllAffiliateApprovals method for Offer

* Support findAllAffiliateApprovals method for Offer

* Fix changelog

* Fix find relations methods for tags

* Remove unused import

* Remove unused code
  • Loading branch information
iamanikeev authored and Stranger6667 committed Jun 18, 2018
1 parent 5ea5658 commit a59393e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Changelog
`Unreleased`_
-------------

Added
~~~~~
- ``find_all_affiliate_approvals``. (`iamanikeev`_)
- Fix ``find_all_(offer|affiliate|advertiser)_tag_relations`` methods for Tag model. (`iamanikeev`_)

`0.6.8`_ - 2018-06-15
---------------------

Expand Down
18 changes: 18 additions & 0 deletions pyoffers/models/offer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding: utf-8
from pyoffers.utils import Filter

from .conversion import ConversionManager
from .core import ApplicationManager, Model, ModelManager
from .offer_file import OfferFileManager
Expand Down Expand Up @@ -58,6 +60,10 @@ def get_unapproved_affiliate_ids(self):
def generate_tracking_link(self, affiliate_id, tiny_url=False, **params):
return self._manager.generate_tracking_link(self.id, affiliate_id, tiny_url=tiny_url, **params)

def find_all_affiliate_approvals(self, sort=(), limit=None, page=None, fields=None, **kwargs):
kwargs['offer_id'] = self.id
return self._manager.find_all_affiliate_approvals(sort=(), limit=None, page=None, fields=None, **kwargs)


class OfferManager(ModelManager):
model = Offer
Expand Down Expand Up @@ -138,6 +144,18 @@ def generate_tracking_link(self, id, affiliate_id, tiny_url=False, **params):
raw=True
)

def find_all_affiliate_approvals(self, sort=(), limit=None, page=None, fields=None, **kwargs):
return self._call(
'findAllAffiliateApprovals',
sort=sort,
limit=limit,
page=page,
fields=fields,
single_result=False,
target_class='AffiliateOffer',
filters=Filter(**kwargs)
)


class OfferCategory(Model):
""""
Expand Down
14 changes: 11 additions & 3 deletions pyoffers/models/tags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pyoffers.utils import Filter

from .core import InvisibleModelManager, Model, ModelManager


Expand Down Expand Up @@ -51,13 +53,19 @@ class TagManager(ModelManager):
)

def find_all_offer_tag_relations(self, **kwargs):
return self._call('findAllOfferTagRelations', target_class='TagRelation', single_result=False, **kwargs)
return self._call(
'findAllOfferTagRelations', target_class='TagRelation', single_result=False, filters=Filter(**kwargs)
)

def find_all_affiliate_tag_relations(self, **kwargs):
return self._call('findAllAffiliateTagRelations', target_class='TagRelation', single_result=False, **kwargs)
return self._call(
'findAllAffiliateTagRelations', target_class='TagRelation', single_result=False, filters=Filter(**kwargs)
)

def find_all_advertiser_tag_relations(self, **kwargs):
return self._call('findAllAdvertiserTagRelations', target_class='TagRelation', single_result=False, **kwargs)
return self._call(
'findAllAdvertiserTagRelations', target_class='TagRelation', single_result=False, filters=Filter(**kwargs)
)

def add_to_offer(self, tag_id, offer_id):
return self._call('addToOffer', target_class='TagRelation', tag_id=tag_id, offer_id=offer_id)
Expand Down
68 changes: 68 additions & 0 deletions tests/cassettes/offer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,74 @@
},
"url": "https://api.hasoffers.com/Apiv3/json?NetworkId=id&NetworkToken=token&Target=Offer&Method=generateTrackingLink&offer_id=196&affiliate_id=94&options%5Btiny_url%5D=0&params%5Bfile_id%5D=727"
}
},
{
"recorded_at": "2018-06-15T12:46:42",
"request": {
"body": {
"base64_string": "",
"encoding": "utf-8"
},
"headers": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Connection": [
"keep-alive"
],
"User-Agent": [
"python-requests/2.18.4"
]
},
"method": "GET",
"uri": "https://api.hasoffers.com/Apiv3/json?NetworkToken=token&NetworkId=id&Target=Offer&Method=findAllAffiliateApprovals&filters%5Boffer_id%5D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eDDK91YFwEvc3DPEgolzWfHjDIFPzDPLIbG+q9myFArnPAE+bsYMel9SNH2RAYe8IFhMphLEN0bpLltxotTPu8vJucc1weIakhGmmNoKTtaqdYDpFpTAIMSSBODtLe1RRVvqegNt133hfO1087b7CPLGKkrygOINxloB4VyUdrQlbQ6wND5FfaVVXpkcPAT5g3LelORv7sygwYlAlooIR0RVA2OoFmrEMUZWbwDmgwc5q765fwcA2TctDBU2C+/tdrlhtrCrJlmqBzdpu8tf3gD2ujwZTl0nust6ViYGshzQdZCr0hzBVQWEQt0OqYXBXQkIaq2tme6c/ZJBcQ+u7WA4wTX3zBfz2/F53uXYemNccel/zdi2chv40dG71SCSr/Whop3mfmTuoKVl7dftwQwUcBgrP4QrEBZcZdOlpnHTXqxfDdzhIrjpVWvdVh8J7WNdc5goSRlZwhO9FpyakAPNOWCHgbiop0yrUbEfxvdOAMmrISgEaJVz68X4465BHmhsmGsRwwRwwXu8raERN2QYs6i4/l2mnvemX3RoKvTdRQlH5aQFla0gpZN3DjggkvQXYlM0E0nVX4cEKwyGQvDMCOyREQHPELA4y1pa1d6yb+/Hczf0ZyBUih5CWfHi4ttzB4d5yH05yRPTpIn4SoccDCH36XBF6dIqWDiP00wkgmmS6TGY/FqFPHyD0F3FygM+j6DF07qHSMDb/TmT+U4LxNomLSTJHMJ5MRzA+gvERjI9gfATjIxgfwfgIxp8HGJ/PnwLj8/kAGJ89VzD+1OdyB8bTBJ4fC8ZnA2A8jf6fj+Uf330nJG8+lieIUaY/JT4fP5aP+HzE5yM+H/H5iM9HfD7i8+eJz+HSB2ylcKb99Xfz/h6cBUTboIK7fwGUnz7N+yMAAA==",
"encoding": null
},
"headers": {
"Access-Control-Allow-Headers": [
"X-Requested-With"
],
"Access-Control-Allow-Origin": [
"*"
],
"Connection": [
"keep-alive"
],
"Content-Encoding": [
"gzip"
],
"Content-Length": [
"1480"
],
"Content-Type": [
"application/json"
],
"Date": [
"Fri, 15 Jun 2018 12:46:42 GMT"
],
"Server": [
"Apache"
],
"Vary": [
"Accept-Encoding"
],
"X-Request-Id": [
"61f90654-7969-4388-be73-bd6a2d2ffc76"
]
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://api.hasoffers.com/Apiv3/json?NetworkToken=token&NetworkId=id&Target=Offer&Method=findAllAffiliateApprovals&filters%5Boffer_id%5D=196"
}
}
],
"recorded_with": "betamax/0.8.1"
Expand Down
7 changes: 7 additions & 0 deletions tests/models/test_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,10 @@ def test_generate_tracking_link(offer):
def test_generate_tracking_link_w_tiny_url(offer):
result = offer.generate_tracking_link(94, file_id=727, tiny_url=True)
assert 'offer_id=472' not in result['click_url']


def test_find_all_affiliate_approvals(offer):
result = offer.find_all_affiliate_approvals()
assert isinstance(result, list)
assert all(isinstance(item, AffiliateOffer) for item in result)
assert len(set(item.offer_id for item in result)) == 1 # Check that all results have the same offer_id

0 comments on commit a59393e

Please sign in to comment.