from pynexus import AppNexusAPI

APPNEXUS_ACCOUNT = {
    "username": "",
    "password": ""
}
api = AppNexusAPI(**APPNEXUS_ACCOUNT)

"""
Explanation: Summary
Requirements:

python 3  

This notebook show how to make call to the AppNexus API.
Implemented functions:
```python
   def get_campaign(self, ids=None, one_id=None, advertiser_id=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Campaign+Service"""
def get_pixel(self, ids=None, one_id=None, advertiser_id=None,
               advertiser_code=None, pixel_code=None, only_names=True):
    """ cf https://wiki.appnexus.com/display/api/Conversion+Pixel+Service """

def get_device(self, one_id=None, device_type=None, only_names=True):
    """ cf https://wiki.appnexus.com/display/api/Device+Model+Service """

def get_advertiser(self, ids=None, one_id=None, search_term=None, only_names=True):
    """ cf https://wiki.appnexus.com/display/api/Advertiser+Service"""

def get_line_item(self, ids=None, one_id=None, advertiser_id=None, only_names=True):
    """ cf https://wiki.appnexus.com/display/api/Line+Item+Service"""

def get_insertion_order(self, ids=None, one_id=None, advertiser_id=None, search_term=None, only_names=True):
    """ cf https://wiki.appnexus.com/display/api/Insertion+Order+Service"""

def get_segment(self, ids=None, one_id=None, search_term=None, only_names=True):
    """ cf https://wiki.appnexus.com/display/api/Segment+Service"""

```
End of explanation
"""


api.get_device(one_id=80)

"""
Explanation: 1. Make a request
Only the mapping *id -> name *
End of explanation
"""


api.get_device(one_id=80, only_names=False)

"""
Explanation: Full response
End of explanation
"""


pixels = AppNexusAPI.bulk_requests(api.get_pixel, range(0, 300))

"""
Explanation: 2. Bulk request
If you need to retrieve more than 100 mappings, you will need to make several call.
The bulk_requests function can to that for you
End of explanation
"""


# We limit here the number of calls to 10
names = AppNexusAPI.bulk_request_get_all(api.get_pixel, limit=10, only_names=True)

print('%d elements downloaded' % len(names))

"""
Explanation: You may also want to retrieve all the elements, without specifying an id.
base the default get function will only return up to 100 elements, you can use the bulk_request_get_all
to avoid hitting the limit.
End of explanation
"""


