Skip to content

Commit dbf7b69

Browse files
committed
Add changes to the Authoriztaions API.
Authorizations change - 27e8e0d1373870d20fbf1fbc7dacaf908510a507 Also, accurately track User-Agent via version number.
1 parent f7ff568 commit dbf7b69

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

github3/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
gh = GitHub()
1313

1414

15-
def authorize(login, password, scopes, note='', note_url=''):
15+
def authorize(login, password, scopes, note='', note_url='', client_id='',
16+
client_secret=''):
1617
"""Obtain an authorization token from the GitHub API for the GitHub
1718
API.
1819
@@ -22,6 +23,10 @@ def authorize(login, password, scopes, note='', note_url=''):
2223
i.e., 'gist', 'user'
2324
:param str note: (optional), note about the authorization
2425
:param str note_url: (optional), url for the application
26+
:param str client_id: (optional), 20 character OAuth client key for which
27+
to create a token
28+
:param str client_secret: (optional), 40 character OAuth client secret for
29+
which to create the token
2530
:returns: :class:`Authorization <Authorization>`
2631
"""
2732
return gh.authorize(login, password, scopes, note, note_url)

github3/github.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def authorization(self, id_num):
7777
json = self._json(self._get(url), 200)
7878
return Authorization(json, self) if json else None
7979

80-
def authorize(self, login, password, scopes, note='', note_url=''):
80+
def authorize(self, login, password, scopes, note='', note_url='',
81+
client_id='', client_secret=''):
8182
"""Obtain an authorization token from the GitHub API for the GitHub
8283
API.
8384
@@ -87,14 +88,18 @@ def authorize(self, login, password, scopes, note='', note_url=''):
8788
i.e., 'gist', 'user'
8889
:param str note: (optional), note about the authorization
8990
:param str note_url: (optional), url for the application
91+
:param str client_id: (optional), 20 character OAuth client key for
92+
which to create a token
93+
:param str client_secret: (optional), 40 character OAuth client secret
94+
for which to create the token
9095
:returns: :class:`Authorization <Authorization>`
9196
"""
9297
json = None
9398
auth = self._session.auth or (login and password)
9499
if isinstance(scopes, list) and auth:
95100
url = self._build_url('authorizations')
96-
data = {'scopes': scopes, 'note': note,
97-
'note_url': note_url}
101+
data = {'scopes': scopes, 'note': note, 'note_url': note_url,
102+
'client_id': client_id, 'client_secret': client_secret}
98103
if self._session.auth:
99104
json = self._json(self._post(url, data=data), 201)
100105
else:

github3/models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from requests.compat import urlparse
1212
from github3.decorators import requires_auth
1313
from github3.packages.PySO8601 import parse
14+
from github3 import __version__
1415

1516
__url_cache__ = {}
1617

@@ -37,11 +38,6 @@ def from_json(cls, json):
3738
return cls(json)
3839

3940

40-
def json_hook(args):
41-
if args.get('data') and not args.get('files'):
42-
args['data'] = dumps(args['data'])
43-
44-
4541
class GitHubCore(GitHubObject):
4642
"""The :class:`GitHubCore <GitHubCore>` object. This class provides some
4743
basic attributes to other classes that are very useful to have.
@@ -62,9 +58,14 @@ def __init__(self, json, ses=None):
6258
# Always sending JSON
6359
'Content-Type': "application/json",
6460
# Set our own custom User-Agent string
65-
'User-Agent': 'github3.py/0.1b0',
61+
'User-Agent': 'github3.py/{0}'.format(__version__),
6662
}
6763

64+
# Requests hook
65+
def json_hook(args):
66+
if args.get('data') and not args.get('files'):
67+
args['data'] = dumps(args['data'])
68+
6869
self._session.headers.update(headers)
6970
self._session.config['base_headers'].update(headers)
7071
self._session.hooks.update({'args': [json_hook]})

0 commit comments

Comments
 (0)