From ca6e7ef9ce22dc01290bb59507f24cc17f42daa4 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Tue, 29 May 2012 19:00:57 +0100 Subject: [PATCH] Automatic implementation of url_parameters --- .../GithubObject.MethodBody.DoRequest.py | 18 ++++++-- src/github/AuthenticatedUser.py | 8 ++-- src/github/Authorization.py | 3 +- src/github/Gist.py | 3 +- src/github/Issue.py | 3 +- src/github/NamedUser.py | 5 ++- src/github/Organization.py | 8 ++-- src/github/PullRequest.py | 6 +-- src/github/Repository.py | 42 ++++++++++++++++--- src/github/RepositoryKey.py | 3 +- src/github/UserKey.py | 3 +- 11 files changed, 71 insertions(+), 31 deletions(-) diff --git a/codegen/templates/GithubObject.MethodBody.DoRequest.py b/codegen/templates/GithubObject.MethodBody.DoRequest.py index 0c4279c4..de3d37f4 100644 --- a/codegen/templates/GithubObject.MethodBody.DoRequest.py +++ b/codegen/templates/GithubObject.MethodBody.DoRequest.py @@ -6,16 +6,28 @@ post_parameters = [ {{ method.variadicParameter.name }}._identity for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ] {% endif %} {% else %} + {% if method.mandatoryParameters %} post_parameters = { - {% for parameter in method.mandatoryParameters %} + {% for parameter in method.mandatoryParameters %} "{{ parameter.name }}": {{ parameter.name }}, - {% endfor %} + {% endfor %} } + {% else %} + post_parameters = dict() + {% endif %} {% for parameter in method.optionalParameters %} if {{ parameter.name }} is not DefaultValueForOptionalParameters: post_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }} {% endfor %} {% endif %} +{% else %} + {% if method.optionalParameters %} + url_parameters = dict() + {% for parameter in method.optionalParameters %} + if {{ parameter.name }} is not DefaultValueForOptionalParameters: + url_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }} + {% endfor %} + {% endif %} {% endif %} {% if method.request.urlParameters %} @@ -29,7 +41,7 @@ status, headers, data = self.__requester.request( "{{ method.request.verb }}", {% include "GithubObject.Concatenation.py" with concatenation=method.request.url only %}, -{% if method.request.urlParameters %} +{% if method.request.urlParameters or not method.request.postParameters and method.optionalParameters %} url_parameters, {% else %} None, diff --git a/src/github/AuthenticatedUser.py b/src/github/AuthenticatedUser.py index 2cff315f..3f3706c8 100644 --- a/src/github/AuthenticatedUser.py +++ b/src/github/AuthenticatedUser.py @@ -182,8 +182,7 @@ class AuthenticatedUser( object ): assert isinstance( note, ( str, unicode ) ), note if note_url is not DefaultValueForOptionalParameters: assert isinstance( note_url, ( str, unicode ) ), note_url - post_parameters = { - } + post_parameters = dict() if scopes is not DefaultValueForOptionalParameters: post_parameters[ "scopes" ] = scopes if note is not DefaultValueForOptionalParameters: @@ -293,8 +292,7 @@ class AuthenticatedUser( object ): assert isinstance( hireable, bool ), hireable if bio is not DefaultValueForOptionalParameters: assert isinstance( bio, ( str, unicode ) ), bio - post_parameters = { - } + post_parameters = dict() if name is not DefaultValueForOptionalParameters: post_parameters[ "name" ] = name if email is not DefaultValueForOptionalParameters: @@ -486,7 +484,7 @@ class AuthenticatedUser( object ): def get_repos( self, type = DefaultValueForOptionalParameters ): if type is not DefaultValueForOptionalParameters: assert isinstance( type, ( str, unicode ) ), type - url_parameters = {} + url_parameters = dict() if type is not DefaultValueForOptionalParameters: url_parameters[ "type" ] = type status, headers, data = self.__requester.request( diff --git a/src/github/Authorization.py b/src/github/Authorization.py index 1f482e5b..9bbef2c4 100644 --- a/src/github/Authorization.py +++ b/src/github/Authorization.py @@ -77,8 +77,7 @@ class Authorization( object ): assert isinstance( note, ( str, unicode ) ), note if note_url is not DefaultValueForOptionalParameters: assert isinstance( note_url, ( str, unicode ) ), note_url - post_parameters = { - } + post_parameters = dict() if scopes is not DefaultValueForOptionalParameters: post_parameters[ "scopes" ] = scopes if add_scopes is not DefaultValueForOptionalParameters: diff --git a/src/github/Gist.py b/src/github/Gist.py index 80fccd8b..75d50b15 100644 --- a/src/github/Gist.py +++ b/src/github/Gist.py @@ -125,8 +125,7 @@ class Gist( object ): def edit( self, description = DefaultValueForOptionalParameters, files = DefaultValueForOptionalParameters ): if description is not DefaultValueForOptionalParameters: assert isinstance( description, ( str, unicode ) ), description - post_parameters = { - } + post_parameters = dict() if description is not DefaultValueForOptionalParameters: post_parameters[ "description" ] = description if files is not DefaultValueForOptionalParameters: diff --git a/src/github/Issue.py b/src/github/Issue.py index 500eeb8a..07d29272 100644 --- a/src/github/Issue.py +++ b/src/github/Issue.py @@ -153,8 +153,7 @@ class Issue( object ): assert isinstance( milestone, int ), milestone if labels is not DefaultValueForOptionalParameters: assert isinstance( labels, list ) and ( len( labels ) == 0 or isinstance( labels[ 0 ], ( str, unicode ) ) ), labels - post_parameters = { - } + post_parameters = dict() if title is not DefaultValueForOptionalParameters: post_parameters[ "title" ] = title if body is not DefaultValueForOptionalParameters: diff --git a/src/github/NamedUser.py b/src/github/NamedUser.py index 5a9d51c4..2c41af1d 100644 --- a/src/github/NamedUser.py +++ b/src/github/NamedUser.py @@ -292,10 +292,13 @@ class NamedUser( object ): def get_repos( self, type = DefaultValueForOptionalParameters ): if type is not DefaultValueForOptionalParameters: assert isinstance( type, ( str, unicode ) ), type + url_parameters = dict() + if type is not DefaultValueForOptionalParameters: + url_parameters[ "type" ] = type status, headers, data = self.__requester.request( "GET", str( self.url ) + "/repos", - None, + url_parameters, None ) return PaginatedList.PaginatedList( diff --git a/src/github/Organization.py b/src/github/Organization.py index 59b9ffff..e24c2125 100644 --- a/src/github/Organization.py +++ b/src/github/Organization.py @@ -235,8 +235,7 @@ class Organization( object ): assert isinstance( location, ( str, unicode ) ), location if name is not DefaultValueForOptionalParameters: assert isinstance( name, ( str, unicode ) ), name - post_parameters = { - } + post_parameters = dict() if billing_email is not DefaultValueForOptionalParameters: post_parameters[ "billing_email" ] = billing_email if blog is not DefaultValueForOptionalParameters: @@ -312,10 +311,13 @@ class Organization( object ): def get_repos( self, type = DefaultValueForOptionalParameters ): if type is not DefaultValueForOptionalParameters: assert isinstance( type, ( str, unicode ) ), type + url_parameters = dict() + if type is not DefaultValueForOptionalParameters: + url_parameters[ "type" ] = type status, headers, data = self.__requester.request( "GET", str( self.url ) + "/repos", - None, + url_parameters, None ) return PaginatedList.PaginatedList( diff --git a/src/github/PullRequest.py b/src/github/PullRequest.py index e4458514..1ab7e832 100644 --- a/src/github/PullRequest.py +++ b/src/github/PullRequest.py @@ -173,8 +173,7 @@ class PullRequest( object ): assert isinstance( body, ( str, unicode ) ), body if state is not DefaultValueForOptionalParameters: assert isinstance( state, ( str, unicode ) ), state - post_parameters = { - } + post_parameters = dict() if title is not DefaultValueForOptionalParameters: post_parameters[ "title" ] = title if body is not DefaultValueForOptionalParameters: @@ -253,8 +252,7 @@ class PullRequest( object ): def merge( self, commit_message = DefaultValueForOptionalParameters ): if commit_message is not DefaultValueForOptionalParameters: assert isinstance( commit_message, ( str, unicode ) ), commit_message - post_parameters = { - } + post_parameters = dict() if commit_message is not DefaultValueForOptionalParameters: post_parameters[ "commit_message" ] = commit_message status, headers, data = self.__requester.request( diff --git a/src/github/Repository.py b/src/github/Repository.py index 67f49301..8bf4e562 100644 --- a/src/github/Repository.py +++ b/src/github/Repository.py @@ -550,10 +550,15 @@ class Repository( object ): assert isinstance( sha, ( str, unicode ) ), sha if path is not DefaultValueForOptionalParameters: assert isinstance( path, ( str, unicode ) ), path + url_parameters = dict() + if sha is not DefaultValueForOptionalParameters: + url_parameters[ "sha" ] = sha + if path is not DefaultValueForOptionalParameters: + url_parameters[ "path" ] = path status, headers, data = self.__requester.request( "GET", str( self.url ) + "/commits", - None, + url_parameters, None ) return PaginatedList.PaginatedList( @@ -687,7 +692,7 @@ class Repository( object ): assert isinstance( sha, ( str, unicode ) ), sha if recursive is not DefaultValueForOptionalParameters: assert isinstance( recursive, bool ), recursive - url_parameters = {} + url_parameters = dict() if recursive is not DefaultValueForOptionalParameters: url_parameters[ "recursive" ] = recursive status, headers, data = self.__requester.request( @@ -749,10 +754,27 @@ class Repository( object ): assert isinstance( direction, ( str, unicode ) ), direction if since is not DefaultValueForOptionalParameters: assert isinstance( since, ( str, unicode ) ), since + url_parameters = dict() + if milestone is not DefaultValueForOptionalParameters: + url_parameters[ "milestone" ] = milestone + if state is not DefaultValueForOptionalParameters: + url_parameters[ "state" ] = state + if assignee is not DefaultValueForOptionalParameters: + url_parameters[ "assignee" ] = assignee + if mentioned is not DefaultValueForOptionalParameters: + url_parameters[ "mentioned" ] = mentioned + if labels is not DefaultValueForOptionalParameters: + url_parameters[ "labels" ] = labels + if sort is not DefaultValueForOptionalParameters: + url_parameters[ "sort" ] = sort + if direction is not DefaultValueForOptionalParameters: + url_parameters[ "direction" ] = direction + if since is not DefaultValueForOptionalParameters: + url_parameters[ "since" ] = since status, headers, data = self.__requester.request( "GET", str( self.url ) + "/issues", - None, + url_parameters, None ) return PaginatedList.PaginatedList( @@ -860,10 +882,17 @@ class Repository( object ): assert isinstance( sort, ( str, unicode ) ), sort if direction is not DefaultValueForOptionalParameters: assert isinstance( direction, ( str, unicode ) ), direction + url_parameters = dict() + if state is not DefaultValueForOptionalParameters: + url_parameters[ "state" ] = state + if sort is not DefaultValueForOptionalParameters: + url_parameters[ "sort" ] = sort + if direction is not DefaultValueForOptionalParameters: + url_parameters[ "direction" ] = direction status, headers, data = self.__requester.request( "GET", str( self.url ) + "/milestones", - None, + url_parameters, None ) return PaginatedList.PaginatedList( @@ -900,10 +929,13 @@ class Repository( object ): def get_pulls( self, state = DefaultValueForOptionalParameters ): if state is not DefaultValueForOptionalParameters: assert isinstance( state, ( str, unicode ) ), state + url_parameters = dict() + if state is not DefaultValueForOptionalParameters: + url_parameters[ "state" ] = state status, headers, data = self.__requester.request( "GET", str( self.url ) + "/pulls", - None, + url_parameters, None ) return PaginatedList.PaginatedList( diff --git a/src/github/RepositoryKey.py b/src/github/RepositoryKey.py index 627fba5c..c97c38ed 100644 --- a/src/github/RepositoryKey.py +++ b/src/github/RepositoryKey.py @@ -56,8 +56,7 @@ class RepositoryKey( object ): assert isinstance( title, ( str, unicode ) ), title if key is not DefaultValueForOptionalParameters: assert isinstance( key, ( str, unicode ) ), key - post_parameters = { - } + post_parameters = dict() if title is not DefaultValueForOptionalParameters: post_parameters[ "title" ] = title if key is not DefaultValueForOptionalParameters: diff --git a/src/github/UserKey.py b/src/github/UserKey.py index 4205bb3c..6f3af7ec 100644 --- a/src/github/UserKey.py +++ b/src/github/UserKey.py @@ -51,8 +51,7 @@ class UserKey( object ): assert isinstance( title, ( str, unicode ) ), title if key is not DefaultValueForOptionalParameters: assert isinstance( key, ( str, unicode ) ), key - post_parameters = { - } + post_parameters = dict() if title is not DefaultValueForOptionalParameters: post_parameters[ "title" ] = title if key is not DefaultValueForOptionalParameters: