Permalink
Browse files

Implement https://api.github.com/hooks (issue #35)

  • Loading branch information...
1 parent fb62ca3 commit b758b24bdb35c942b9d770c52493cffec0e0ac3b @jacquev6 jacquev6 committed Sep 8, 2012
@@ -1,6 +1,15 @@
{
"classes": [
{
+ "name": "HookDescription",
+ "attributes": [
+ { "name": "supported_events", "type": "list:string" },
+ { "name": "events", "type": "list:string" },
+ { "name": "name", "type": "string" },
+ { "name": "schema", "type": "list:list:string" }
+ ]
+ },
+ {
"name": "Plan",
"attributes": [
{ "name": "collaborators", "type": "integer" },
@@ -4291,6 +4291,45 @@
{
"type": {
"simple": true,
+ "cardinality": "list",
+ "name": "string"
+ },
+ "name": "events"
+ },
+ {
+ "type": {
+ "simple": true,
+ "cardinality": "scalar",
+ "name": "string"
+ },
+ "name": "name"
+ },
+ {
+ "type": {
+ "simple": false,
+ "cardinality": "list",
+ "name": "list:string"
+ },
+ "name": "schema"
+ },
+ {
+ "type": {
+ "simple": true,
+ "cardinality": "list",
+ "name": "string"
+ },
+ "name": "supported_events"
+ }
+ ],
+ "isCompletable": false,
+ "name": "HookDescription",
+ "methods": []
+ },
+ {
+ "attributes": [
+ {
+ "type": {
+ "simple": true,
"cardinality": "scalar",
"name": "integer"
},
View
@@ -53,6 +53,10 @@ API `/gists/starred`
====================
* GET: `AuthenticatedUser.get_starred_gists`
+API `/hooks`
+====================
+* GET: `Github.get_hooks`
+
API `/issues`
=============
* GET: `AuthenticatedUser.get_issues`
View
@@ -32,6 +32,7 @@ Methods
* `get_gist( id )`: `Gist`
* `id`: string
* `get_gists()`: iterator of `Gist`
+* `get_hooks()`: iterator of `HookDescription`
* `search_repos( keyword )`: iterator of `Repository`
* `legacy_search_repos( keyword, [language] )`: iterator of `Repository`
* `keyword`: string
@@ -642,6 +643,16 @@ Testing
-------
* `test()`
+Class `HookDescription`
+=======================
+
+Attributes
+----------
+* `events`: list of string
+* `name`: string
+* `schema`: list of list of string
+* `supported_events`: list of string
+
Class `HookResponse`
====================
View
@@ -22,6 +22,7 @@
import Repository
import Legacy
import GithubObject
+import HookDescription
DEFAULT_BASE_URL = "https://api.github.com"
DEFAULT_TIMEOUT = 10
@@ -126,3 +127,12 @@ def render_markdown( self, text, context = GithubObject.NotSet ):
post_parameters
)
return data
+
+ def get_hooks( self ):
+ headers, data = self.__requester.requestAndCheck(
+ "GET",
+ "/hooks",
+ None,
+ None
+ )
+ return [ HookDescription.HookDescription( self.__requester, attributes, completed = True ) for attributes in data ]
View
@@ -0,0 +1,54 @@
+# WARNING: this file is generated automaticaly.
+# Do not modify it manually, your work would be lost.
+
+# Copyright 2012 Vincent Jacques
+# vincent@vincent-jacques.net
+
+# This file is part of PyGithub. http://vincent-jacques.net/PyGithub
+
+# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public License along with PyGithub. If not, see <http://www.gnu.org/licenses/>.
+
+import GithubObject
+
+class HookDescription( GithubObject.BasicGithubObject ):
+ @property
+ def events( self ):
+ return self._NoneIfNotSet( self._events )
+
+ @property
+ def name( self ):
+ return self._NoneIfNotSet( self._name )
+
+ @property
+ def schema( self ):
+ return self._NoneIfNotSet( self._schema )
+
+ @property
+ def supported_events( self ):
+ return self._NoneIfNotSet( self._supported_events )
+
+ def _initAttributes( self ):
+ self._events = GithubObject.NotSet
+ self._name = GithubObject.NotSet
+ self._schema = GithubObject.NotSet
+ self._supported_events = GithubObject.NotSet
+
+ def _useAttributes( self, attributes ):
+ if "events" in attributes: # pragma no branch
+ assert attributes[ "events" ] is None or all( isinstance( element, ( str, unicode ) ) for element in attributes[ "events" ] ), attributes[ "events" ]
+ self._events = attributes[ "events" ]
+ if "name" in attributes: # pragma no branch
+ assert attributes[ "name" ] is None or isinstance( attributes[ "name" ], ( str, unicode ) ), attributes[ "name" ]
+ self._name = attributes[ "name" ]
+ if "schema" in attributes: # pragma no branch
+ assert attributes[ "schema" ] is None or all( isinstance( element, list ) for element in attributes[ "schema" ] ), attributes[ "schema" ]
+ self._schema = attributes[ "schema" ]
+ if "supported_events" in attributes: # pragma no branch
+ assert attributes[ "supported_events" ] is None or all( isinstance( element, ( str, unicode ) ) for element in attributes[ "supported_events" ] ), attributes[ "supported_events" ]
+ self._supported_events = attributes[ "supported_events" ]
View
@@ -41,3 +41,11 @@ def testLegacySearchUserByEmail( self ):
user = self.g.legacy_search_user_by_email( "vincent@vincent-jacques.net" )
self.assertEqual( user.login, "jacquev6" )
self.assertEqual( user.followers, 13 )
+
+ def testGetHooks( self ):
+ hooks = self.g.get_hooks()
+ hook = hooks[ 0 ]
+ self.assertEqual( hook.name, "activecollab" )
+ self.assertEqual( hook.supported_events, [ "push" ] )
+ self.assertEqual( hook.events, [ "push" ] )
+ self.assertEqual( hook.schema, [ [ "string", "url" ], [ "string", "token" ], [ "string", "project_id" ], [ "string", "milestone_id" ], [ "string", "category_id" ] ] )

Large diffs are not rendered by default.

Oops, something went wrong.

0 comments on commit b758b24

Please sign in to comment.