Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.

Commit f639cad

Browse files
author
Mark Beacom
authored
Merge pull request #3 from raphaelhuefner/release_candidate
Release candidate
2 parents 3737624 + 89edc53 commit f639cad

14 files changed

+798
-17
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ __pycache__/
99

1010
# Distribution / packaging
1111
.Python
12+
bin/
1213
build/
1314
develop-eggs/
1415
dist/
@@ -25,6 +26,8 @@ wheels/
2526
.installed.cfg
2627
*.egg
2728
MANIFEST
29+
pip-selfcheck.json
30+
pyvenv.cfg
2831

2932
# PyInstaller
3033
# Usually these files are written by a python script from a template

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ matrix:
1818
- python: 3.4
1919
- python: 3.5
2020
- python: 3.6
21+
# - python: 3.7 # As of 2018-07-18T13-10-00Z, Python 3.7 is not available on Travis just yet.
2122

2223
install: pip install .
2324

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ test: ## Run pytest.
1919
@python setup.py test
2020

2121
fix-isort: ## Run isort against python files in the project directory.
22-
@isort -rc --atomic .
22+
@isort -rc --atomic ./gitcoin ./tests
2323

2424
fix-yapf: ## Run yapf against any included or newly introduced Python code.
25-
@yapf -i -r -p .
25+
@yapf -i -r -p ./gitcoin ./tests
2626

2727
fix: fix-isort fix-yapf ## Attempt to run all fixes against the project directory.
2828

README.md

+194-13
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,220 @@
1-
# python-api-client
2-
Python API Client
1+
# Gitcoin Python API Client
2+
3+
This Python package provides the `bounties` endpoint of the Gitcoin API, which allows you to:
4+
5+
- list all bounties
6+
- list all bounties which meet certain conditions (i.e. filter them)
7+
- retrieve a single bounty by it's primary key
38

49
## Install via pypi
510

611
```bash
712
pip install gitcoin
813
```
914

10-
## Usage
15+
## Usage Examples
16+
17+
### List all bounties
18+
19+
```python
20+
from gitcoin import Gitcoin
21+
api = Gitcoin()
22+
all_bounties = api.bounties.all()
23+
```
24+
25+
### List all open bounties
26+
27+
```python
28+
from gitcoin import Gitcoin
29+
api = Gitcoin()
30+
open_bounties = api.bounties.filter(is_open=True).all()
31+
```
32+
33+
### List all open "Beginner" bounties
34+
35+
```python
36+
from gitcoin import Gitcoin
37+
api = Gitcoin()
38+
bounties_api = api.bounties
39+
bounties_api.filter(is_open=True)
40+
bounties_api.filter(experience_level='Beginner')
41+
open_beginner_bounties = bounties_api.all()
42+
```
43+
44+
The example above has been reformatted for easier reading. A [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface#Python) is also available. Please scroll the following code block all the way to the end to see the whole line:
45+
46+
```python
47+
from gitcoin import Gitcoin
48+
api = Gitcoin()
49+
open_beginner_bounties = api.bounties.filter(is_open=True, experience_level='Beginner').all()
50+
```
51+
52+
### List all open bounties marked for either "Beginner" OR "Intermediate" experience level
53+
54+
For some filter conditions, multiple different values can be given, which results in a logical `OR` for that condition:
1155

1256
```python
1357
from gitcoin import Gitcoin
1458
api = Gitcoin()
15-
api.bounties.all()
16-
api.bounties.filter(pk__gt=100).all()
59+
bounties_api = api.bounties
60+
bounties_api.filter(is_open=True)
61+
bounties_api.filter(experience_level='Beginner')
62+
bounties_api.filter(experience_level='Intermediate')
63+
open_beginner_and_intermediate_bounties = bounties_api.all()
64+
```
65+
66+
The example above has been reformatted for easier reading. A [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface#Python) is also available. Please scroll the following code block all the way to the end to see the whole line:
67+
68+
```python
69+
from gitcoin import Gitcoin
70+
api = Gitcoin()
71+
open_beginner_and_intermediate_bounties = api.bounties.filter(is_open=True).filter(experience_level='Beginner').filter(experience_level='Intermediate').all()
1772
```
1873

1974
## API
2075

21-
### public (unrestricted)
76+
### Instantiation
77+
78+
1. Create a `Gitcoin()` API root object:
79+
```python
80+
from gitcoin import Gitcoin
81+
api = Gitcoin()
82+
```
83+
2. The `bounties` API endpoint is accessible as a property of the API root object:
84+
```python
85+
bounties_endpoint = api.bounties
86+
```
87+
Each access to the `bounties` property results in a new `Endpoint` object with no filter conditions or any other parameters (like sorting) set. If you want to keep a specific set of filter conditions, simply store the `Endpoint` object in a variable instead of referring to the `bounties` property of the root object.
88+
89+
### `bounties.filter(**kwargs)`
90+
91+
Limit the list of bounties returned by either `get_page()` or `all()` to those bounties meeting the filter condition(s). For some filter conditions, multiple different values can be given, which results in a logical `OR` for that condition.
92+
93+
The condition name is the name of the keyword argument, and the condition value is the value of the keyword argument:
94+
95+
```python
96+
open_bounties = api.bounties.filter(is_open=True).all()
97+
```
98+
99+
Conditions with different names can be given in one `filter()` call:
100+
101+
```python
102+
open_beginner bounties = api.bounties.filter(is_open=True, experience_level='Beginner').all()
103+
```
104+
105+
Or if preferred, they can also be given in separate `filter()` calls:
106+
107+
```python
108+
open_beginner bounties = api.bounties.filter(is_open=True).filter(experience_level='Beginner').all()
109+
```
110+
111+
Giving multiple values for the same filter condition has to be done in separate calls to `filter()`:
112+
113+
```python
114+
beginner_and_intermediate_bounties = api.bounties.filter(experience_level='Beginner').filter(experience_level='Intermediate').all()
115+
```
116+
117+
For the following filter conditions, multiple values can be given to achieve a logical `OR`:
118+
119+
- `experience_level (str)`
120+
- `project_length (str)`
121+
- `bounty_type (str)`
122+
- `bounty_owner_address (str)`
123+
- `bounty_owner_github_username (str)`
124+
- `idx_status (str)`
125+
- `network (str)`
126+
- `standard_bounties_id (int)`
127+
- `github_url (str)`
128+
- `raw_data (str)`
129+
130+
The following filter conditions are **single value**, in other words, multiple values result in the last value overwriting all earlier values:
131+
132+
- `pk__gt (int)`
133+
- `started (str)`
134+
- `is_open (bool)`
135+
- `fulfiller_github_username (str)`
136+
- `interested_github_username (str)`
137+
138+
`filter()` returns the `Endpoint` object itself to enable a [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface#Python).
139+
140+
### `bounties.order_by(sort)`
141+
142+
Determine the order of the bounties returned by either `get_page()` or `all()`. The `sort` argument is a `string` containing a DB field name to sort by. It can also have an optional "-" prefix for reversing the direction. Choose from these field names:
143+
144+
- `accepted`
145+
- `balance`
146+
- `bounty_owner_address`
147+
- `bounty_owner_email`
148+
- `bounty_owner_github_username`
149+
- `bounty_owner_name`
150+
- `bounty_type`
151+
- `canceled_on`
152+
- `contract_address`
153+
- `current_bounty`
154+
- `experience_level`
155+
- `expires_date`
156+
- `fulfillment_accepted_on`
157+
- `fulfillment_started_on`
158+
- `fulfillment_submitted_on`
159+
- `github_comments`
160+
- `github_url`
161+
- `idx_experience_level`
162+
- `idx_project_length`
163+
- `idx_status`
164+
- `interested`
165+
- `interested_comment`
166+
- `is_open`
167+
- `issue_description`
168+
- `last_comment_date`
169+
- `metadata`
170+
- `network`
171+
- `num_fulfillments`
172+
- `override_status`
173+
- `privacy_preferences`
174+
- `project_length`
175+
- `raw_data`
176+
- `snooze_warnings_for_days`
177+
- `standard_bounties_id`
178+
- `submissions_comment`
179+
- `title`
180+
- `token_address`
181+
- `token_name`
182+
- `token_value_in_usdt`
183+
- `token_value_time_peg`
184+
- `_val_usd_db`
185+
- `value_in_eth`
186+
- `value_in_token`
187+
- `value_in_usdt`
188+
- `value_in_usdt_now`
189+
- `value_true`
190+
- `web3_created`
191+
- `web3_type`
192+
193+
`order_by()` returns the `Endpoint` object itself to enable a [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface#Python).
194+
195+
### `bounties.get_page(number=1, per_page=25)`
196+
197+
Returns one page of the (potentially `filter()`ed) `list` of bounties with the given 1-based index `number (int)`. The page size can be set with `per_page (int)`. Each bounty is a `dict`, basically the direct output of [`requests`' `.json()`](http://docs.python-requests.org/en/master/user/quickstart/#json-response-content) call.
198+
199+
### `bounties.all()`
200+
201+
Returns the complete (potentially `filter()`ed) `list` of bounties. Each bounty is a `dict`, basically the direct output of [`requests`' `.json()`](http://docs.python-requests.org/en/master/user/quickstart/#json-response-content) call.
22202

23-
`GET /api/v2/bounties`
203+
### `bounties.get(primary_key)`
24204

25-
### private (restricted)
205+
Returns one (1) bounty as specified by `primary_key (int)`. It is returned as a `dict`, basically the direct output of [`requests`' `.json()`](http://docs.python-requests.org/en/master/user/quickstart/#json-response-content) call.
26206

207+
-------------------------
27208

28209
## Todo
29210

30-
- [ ] Add base gitcoin.Gitcoin client
31-
- [ ] Add `bounties` api filter
32-
- [ ] Implement all filter fields present in `gitcoinco/web/app/dashboard/router.py`
211+
- [x] Add base gitcoin.Gitcoin client
212+
- [x] Add `bounties` api filter
213+
- [x] Implement all filter fields present in `gitcoinco/web/app/dashboard/router.py`
33214
- [ ] Add `universe` api filter
34215
- [ ] Implement all filter fields present in `gitcoinco/web/app/external_bounties/router.py`
35-
- [ ] Add sorting/order_by
36-
- [ ] Add pagination (page/limit)
216+
- [x] Add sorting/order_by
217+
- [x] Add pagination (page/limit)
37218
- [ ] Add travis-ci.com project and twine/pypi credentials.
38219
- [ ] Add codecov.io project.
39220
- [ ] Cut first release (Tag github release, push changes, and let CI deploy to pypi)

conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
4+
# see https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option
5+
def pytest_addoption(parser):
6+
parser.addoption('--liveapi', action='store_true',
7+
default=False, help='run some tests againts live API')

gitcoin/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Define the Gitcoin API client."""
2+
3+
from gitcoin.client import Config
4+
from gitcoin.client import BountyConfig
5+
from gitcoin.client import Endpoint
6+
from gitcoin.client import Gitcoin
7+
8+
__all__ = [
9+
'Config', 'BountyConfig', 'Endpoint', 'Gitcoin',
10+
]

0 commit comments

Comments
 (0)