Skip to content

Commit 3e551e6

Browse files
committed
Gists service done
2 parents 11e9410 + 673686f commit 3e551e6

File tree

14 files changed

+588
-13
lines changed

14 files changed

+588
-13
lines changed

docs/gists.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _Gists service:
2+
3+
Gists services
4+
===============
5+
6+
**Fast sample**::
7+
8+
from pygithub3 import Github
9+
10+
auth = dict(login='octocat', password='pass')
11+
gh = Github(**auth)
12+
13+
octocat_gists = gh.gists.list()
14+
the_first_gist = gh.gists.get(1)
15+
16+
the_first_gist_comments = gh.gists.comments.list(1)
17+
18+
Gist
19+
-----
20+
21+
.. autoclass:: pygithub3.services.gists.Gist
22+
:members:
23+
24+
.. attribute:: comments
25+
26+
:ref:`Comments service`
27+
28+
.. _Comments service:
29+
30+
Comments
31+
----------
32+
33+
.. autoclass:: pygithub3.services.gists.Comments
34+
:members:
35+
36+
.. _github gists doc: http://developer.github.com/v3/gists
37+
.. _github comments doc: http://developer.github.com/v3/gists/comments

docs/repos.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _Repos service:
22

3-
Repos's services
3+
Repos services
44
===================
55

66
**Fast sample**::
@@ -50,7 +50,7 @@ You can see it better with an example: ::
5050
Repo
5151
-------
5252

53-
.. autoclass:: pygithub3.services.repos.Repos
53+
.. autoclass:: pygithub3.services.repos.Repo
5454
:members:
5555

5656
.. attribute:: collaborators

docs/services.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ attributes or all of them.
5353
.. autoclass:: pygithub3.services.base.MimeTypeMixin
5454
:members:
5555

56+
**Fast example**::
57+
58+
from pygithub3 import Github
59+
60+
gh = Github()
61+
62+
gh.gists.comments.set_html()
63+
comment = gh.gists.comments.list(1).all()[0]
64+
print comment.body, comment.body_text, comment.body_html
65+
5666
List of services
5767
-------------------
5868

@@ -61,5 +71,6 @@ List of services
6171

6272
users
6373
repos
74+
gists
6475

6576
.. _mimetypes: http://developer.github.com/v3/mime

docs/users.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.. _User service:
1+
.. _Users service:
22

3-
User's services
3+
Users services
44
===============
55

66
**Fast sample**::

pygithub3/github.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- encoding: utf-8 -*-
33

44

5+
#TODO: Move the imports out. setup related
56
class Github(object):
67
"""
78
You can preconfigure all services globally with a ``config`` dict. See
@@ -14,9 +15,11 @@ class Github(object):
1415

1516
def __init__(self, **config):
1617
from pygithub3.services.users import User
17-
from pygithub3.services.repos import Repos
18+
from pygithub3.services.repos import Repo
19+
from pygithub3.services.gists import Gist
1820
self._users = User(**config)
19-
self._repos = Repos(**config)
21+
self._repos = Repo(**config)
22+
self._gists = Gist(**config)
2023

2124
@property
2225
def remaining_requests(self):
@@ -27,7 +30,7 @@ def remaining_requests(self):
2730
@property
2831
def users(self):
2932
"""
30-
:ref:`User service <User service>`
33+
:ref:`Users service <Users service>`
3134
"""
3235
return self._users
3336

@@ -37,3 +40,10 @@ def repos(self):
3740
:ref:`Repos service <Repos service>`
3841
"""
3942
return self._repos
43+
44+
@property
45+
def gists(self):
46+
"""
47+
:ref:`Gists service <Gists service>`
48+
"""
49+
return self._gists

pygithub3/requests/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def parse(self):
3737
if attr_required not in parsed:
3838
raise ValidationError("'%s' attribute is required" %
3939
attr_required)
40-
if not parsed[attr_required]:
40+
if parsed[attr_required] is None:
4141
raise ValidationError("'%s' attribute can't be empty" %
4242
attr_required)
4343
return parsed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
from pygithub3.requests.base import Request, ValidationError
4+
from pygithub3.resources.gists import Gist
5+
6+
class List(Request):
7+
8+
uri = 'users/{user}/gists'
9+
resource = Gist
10+
11+
def clean_uri(self):
12+
if not self.user:
13+
return 'gists'
14+
15+
16+
class Public(Request):
17+
18+
uri = 'gists/public'
19+
resource = Gist
20+
21+
22+
class Starred(Request):
23+
24+
uri = 'gists/starred'
25+
resource = Gist
26+
27+
28+
class Get(Request):
29+
30+
uri = 'gists/{id}'
31+
resource = Gist
32+
33+
34+
class Create(Request):
35+
36+
uri = 'gists'
37+
resource = Gist
38+
body_schema = {
39+
'schema': ('description', 'public', 'files'),
40+
'required': ('public', 'files')
41+
}
42+
43+
44+
class Update(Request):
45+
46+
uri = 'gists/{id}'
47+
resource = Gist
48+
body_schema = {
49+
'schema': ('description', 'public', 'files'),
50+
'required': (),
51+
}
52+
53+
54+
class Star(Request):
55+
56+
uri = 'gists/{id}/star'
57+
58+
59+
class Unstar(Request):
60+
61+
uri = 'gists/{id}/star'
62+
63+
64+
class Is_starred(Request):
65+
66+
uri = 'gists/{id}/star'
67+
68+
69+
class Fork(Request):
70+
71+
uri = 'gists/{id}/fork'
72+
resource = Gist
73+
74+
75+
class Delete(Request):
76+
77+
uri = 'gists/{id}'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
from pygithub3.requests.base import Request
4+
from pygithub3.resources.gists import Comment
5+
6+
class List(Request):
7+
8+
uri = 'gists/{gist_id}/comments'
9+
resource = Comment
10+
11+
12+
class Get(Request):
13+
14+
uri = 'gists/comments/{id}'
15+
resource = Comment
16+
17+
18+
class Create(Request):
19+
20+
uri = 'gists/{gist_id}/comments'
21+
resource = Comment
22+
body_schema = {
23+
'schema': ('body', ),
24+
'required': ('body', )
25+
}
26+
27+
28+
class Update(Request):
29+
30+
uri = 'gists/comments/{id}'
31+
resource = Comment
32+
body_schema = {
33+
'schema': ('body', ),
34+
'required': ('body', )
35+
}
36+
37+
38+
class Delete(Request):
39+
40+
uri = 'gists/comments/{id}'

pygithub3/resources/gists.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from .base import Resource
5+
from .users import User
6+
7+
8+
class File(Resource):
9+
10+
def __str__(self):
11+
return '<GistFile (%s)>' % getattr(self, 'filename', '')
12+
13+
14+
class Fork(Resource):
15+
16+
_dates = ('created_at', )
17+
_maps = {'user': User}
18+
def __str__(self):
19+
return '<GistFork>'
20+
21+
22+
class History(Resource):
23+
24+
_dates = ('committed_at', )
25+
_maps = {'user': User}
26+
27+
def __str__(self):
28+
return '<GistHistory (%s)>' % getattr(self, 'version', '')
29+
30+
class Gist(Resource):
31+
32+
_dates = ('created_at', )
33+
_maps = {'user': User}
34+
_collection_maps = {'files': File, 'forks': Fork, 'history': History}
35+
36+
def __str__(self):
37+
return '<Gist (%s)>' % getattr(self, 'description', '')
38+
39+
class Comment(Resource):
40+
41+
_dates = ('created_at', )
42+
_maps = {'user': User}
43+
44+
def __str__(self):
45+
return '<GistComment (%s)>' % getattr(self, 'user', '')

0 commit comments

Comments
 (0)