Skip to content

Commit 21e2d1d

Browse files
authored
Merge pull request #44 from osmlab/dev
Merging dev > master
2 parents 00e78ea + 31bd947 commit 21e2d1d

18 files changed

Lines changed: 626 additions & 21 deletions

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# MapRoulette - A Python Client for the MapRoulette API
22

3-
https://maproulette-python-client.readthedocs.io/
3+
4+
https://maproulette-python-client.readthedocs.io
5+
6+
[![PyPI version](https://badge.fury.io/py/maproulette.svg)](https://badge.fury.io/py/maproulette)
7+
[![Build Status](https://travis-ci.com/osmlab/maproulette-python-client.svg?branch=master)](https://travis-ci.com/osmlab/maproulette-python-client)
48

59
This client makes it easy for users to communicate with the MapRoulette API from within
610
their Python environment. In the example below, we are able to access a MapRoulette project in just four lines of code:

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Welcome to MapRoulette's documentation!
1717
usage/models/project
1818
usage/models/challenge
1919
usage/models/task
20+
usage/models/priority_rule
2021
usage/exceptions
2122

2223
---------------

docs/usage/functionality.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Module: task
2222
:members:
2323
:show-inheritance:
2424

25+
Module: user
26+
-----------------------------------------------------
27+
28+
.. automodule:: maproulette.api.user
29+
:members:
30+
:show-inheritance:
31+
2532
Module: configuration
2633
-----------------------------------------------------
2734

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Priority Rule Model
2+
=====================================================
3+
4+
.. autoclass:: maproulette.models.priority_rule.PriorityRule
5+
:members:
6+
7+
.. autoclass:: maproulette.models.priority_rule.PriorityRuleModel
8+
:members:
9+
10+
.. autoclass:: maproulette.models.priority_rule.Conditions
11+
:members:
12+
13+
.. autoclass:: maproulette.models.priority_rule.Types
14+
:members:
15+
:undoc-members:
16+
17+
.. autoclass:: maproulette.models.priority_rule.Conditions
18+
:members:
19+
:undoc-members:
20+
21+
.. autoclass:: maproulette.models.priority_rule.StringOperators
22+
:members:
23+
:undoc-members:
24+
25+
.. autoclass:: maproulette.models.priority_rule.NumericOperators
26+
:members:
27+
:undoc-members:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import maproulette
2+
import json
3+
4+
# Create a configuration object using a url and API key
5+
config = maproulette.Configuration(api_key='{YOUR_API_KEY}')
6+
7+
# Create an API object using your config object
8+
api = maproulette.User(config)
9+
10+
# Specify the user IDs to grant privileges to
11+
user_ids = [123, 456, 789]
12+
13+
# Specify the project ID to update the privileges for
14+
project_id = '147'
15+
16+
# Specify what level of access you want to grant this user (1 - Admin, 2 - Write, 3 - Read)
17+
group = '2'
18+
19+
# Print the API response
20+
print(json.dumps(api.add_user_list_to_project(user_ids=user_ids,
21+
project_id=project_id,
22+
group_type=group), indent=4, sort_keys=True))

examples/add_user_to_project.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import maproulette
2+
import json
3+
4+
# Create a configuration object using a url and API key
5+
config = maproulette.Configuration(api_key='{YOUR_API_KEY}')
6+
7+
# Create an API object using your config object
8+
api = maproulette.User(config)
9+
10+
# Specify the user ID to grant privileges to
11+
user_id = '{SOME_USER_ID}'
12+
13+
# Specify the project ID to update the privileges for
14+
project_id = '{YOUR_PROJECT_ID}'
15+
16+
# Specify what level of access you want to grant this user (1 - Admin, 2 - Write, 3 - Read)
17+
group = '2'
18+
19+
# Print the API response
20+
print(json.dumps(api.add_user_to_project(user_id=user_id,
21+
project_id=project_id,
22+
group_type=group), indent=4, sort_keys=True))

examples/create_challenge_from_model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
# Adding required instruction
1717
challenge_data.instruction = "Do something"
1818

19+
# Let's create a basic rule to classify features with tags 'highway' = 'footway' to be high priority
20+
rule_1 = maproulette.PriorityRule(priority_value='highway.footway',
21+
priority_type=maproulette.priority_rule.Types.STRING,
22+
priority_operator=maproulette.priority_rule.StringOperators.EQUAL)
23+
24+
# Create a formal priority rule for the challenge
25+
challenge_data.high_priority_rule = maproulette.PriorityRuleModel(condition=maproulette.priority_rule.Conditions.OR,
26+
rules=rule_1
27+
).to_json()
28+
1929
# Adding example overpass QL input for challenge
2030
challenge_data.overpassQL = open('data/Example_OverpassQL_Query', 'r').read()
2131

examples/find_user_by_username.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import maproulette
2+
import json
3+
4+
# Create a configuration object using a url and API key
5+
config = maproulette.Configuration(api_key='{YOUR_API_KEY}')
6+
7+
# Create an API object using your config object
8+
api = maproulette.User(config)
9+
10+
# We want to fetch a user with a particular name
11+
username = '{YOUR_USERNAME}'
12+
13+
# Print the API response
14+
print(json.dumps(api.find_user_by_username(username), indent=4, sort_keys=True))

maproulette/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from .models.project import ProjectModel
88
from .models.challenge import ChallengeModel
99
from .models.task import TaskModel
10+
from .models.priority_rule import PriorityRule, PriorityRuleModel
11+
from .models import priority_rule
1012
from .api.project import Project
1113
from .api.challenge import Challenge
1214
from .api.task import Task
1315
from .api.user import User
1416

15-
__version__ = '1.0.0'
17+
__version__ = '1.1.0'

maproulette/api/maproulette_server.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def get(self, endpoint, params=None):
5757
"""
5858
response = self.session.get(
5959
self.url + endpoint,
60-
params=params)
60+
params=params
61+
)
6162
try:
6263
response.raise_for_status()
6364
except requests.exceptions.HTTPError as e:
@@ -89,16 +90,19 @@ def get(self, endpoint, params=None):
8990
"status": response.status_code
9091
}
9192

92-
def post(self, endpoint, body=None):
93+
def post(self, endpoint, body=None, params=None):
9394
"""Method that completes a POST request to the MapRoulette API
9495
9596
:param endpoint: the server endpoint to use for the POST request
9697
:param body: the body of the request (optional)
98+
:param params: the parameters that pertain to the request (optional)
9799
:returns: a JSON object containing the API response
98100
"""
99101
response = self.session.post(
100102
self.url + endpoint,
101-
json=body)
103+
params=params,
104+
json=body
105+
)
102106
try:
103107
response.raise_for_status()
104108
except requests.exceptions.HTTPError as e:
@@ -132,16 +136,19 @@ def post(self, endpoint, body=None):
132136
"status": response.status_code
133137
}
134138

135-
def put(self, endpoint, body=None):
139+
def put(self, endpoint, body=None, params=None):
136140
"""Method that completes a PUT request to the MapRoulette API
137141
138142
:param endpoint: the server endpoint to use for the PUT request
139143
:param body: the body of the request (optional)
144+
:param params: the parameters that pertain to the request (optional)
140145
:returns: a JSON object containing the response code and the API response if
141146
"""
142147
response = self.session.put(
143148
self.url + endpoint,
144-
json=body)
149+
params=params,
150+
json=body
151+
)
145152
try:
146153
response.raise_for_status()
147154
except requests.exceptions.HTTPError as e:

0 commit comments

Comments
 (0)