11# -*- coding: utf-8 -*-
2- """
3- github3.repos.hook
4- ==================
5-
6- This module contains only the Hook object for GitHub's Hook API.
7-
8- """
2+ """This module contains only the Hook object for GitHub's Hook API."""
93from __future__import unicode_literals
104
115from json import dumps
148
159
1610class Hook (GitHubCore ):
17- """The :class:`Hook <Hook>` object. This handles the information returned
18- by GitHub about hooks set on a repository.
11+ """The representation of a hook on a repository.
1912
20- Two hook instances can be checked like so::
13+ See also: http://developer.github.com/v3/repos/hooks/
2114
22- h1 == h2
23- h1 != h2
15+ This object has the following attributes:
2416
25- And is equivalent to::
17+ .. attribute:: active
2618
27- h1.id == h2.id
28- h1.id != h2.id
19+ A boolean attribute describing whether the hook is active or not.
2920
30- See also: http://developer.github.com/v3/repos/hooks/
31- """
32- def _update_attributes (self ,hook ,session = None ):
33- self ._api = self ._get_attribute (hook ,'url' )
21+ .. attribute:: config
22+
23+ A dictionary containing the configuration for this hook.
3424
35- #: datetime object representing when this hook was last updated.
36- self .updated_at = self ._strptime_attribute (hook ,'updated_at' )
25+ .. attribute:: created_at
3726
38- #: datetime object representing the datethe hook was created.
39- self . created_at = self . _strptime_attribute ( hook , 'created_at' )
27+ A :class:`~ datetime.datetime` object representing the dateand time
28+ when this hook was created.
4029
41- #: The name of the hook.
42- self .name = self ._get_attribute (hook ,'name' )
30+ .. attribute:: events
4331
44- #: Events which trigger the hook.
45- self .events = self ._get_attribute (hook ,'events' )
32+ The list of events which trigger this hook.
4633
47- #: Whether or not this Hook is marked as active on GitHub
48- self .active = self ._get_attribute (hook ,'active' )
34+ .. attribute:: id
4935
50- #: Dictionary containing the configuration for the Hook.
51- self .config = self ._get_attribute (hook ,'config' )
36+ The unique identifier for this hook.
5237
53- #: Unique id of the hook.
54- self .id = self ._get_attribute (hook ,'id' )
38+ .. attribute:: name
39+
40+ The name provided to this hook.
41+
42+ .. attribute:: updated_at
43+
44+ A :class:`~datetime.datetime` object representing the date and time
45+ when this hook was updated.
46+ """
47+
48+ def _update_attributes (self ,hook ,session = None ):
49+ self ._api = hook ['url' ]
50+ self .active = hook ['active' ]
51+ self .config = hook ['config' ]
52+ self .created_at = self ._strptime (hook ['created_at' ])
53+ self .events = hook ['events' ]
54+ self .id = hook ['id' ]
55+ self .name = hook ['name' ]
56+ self .updated_at = self ._strptime (hook ['updated_at' ])
5557
5658def _repr (self ):
5759return '<Hook [{0}]>' .format (self .name )
@@ -60,7 +62,10 @@ def _repr(self):
6062def delete (self ):
6163"""Delete this hook.
6264
63- :returns: bool
65+ :returns:
66+ True if successful, False otherwise
67+ :rtype:
68+ bool
6469 """
6570return self ._boolean (self ._delete (self ._api ),204 ,404 )
6671
@@ -69,16 +74,22 @@ def edit(self, config={}, events=[], add_events=[], rm_events=[],
6974active = True ):
7075"""Edit this hook.
7176
72- :param dict config: (optional), key-value pairs of settings for this
73- hook
74- :param list events: (optional), which events should this be triggered
75- for
76- :param list add_events: (optional), events to be added to the list of
77- events that this hook triggers for
78- :param list rm_events: (optional), events to be removed from the list
79- of events that this hook triggers for
80- :param bool active: (optional), should this event be active
81- :returns: bool
77+ :param dict config:
78+ (optional), key-value pairs of settings for this hook
79+ :param list events:
80+ (optional), which events should this be triggered for
81+ :param list add_events:
82+ (optional), events to be added to the list of events that this hook
83+ triggers for
84+ :param list rm_events:
85+ (optional), events to be removed from the list of events that this
86+ hook triggers for
87+ :param bool active:
88+ (optional), should this event be active
89+ :returns:
90+ True if successful, False otherwise
91+ :rtype:
92+ bool
8293 """
8394data = {'config' :config ,'active' :active }
8495if events :
@@ -102,16 +113,22 @@ def edit(self, config={}, events=[], add_events=[], rm_events=[],
102113def ping (self ):
103114"""Ping this hook.
104115
105- :returns: bool
116+ :returns:
117+ True if successful, False otherwise
118+ :rtype:
119+ bool
106120 """
107121url = self ._build_url ('pings' ,base_url = self ._api )
108122return self ._boolean (self ._post (url ),204 ,404 )
109123
110124@requires_auth
111125def test (self ):
112- """Test this hook
126+ """Test this hook.
113127
114- :returns: bool
128+ :returns:
129+ True if successful, False otherwise
130+ :rtype:
131+ bool
115132 """
116133url = self ._build_url ('tests' ,base_url = self ._api )
117134return self ._boolean (self ._post (url ),204 ,404 )