-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-cli.py
More file actions
58 lines (51 loc) · 1.68 KB
/
Copy pathapp-cli.py
File metadata and controls
58 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from rauth import OAuth2Service
import json
nation_slug = "pointblankdev"
oauth_id = "69c795c86f160f200db75597ca9b9a3e82ef8980769056802d7826d682289fa7"
oauth_secret = "29690408c988744532cc94245b5081cfb55955c23ebfea17ad7d09e357d86f7c"
redirect_uri = "https://pointblankdev.nationbuilder.com/oauth_callback"
code ="c921f8957408faf2bc262d2d54dd902e312e8e1d88680e19cc3fc37329602de0"
access_token_url = "http://" + nation_slug + ".nationbuilder.com/oauth/token"
authorize_url = nation_slug + ".nationbuilder.com/oauth/authorize"
service = OAuth2Service(
client_id = oauth_id,
client_secret = oauth_secret,
name = "First_app",
authorize_url = authorize_url,
access_token_url = access_token_url,
base_url = nation_slug + ".nationbuilder.com")
token = service.get_access_token(
decoder=json.loads,
data = {
"code": code,
"redirect_uri": redirect_uri,
"grant_type": "authorization_code"}
)
session = service.get_session(token)
response = session.get(
"https://"+nation_slug+".nationbuilder.com/api/v1/people",
params={'format': 'json'},
headers={'content-type': 'application/json'}
)
#actual work
# create a person
create_person = {
"person": {
"last_name": "Snow",
"first_name": "Jane",
"email": "jane@danorf.ca",
"sex": "F",
"signup_type": 0,
"employer": "Free Folk Inc",
"party": "C",
"registered_address": {
"state": "BC",
"country_code": "CA"
}
}
}
response = session.post(
"https://" + nation_slug + ".nationbuilder.com/api/v1/people",
params={'format': 'json', 'person': create_person},
headers={'content-type': 'application/json'}
)