Commits

Ian Cordasco  committed dbf7b69

Add changes to the Authoriztaions API.

Authorizations change - 27e8e0d1373870d20fbf1fbc7dacaf908510a507
Also, accurately track User-Agent via version number.

  • Participants
  • Parent commits f7ff568

Comments (0)

Files changed (3)

File github3/api.py

 gh = GitHub()
 
 
-def authorize(login, password, scopes, note='', note_url=''):
+def authorize(login, password, scopes, note='', note_url='', client_id='',
+              client_secret=''):
     """Obtain an authorization token from the GitHub API for the GitHub
     API.
 
         i.e., 'gist', 'user'
     :param str note: (optional), note about the authorization
     :param str note_url: (optional), url for the application
+    :param str client_id: (optional), 20 character OAuth client key for which
+        to create a token
+    :param str client_secret: (optional), 40 character OAuth client secret for
+        which to create the token
     :returns: :class:`Authorization <Authorization>`
     """
     return gh.authorize(login, password, scopes, note, note_url)

File github3/github.py

             json = self._json(self._get(url), 200)
         return Authorization(json, self) if json else None
 
-    def authorize(self, login, password, scopes, note='', note_url=''):
+    def authorize(self, login, password, scopes, note='', note_url='',
+                  client_id='', client_secret=''):
         """Obtain an authorization token from the GitHub API for the GitHub
         API.
 
             i.e., 'gist', 'user'
         :param str note: (optional), note about the authorization
         :param str note_url: (optional), url for the application
+        :param str client_id: (optional), 20 character OAuth client key for
+            which to create a token
+        :param str client_secret: (optional), 40 character OAuth client secret
+            for which to create the token
         :returns: :class:`Authorization <Authorization>`
         """
         json = None
         auth = self._session.auth or (login and password)
         if isinstance(scopes, list) and auth:
             url = self._build_url('authorizations')
-            data = {'scopes': scopes, 'note': note,
-                    'note_url': note_url}
+            data = {'scopes': scopes, 'note': note, 'note_url': note_url,
+                    'client_id': client_id, 'client_secret': client_secret}
             if self._session.auth:
                 json = self._json(self._post(url, data=data), 201)
             else:

File github3/models.py

 from requests.compat import urlparse
 from github3.decorators import requires_auth
 from github3.packages.PySO8601 import parse
+from github3 import __version__
 
 __url_cache__ = {}
 
         return cls(json)
 
 
-def json_hook(args):
-    if args.get('data') and not args.get('files'):
-        args['data'] = dumps(args['data'])
-
-
 class GitHubCore(GitHubObject):
     """The :class:`GitHubCore <GitHubCore>` object. This class provides some
     basic attributes to other classes that are very useful to have.
             # Always sending JSON
             'Content-Type': "application/json",
             # Set our own custom User-Agent string
-            'User-Agent': 'github3.py/0.1b0',
+            'User-Agent': 'github3.py/{0}'.format(__version__),
         }
 
+        # Requests hook
+        def json_hook(args):
+            if args.get('data') and not args.get('files'):
+                args['data'] = dumps(args['data'])
+
         self._session.headers.update(headers)
         self._session.config['base_headers'].update(headers)
         self._session.hooks.update({'args': [json_hook]})