1818from __future__ import print_function
1919from __future__ import absolute_import
2020import base64
21- import json
2221
2322import six
2423
@@ -1573,14 +1572,14 @@ class ProjectVariableManager(CRUDMixin, RESTManager):
15731572 _update_attrs = (('key' , 'value' ), tuple ())
15741573
15751574
1576- class ProjectService (GitlabObject ):
1577- _url = '/projects/%(project_id)s/services/%(service_name)s'
1578- canList = False
1579- canCreate = False
1580- _id_in_update_url = False
1581- _id_in_delete_url = False
1582- getRequiresId = False
1583- requiredUrlAttrs = [ 'project_id' , 'service_name' ]
1575+ class ProjectService (SaveMixin , ObjectDeleteMixin , RESTObject ):
1576+ pass
1577+
1578+
1579+ class ProjectServiceManager ( GetMixin , UpdateMixin , DeleteMixin , RESTManager ):
1580+ _path = '/projects/%(project_id)s/services'
1581+ _from_parent_attrs = { 'project_id' : 'id' }
1582+ _obj_cls = ProjectService
15841583
15851584 _service_attrs = {
15861585 'asana' : (('api_key' , ), ('restrict_to_branch' , )),
@@ -1606,16 +1605,10 @@ class ProjectService(GitlabObject):
16061605 'server' )),
16071606 'irker' : (('recipients' , ), ('default_irc_uri' , 'server_port' ,
16081607 'server_host' , 'colorize_messages' )),
1609- 'jira' : (tuple (), (
1610- # Required fields in GitLab >= 8.14
1611- 'url' , 'project_key' ,
1612-
1613- # Required fields in GitLab < 8.14
1614- 'new_issue_url' , 'project_url' , 'issues_url' , 'api_url' ,
1615- 'description' ,
1616-
1617- # Optional fields
1618- 'username' , 'password' , 'jira_issue_transition_id' )),
1608+ 'jira' : (('url' , 'project_key' ),
1609+ ('new_issue_url' , 'project_url' , 'issues_url' , 'api_url' ,
1610+ 'description' , 'username' , 'password' ,
1611+ 'jira_issue_transition_id' )),
16191612 'pivotaltracker' : (('token' , ), tuple ()),
16201613 'pushover' : (('api_key' , 'user_key' , 'priority' ), ('device' , 'sound' )),
16211614 'redmine' : (('new_issue_url' , 'project_url' , 'issues_url' ),
@@ -1625,41 +1618,52 @@ class ProjectService(GitlabObject):
16251618 tuple ())
16261619 }
16271620
1628- def _data_for_gitlab (self , extra_parameters = {}, update = False ,
1629- as_json = True ):
1630- data = (super (ProjectService , self )
1631- ._data_for_gitlab (extra_parameters , update = update ,
1632- as_json = False ))
1633- missing = []
1634- # Mandatory args
1635- for attr in self ._service_attrs [self .service_name ][0 ]:
1636- if not hasattr (self , attr ):
1637- missing .append (attr )
1638- else :
1639- data [attr ] = getattr (self , attr )
1621+ def get (self , id , ** kwargs ):
1622+ """Retrieve a single object.
16401623
1641- if missing :
1642- raise GitlabUpdateError ('Missing attribute(s): %s' %
1643- ", " .join (missing ))
1624+ Args:
1625+ id (int or str): ID of the object to retrieve
1626+ lazy (bool): If True, don't request the server, but create a
1627+ shallow object giving access to the managers. This is
1628+ useful if you want to avoid useless calls to the API.
1629+ **kwargs: Extra options to send to the Gitlab server (e.g. sudo)
16441630
1645- # Optional args
1646- for attr in self ._service_attrs [self .service_name ][1 ]:
1647- if hasattr (self , attr ):
1648- data [attr ] = getattr (self , attr )
1631+ Returns:
1632+ object: The generated RESTObject.
16491633
1650- return json .dumps (data )
1634+ Raises:
1635+ GitlabAuthenticationError: If authentication is not correct
1636+ GitlabGetError: If the server cannot perform the request
1637+ """
1638+ obj = super (ProjectServiceManager , self ).get (id , ** kwargs )
1639+ obj .id = id
1640+ return obj
1641+
1642+ def update (self , id = None , new_data = {}, ** kwargs ):
1643+ """Update an object on the server.
1644+
1645+ Args:
1646+ id: ID of the object to update (can be None if not required)
1647+ new_data: the update data for the object
1648+ **kwargs: Extra options to send to the Gitlab server (e.g. sudo)
16511649
1650+ Returns:
1651+ dict: The new object data (*not* a RESTObject)
16521652
1653- class ProjectServiceManager (BaseManager ):
1654- obj_cls = ProjectService
1653+ Raises:
1654+ GitlabAuthenticationError: If authentication is not correct
1655+ GitlabUpdateError: If the server cannot perform the request
1656+ """
1657+ super (ProjectServiceManager , self ).update (id , new_data , ** kwargs )
1658+ self .id = id
16551659
16561660 def available (self , ** kwargs ):
16571661 """List the services known by python-gitlab.
16581662
16591663 Returns:
16601664 list (str): The list of service code names.
16611665 """
1662- return list (ProjectService ._service_attrs .keys ())
1666+ return list (self ._service_attrs .keys ())
16631667
16641668
16651669class ProjectAccessRequest (AccessRequestMixin , ObjectDeleteMixin , RESTObject ):
0 commit comments