Giter Site home page Giter Site logo

pyoffers's Introduction

PyOffers

Build Coverage Version Python versions License

Python client library for HasOffers API.

Installation

PyOffers can be obtained with pip:

$ pip install pyoffers

Usage example

Initialize API client:

>>> from pyoffers.api import HasOffersAPI
>>> hasoffers = HasOffersAPI(
    endpoint='https://api.hasoffers.com/Apiv3/json',
    network_token='<your_network_token>',
    network_id='<your_network_id>',
)

Execute queries:

   >>> # Get all offers with ID greater than 100, sorted by ID and with loaded `Country` data
   >>> hasoffers.offers.find_all(id__gt=100, sort='id', contain=['Country'])
   [<Offer: 102>,
<Offer: 104>,
<Offer: 106>,
<Offer: 108>,
<Offer: 110>,
<Offer: 112>]
   >>> # Get all clicks records for 2016-09-20
   >>> hasoffers.raw_logs.clicks.find_all('20160920')
   [<LogRecord: 7 (1027a606128bd067105f0b0921840f)>, ...]
   >>> # Get all conversions for specific offer
   >>> offer = hasoffers.offers.get_by_id(100)
   >>> offer.conversions.find_all()
   [<Conversion: 70532>]

Documentation

You can view documentation online at:

Or you can look at the docs/ directory in the repository.

Python support

PyOffers supports Python 3.5+.

pyoffers's People

Contributors

iamanikeev avatar stranger6667 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyoffers's Issues

Support for filters

Support for this kind of things without manual building:

&filters[OR][status]=active&filters[OR][currency]=USD

may be something like:

api.conversions.filter_all(filters=Q(status='active') | Q(currency='USD'))

Refactor models instantiation

This is ugly:

if 'pageCount' in data:
    inner_data = data['data']
    result = []
    for item in inner_data.values():
        if 'Advertiser' in item:
            result.append(Advertiser(manager=self.advertisers, **item['Advertiser']))
        elif 'Offer' in item:
            result.append(Offer(manager=self.offers, **item['Offer']))
        elif 'Goal' in item:
            result.append(Goal(manager=self.goals, **item['Goal']))
    return result
elif 'Advertiser' in data:
    return Advertiser(manager=self.advertisers, **data['Advertiser'])
elif 'Offer' in data:
    return Offer(manager=self.offers, **data['Offer'])
elif 'Goal' in data:
    return Goal(manager=self.goals, **data['Goal'])

Generic methods

There are a lot of methods with same signatures and implementation. There should be a better way to work with them.

E.g. AdvertiserManager:

    def create(self, **kwargs):
        return self._call('create', data=kwargs)

GoalManager:

    def create(self, **kwargs):
        return self._call('create', data=kwargs)

It can be solved with inheritance, but it will lead to very large amount of base classes (I have to check it).

Possible solution - add all these methods to base class and propagate to child only members of generic_methods attribute:

generic_methods = ('find_all', 'create')

Async requests

E.g. for logs, when we have to make a lot of requests to HasOffers API

Goal model

Methods:

  • create
  • findById
  • update

Tests

Multiple parameters feature is not working

prepare_query_params should return list of tuples instead of dict.
Because of this the following query will produce incorrect URL:

key=[1, 2, 3]

Url will contain only last value: key[]=3

In other words produced parameters may have identical keys

Pagination support

Case:
You have 1500 conversions for some offer and you want to grab them all. But you cant get them all in single pyoffers API call, because of max limit is 1000 items.
So, there should be an ability to get everything in one find_all call.
Possibly async request would be helpful here

Improve sorting

HasOffers doc has a mistake.
Sorting key should be in the following format:

Target.key

It would be convenient if by default target will be prepended to key

Offer model

Methods:

  • create
  • addTargetCountry
  • addCategory
  • findById
  • update

Tests

OR queries

For now it is not supported, but it is easy to implement. But the main question is - how to design the interface?

Improved 'contain'

It would be better if related instances will be instantiated as attributes of returned object

Not paginated result leads to exception

api.conversions.find_all(filters={'offer_id': 9})

Exception:

    112             self._managers[key].init_instance(item)
    113             for chunk in data
--> 114             for key, item in chunk.items()
    115         ]
    116         if len(initialized) == 1 and single:

KeyError: '55632'

Change 'update' method

There is better interface - pass kwargs to this methods with data to update.
Current behaviour is more like 'save' method

Error if some objects has no objects from `contain`

Call:

api.offers.find_all(currency='CZK', sort='id', contain=['Country'])

Exception:

     13     def init_instance(self, data):
     14         if 'id' not in data:
---> 15             data = list(data.values())[0]
     16         return super().init_instance(data)

AttributeError: 'list' object has no attribute 'values'

Logs filtration

It is not very convenient to do like this to get log records:

In [2]: dirs = hasoffers.raw_logs.clicks.list_date_dirs()
In [3]: date_dir = dirs[0]
In [4]: logs = date_dir.list_logs()
In [5]: logs[0].records

It should be like this:

records = hasoffers.raw_logs.clicks.find_all(date='2016-09-09 09:00')

Sort in queries

Django-like style
´´´
sort='-key'
´´´

´´´
sort=['key1', '-key2']
´´´

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.