Skip to content

Commit be2a61e

Browse files
authored
refactor examples (#8)
* refactor examples
1 parent af2920e commit be2a61e

6 files changed

Lines changed: 85 additions & 56 deletions

File tree

README.MD

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
##Usabilla API - Python Client
1+
#Usabilla API - Python Client
22

33
[![Build Status](https://travis-ci.org/usabilla/api-python.svg?branch=master)](https://travis-ci.org/usabilla/api-python)
44
[![PyPI version](https://badge.fury.io/py/usabilla-api.svg)](https://badge.fury.io/py/usabilla-api)
@@ -26,42 +26,24 @@ It makes use of the API to request the following products and resources:
2626

2727
For more information on resources, authorization and available API calls, please visit out [documentation](https://usabilla.com/api).
2828

29-
# Installation:
29+
## Installation:
3030

3131
Requires Python 2.7
3232

3333
```bash
3434
pip install usabilla-api
3535
```
3636

37-
# Buttons example:
38-
```python
39-
>>> import usabilla as ub
40-
>>> api = ub.APIClient('YOUR-ACCESS-KEY', 'YOUR-SECRET-KEY')
41-
>>> api.set_query_parameters({'limit' : 1})
42-
>>> buttons = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES,api.RESOURCE_BUTTON)
43-
>>> print buttons
44-
```
37+
## Examples:
38+
The example folder contains an example of the client, which gives an idea how the client can be used and what is possible.
39+
4540

46-
### Iterators
41+
## Iterators
4742

4843
When working with the <code>limit</code> parameters (default value is **100**) you can request resources using the <code>item_iterator()</code> function.
4944
The API returns data in pages. This function returns a [Generator](https://wiki.python.org/moin/Generators) which
5045
traverses these pages for you and yields each result in the current page before retrieving the next page.
5146

52-
## Feedback example
53-
54-
```python
55-
>>> import usabilla as ub
56-
>>> import json
57-
>>> api = ub.APIClient('YOUR-ACCESS-KEY', 'YOUR-SECRET-KEY')
58-
>>> api.set_query_parameters({'limit' : 1})
59-
>>> feedbackItems = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES,api.RESOURCE_FEEDBACK,'*',iterate=True)
60-
>>> print json.dumps([item for item in feedbackItems], indent=4)
61-
```
62-
63-
Where <code>id</code> is the button id from which the feedback originates.
64-
6547
##Support
6648

6749
The Usabilla Python Client API is maintained by Usabilla Development Team. Everyone is encouraged to file bug reports, feature requests, and pull requests through GitHub. This input is critical and will be carefully considered, but we can’t promise a specific resolution or time frame for any request. For more information please email our Support Team at support@usabilla.com

example/examples_apps.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Example Usabilla for Apps"""
2+
3+
import usabilla as ub
4+
5+
from datetime import datetime, timedelta
6+
7+
if __name__ == '__main__':
8+
# Create an API client with access key and secret key
9+
api = ub.APIClient('YOUR-ACCESS-KEY', 'YOUR-SECRET-KEY')
10+
11+
# Set the limit of buttons to retrieve to 1
12+
if False:
13+
api.set_query_parameters({'limit': 1})
14+
15+
# Set a limit for last 7 days
16+
if False:
17+
epoch = datetime(1970, 1, 1)
18+
since = timedelta(days=7)
19+
since_unix = (datetime.utcnow() - since - epoch).total_seconds() * 1000
20+
api.set_query_parameters({'since': since_unix})
21+
22+
# Get all apps forms for this account
23+
forms = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_APPS, api.RESOURCE_APP)
24+
first_form = forms['items'][0]
25+
print first_form['name']
26+
27+
# Get the feedback of the first app form
28+
feedback = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_APPS, api.RESOURCE_FEEDBACK, first_form['id'], iterate=True)
29+
print len([item for item in feedback])

example/examples_email.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Example Usabilla for Email"""
2+
3+
import usabilla as ub
4+
5+
if __name__ == '__main__':
6+
# Create an API client with access key and secret key
7+
api = ub.APIClient('YOUR-ACCESS-KEY', 'YOUR-SECRET-KEY')
8+
9+
# Get all email widgets for this account
10+
widgets = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_EMAIL, api.RESOURCE_BUTTON)
11+
first_widget = widgets['items'][0]
12+
print first_widget['name']
13+
14+
# Get the feedback of the first email widget
15+
feedback = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_EMAIL, api.RESOURCE_FEEDBACK, first_widget['id'], iterate=True)
16+
print len([item for item in feedback])

example/examples_websites.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Examples Usabilla for Websites"""
2+
3+
import usabilla as ub
4+
5+
if __name__ == '__main__':
6+
# Create an API client with access key and secret key
7+
api = ub.APIClient('YOUR-ACCESS-KEY', 'YOUR-SECRET-KEY')
8+
9+
# Get all buttons for this account
10+
buttons = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES,api.RESOURCE_BUTTON)
11+
first_button = buttons['items'][0]
12+
print first_button['name']
13+
14+
# Get the feedback items for the first button of the list
15+
feedback_items = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES, api.RESOURCE_FEEDBACK, first_button['id'], iterate=True)
16+
print len([item for item in feedback_items])
17+
18+
# ---------------------------------------
19+
# Get all campaigns for this account
20+
campaigns = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES, api.RESOURCE_CAMPAIGN)
21+
first_campaign = campaigns['items'][0]
22+
print first_campaign['name']
23+
24+
# Get the responses of the first campaign
25+
responses = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES, api.RESOURCE_CAMPAIGN_RESULT, first_campaign['id'], iterate=True)
26+
print len([item for item in responses])
27+
28+
# Get the stats of the first campaign
29+
stats = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES, api.RESOURCE_CAMPAIGN_STATS, first_campaign['id'])
30+
print stats
31+
32+
33+
# ---------------------------------------
34+
# in-page is not yet available

examples/buttons_example.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/feedback_iterator_example.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)