desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Show that a user must change something to edit a gist.'
| def test_edit_requires_changes(self):
| self.instance.edit()
assert (self.session.patch.called is False)
|
'Show that a user can fork a gist.'
| def test_fork(self):
| self.instance.fork()
self.session.post.assert_called_once_with(url_for('forks'), None)
|
'Show that a user can get a gist\'s history.'
| def test_history(self):
| history = self.instance.history[0]
assert isinstance(history, github3.gists.history.GistHistory)
assert repr(history).startswith('<Gist History')
|
'Show that each file object is an instance of GistFile.'
| def test_file(self):
| _file = self.instance._files[0]
assert isinstance(_file, github3.gists.file.GistFile)
|
'Show that a user can check if they starred a gist.'
| def test_is_starred(self):
| self.instance.is_starred()
self.session.get.assert_called_once_with(url_for('star'))
|
'Show that a user can star a gist.'
| def test_star(self):
| self.instance.star()
self.session.put.assert_called_once_with(url_for('star'))
|
'Show that a user can unstar a gist.'
| def test_unstar(self):
| self.instance.unstar()
self.session.delete.assert_called_once_with(url_for('star'))
|
'Show that a str(gist) is the same as the gist\'s id.'
| def test_to_str(self):
| assert (str(self.instance) == str(self.instance.id))
|
'Show that a user needs to authenticate to create a comment.'
| def test_create_comment(self):
| with pytest.raises(github3.GitHubError):
self.instance.create_comment('foo')
|
'Show that a user needs to authenticate to delete a gist.'
| def test_delete(self):
| with pytest.raises(github3.GitHubError):
self.instance.delete()
|
'Show that a user needs to authenticate to edit a gist.'
| def test_edit(self):
| with pytest.raises(github3.GitHubError):
self.instance.edit()
|
'Show that a user needs to authenticate to fork a gist.'
| def test_fork(self):
| with pytest.raises(github3.GitHubError):
self.instance.fork()
|
'Show that a user needs to auth to check if they starred a gist.'
| def test_is_starred(self):
| with pytest.raises(github3.GitHubError):
self.instance.is_starred()
|
'Show that a user needs to be authenticated to star a gist.'
| def test_star(self):
| with pytest.raises(github3.GitHubError):
self.instance.star()
|
'Show that a user needs to be authenticated to unstar a gist.'
| def test_unstar(self):
| with pytest.raises(github3.GitHubError):
self.instance.unstar()
|
'Show a user can iterate over the comments on a gist.'
| def test_comments(self):
| i = self.instance.comments()
self.get_next(i)
self.session.get.assert_called_once_with(url_for('comments'), params={'per_page': 100}, headers={})
|
'Show a user can iterate over the commits on a gist.'
| def test_commits(self):
| i = self.instance.commits()
self.get_next(i)
self.session.get.assert_called_once_with(url_for('commits'), params={'per_page': 100}, headers={})
|
'Show that iterating over a gist\'s files does not make a request.'
| def test_files(self):
| files = list(self.instance.files())
assert (len(files) > 0)
assert (self.session.get.called is False)
|
'Show that a user can iterate over a gist\'s forks.'
| def test_forks(self):
| i = self.instance.forks()
self.get_next(i)
self.session.get.assert_called_once_with(url_for('forks'), params={'per_page': 100}, headers={})
|
'Show that two instances of a GistHistory are equal.'
| def test_equality(self):
| history = github3.gists.history.GistHistory(gist_history_example_data())
assert (self.instance == history)
history._uniq = 'foo'
assert (self.instance != history)
|
'Show that two instances of a GistComment are equal.'
| def test_equality(self):
| comment = github3.gists.comment.GistComment(gist_comment_example_data())
assert (self.instance == comment)
comment._uniq = '1'
assert (self.instance != comment)
|
'Excercise the GistComment repr.'
| def test_repr(self):
| assert repr(self.instance).startswith('<Gist Comment')
|
'Verify the request made to retrieve a GistFile\'s content.'
| def test_get_file_content_from_raw_url(self):
| self.instance.content()
self.session.get.assert_called_once_with(self.instance.raw_url)
|
'Retrieve a full User object for this EventUser.'
| def to_user(self):
| from . import users
url = self._build_url(u'users', self.login)
json = self._json(self._get(url), 200)
return self._instance_or_null(users.User, json)
|
'List available payload types.'
| @staticmethod
def list_types():
| return sorted(_payload_handlers.keys())
|
'The actual message returned by the API.'
| @property
def message(self):
| return self.msg
|
'Add the email addresses in ``addresses`` to the authenticated
user\'s account.
:param list addresses: (optional), email addresses to be added
:returns: list of :class:`~github3.users.Email`'
| @requires_auth
def add_email_addresses(self, addresses=[]):
| json = []
if addresses:
url = self._build_url(u'user', u'emails')
json = self._json(self._post(url, data=addresses), 201)
return ([users.Email(email) for email in json] if json else [])
|
'Iterate over public events.
:param int number: (optional), number of events to return. Default: -1
returns all available events
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Event <github3.events.Event>`\ s'
| def all_events(self, number=(-1), etag=None):
| url = self._build_url(u'events')
return self._iter(int(number), url, Event, etag=etag)
|
'Iterate over every organization in the order they were created.
:param int number: (optional), number of organizations to return.
Default: -1, returns all of them
:param int since: (optional), last organization id seen (allows
restarting this iteration)
:param str etag: (optional), ETag from a previous request to the ... | def all_organizations(self, number=(-1), since=None, etag=None, per_page=None):
| url = self._build_url(u'organizations')
return self._iter(int(number), url, Organization, params={u'since': since, u'per_page': per_page}, etag=etag)
|
'Iterate over every repository in the order they were created.
:param int number: (optional), number of repositories to return.
Default: -1, returns all of them
:param int since: (optional), last repository id seen (allows
restarting this iteration)
:param str etag: (optional), ETag from a previous request to the same
... | def all_repositories(self, number=(-1), since=None, etag=None, per_page=None):
| url = self._build_url(u'repositories')
return self._iter(int(number), url, Repository, params={u'since': since, u'per_page': per_page}, etag=etag)
|
'Iterate over every user in the order they signed up for GitHub.
.. versionchanged:: 1.0.0
Inserted the ``since`` parameter after the ``number`` parameter.
:param int number: (optional), number of users to return. Default: -1,
returns all of them
:param int since: (optional), ID of the last user that you\'ve seen.
:par... | def all_users(self, number=(-1), etag=None, per_page=None, since=None):
| url = self._build_url(u'users')
return self._iter(int(number), url, users.ShortUser, etag=etag, params={u'per_page': per_page, u'since': since})
|
'Get information about authorization ``id``.
:param int id_num: (required), unique id of the authorization
:returns: :class:`Authorization <Authorization>`'
| @requires_basic_auth
def authorization(self, id_num):
| json = None
if (int(id_num) > 0):
url = self._build_url(u'authorizations', str(id_num))
json = self._json(self._get(url), 200)
return self._instance_or_null(Authorization, json)
|
'Iterate over authorizations for the authenticated user. This will
return a 404 if you are using a token for authentication.
:param int number: (optional), number of authorizations to return.
Default: -1 returns all available authorizations
:param str etag: (optional), ETag from a previous request to the same
endpoint
... | @requires_basic_auth
def authorizations(self, number=(-1), etag=None):
| url = self._build_url(u'authorizations')
return self._iter(int(number), url, Authorization, etag=etag)
|
'Obtain an authorization token.
The retrieved token will allow future consumers to use the API without
a username and password.
:param str username: (required)
:param str password: (required)
:param list scopes: (optional), areas you want this token to apply to,
i.e., \'gist\', \'user\'
:param str note: (optional), not... | def authorize(self, username, password, scopes=None, note=u'', note_url=u'', client_id=u'', client_secret=u''):
| json = None
if (username and password):
url = self._build_url(u'authorizations')
data = {u'note': note, u'note_url': note_url, u'client_id': client_id, u'client_secret': client_secret}
if scopes:
data[u'scopes'] = scopes
with self.session.temporary_basic_auth(username... |
'Check an authorization created by a registered application.
OAuth applications can use this method to check token validity
without hitting normal rate limits because of failed login attempts.
If the token is valid, it will return True, otherwise it will return
False.
:returns: bool'
| def check_authorization(self, access_token):
| p = self.session.params
auth = (p.get(u'client_id'), p.get(u'client_secret'))
if (access_token and auth):
url = self._build_url(u'applications', str(auth[0]), u'tokens', str(access_token))
resp = self._get(url, auth=auth, params={u'client_id': None, u'client_secret': None})
return se... |
'Create a new gist.
If no login was provided, it will be anonymous.
:param str description: (required), description of gist
:param dict files: (required), file names with associated dictionaries
for content, e.g. ``{\'spam.txt\': {\'content\': \'File contents
:param bool public: (optional), make the gist public if True... | def create_gist(self, description, files, public=True):
| new_gist = {u'description': description, u'public': public, u'files': files}
url = self._build_url(u'gists')
json = self._json(self._post(url, data=new_gist), 201)
return self._instance_or_null(Gist, json)
|
'Create an issue on the project \'repository\' owned by \'owner\'
with title \'title\'.
``body``, ``assignee``, ``milestone``, ``labels`` are all optional.
.. warning::
This method retrieves the repository first and then uses it to
create an issue. If you\'re making several issues, you should use
:py:meth:`repository <... | @requires_auth
def create_issue(self, owner, repository, title, body=None, assignee=None, milestone=None, labels=[]):
| repo = None
if (owner and repository and title):
repo = self.repository(owner, repository)
if (repo is not None):
return repo.create_issue(title, body, assignee, milestone, labels)
return self._instance_or_null(Issue, None)
|
'Create a new key for the authenticated user.
:param str title: (required), key title
:param str key: (required), actual key contents, accepts path
as a string or file-like object
:param bool read_only: (optional), restrict key access to read-only,
default to False
:returns: :class:`Key <github3.users.Key>`'
| @requires_auth
def create_key(self, title, key, read_only=False):
| json = None
if (title and key):
data = {u'title': title, u'key': key, u'read_only': read_only}
url = self._build_url(u'user', u'keys')
req = self._post(url, data=data)
json = self._json(req, 201)
return self._instance_or_null(users.Key, json)
|
'Create a repository for the authenticated user.
:param str name: (required), name of the repository
:param str description: (optional)
:param str homepage: (optional)
:param str private: (optional), If ``True``, create a
private repository. API default: ``False``
:param bool has_issues: (optional), If ``True``, enable... | @requires_auth
def create_repository(self, name, description=u'', homepage=u'', private=False, has_issues=True, has_wiki=True, auto_init=False, gitignore_template=u''):
| url = self._build_url(u'user', u'repos')
data = {u'name': name, u'description': description, u'homepage': homepage, u'private': private, u'has_issues': has_issues, u'has_wiki': has_wiki, u'auto_init': auto_init, u'gitignore_template': gitignore_template}
json = self._json(self._post(url, data=data), 201)
... |
'Delete the email addresses in ``addresses`` from the
authenticated user\'s account.
:param list addresses: (optional), email addresses to be removed
:returns: bool'
| @requires_auth
def delete_email_addresses(self, addresses=[]):
| url = self._build_url(u'user', u'emails')
return self._boolean(self._delete(url, data=json.dumps(addresses)), 204, 404)
|
'Iterate over email addresses for the authenticated user.
:param int number: (optional), number of email addresses to return.
Default: -1 returns all available email addresses
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of dicts'
| @requires_auth
def emails(self, number=(-1), etag=None):
| url = self._build_url(u'user', u'emails')
return self._iter(int(number), url, users.Email, etag=etag)
|
'Retrieves a dictionary of all of the emojis that GitHub supports.
:returns: dictionary where the key is what would be in between the
colons and the value is the URL to the image, e.g., ::
\'+1\': \'https://github.global.ssl.fastly.net/images/...\','
| def emojis(self):
| url = self._build_url(u'emojis')
return self._json(self._get(url), 200, include_cache_info=False)
|
'List GitHub\'s timeline resources in Atom format.
:returns: dictionary parsed to include URITemplates'
| @requires_basic_auth
def feeds(self):
| def replace_href(feed_dict):
if (not feed_dict):
return feed_dict
ret_dict = {}
href = feed_dict.pop(u'href', None)
ret_dict.update(feed_dict)
if (href is not None):
ret_dict[u'href'] = URITemplate(href)
return ret_dict
url = self._build_ur... |
'Make the authenticated user follow the provided username.
:param str username: (required), user to follow
:returns: bool'
| @requires_auth
def follow(self, username):
| resp = False
if username:
url = self._build_url(u'user', u'following', username)
resp = self._boolean(self._put(url), 204, 404)
return resp
|
'Iterate over users being followed by ``username``.
.. versionadded:: 1.0.0
This replaces iter_following(\'sigmavirus24\').
:param str username: (required), login of the user to check
:param int number: (optional), number of people to return. Default: -1
returns all people you follow
:param str etag: (optional), ETag f... | def followed_by(self, username, number=(-1), etag=None):
| url = self._build_url(u'users', username, u'following')
return self._iter(int(number), url, users.ShortUser, etag=etag)
|
'Iterate over followers of the authenticated user.
.. versionadded:: 1.0.0
This replaces iter_followers().
:param int number: (optional), number of followers to return. Default:
-1 returns all followers
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`~github... | @requires_auth
def followers(self, number=(-1), etag=None):
| url = self._build_url(u'user', u'followers')
return self._iter(int(number), url, users.ShortUser, etag=etag)
|
'Iterate over followers of ``username``.
.. versionadded:: 1.0.0
This replaces iter_followers(\'sigmavirus24\').
:param str username: (required), login of the user to check
:param int number: (optional), number of followers to return. Default:
-1 returns all followers
:param str etag: (optional), ETag from a previous r... | def followers_of(self, username, number=(-1), etag=None):
| url = self._build_url(u'users', username, u'followers')
return self._iter(int(number), url, users.ShortUser, etag=etag)
|
'Iterate over users the authenticated user is following.
.. versionadded:: 1.0.0
This replaces iter_following().
:param int number: (optional), number of people to return. Default: -1
returns all people you follow
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :cla... | @requires_auth
def following(self, number=(-1), etag=None):
| url = self._build_url(u'user', u'following')
return self._iter(int(number), url, users.ShortUser, etag=etag)
|
'Retrieve the gist using the specified id number.
:param int id_num: (required), unique id of the gist
:returns: :class:`Gist <github3.gists.Gist>`'
| def gist(self, id_num):
| url = self._build_url(u'gists', str(id_num))
json = self._json(self._get(url), 200)
return self._instance_or_null(Gist, json)
|
'Retrieve the authenticated user\'s gists.
.. versionadded:: 1.0
:param int number: (optional), number of gists to return. Default: -1,
returns all available gists
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Gist <github3.gists.Gist>`\ s'
| @requires_auth
def gists(self, number=(-1), etag=None):
| url = self._build_url(u'gists')
return self._iter(int(number), url, Gist, etag=etag)
|
'Iterate over the gists owned by a user.
.. versionadded:: 1.0
:param str username: login of the user who owns the gists
:param int number: (optional), number of gists to return. Default: -1
returns all available gists
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of... | def gists_by(self, username, number=(-1), etag=None):
| url = self._build_url(u'users', username, u'gists')
return self._iter(int(number), url, Gist, etag=etag)
|
'Return the template for language.
:returns: str'
| def gitignore_template(self, language):
| url = self._build_url(u'gitignore', u'templates', language)
json = self._json(self._get(url), 200)
if (not json):
return u''
return json.get(u'source', u'')
|
'Return the list of available templates.
:returns: list of template names'
| def gitignore_templates(self):
| url = self._build_url(u'gitignore', u'templates')
return (self._json(self._get(url), 200) or [])
|
'Check if the authenticated user is following login.
:param str username: (required), login of the user to check if the
authenticated user is checking
:returns: bool'
| @requires_auth
def is_following(self, username):
| json = False
if username:
url = self._build_url(u'user', u'following', username)
json = self._boolean(self._get(url), 204, 404)
return json
|
'Check if the authenticated user starred username/repo.
:param str username: (required), owner of repository
:param str repo: (required), name of repository
:returns: bool'
| @requires_auth
def is_starred(self, username, repo):
| json = False
if (username and repo):
url = self._build_url(u'user', u'starred', username, repo)
json = self._boolean(self._get(url), 204, 404)
return json
|
'Fetch issue from owner/repository.
:param str username: (required), owner of the repository
:param str repository: (required), name of the repository
:param int number: (required), issue number
:return: :class:`Issue <github3.issues.Issue>`'
| def issue(self, username, repository, number):
| json = None
if (username and repository and (int(number) > 0)):
url = self._build_url(u'repos', username, repository, u'issues', str(number))
json = self._json(self._get(url), 200)
return self._instance_or_null(Issue, json)
|
'List all of the authenticated user\'s (and organization\'s) issues.
.. versionchanged:: 0.9.0
- The ``state`` parameter now accepts \'all\' in addition to \'open\'
and \'closed\'.
:param str filter: accepted values:
(\'assigned\', \'created\', \'mentioned\', \'subscribed\')
api-default: \'assigned\'
:param str state: ... | @requires_auth
def issues(self, filter=u'', state=u'', labels=u'', sort=u'', direction=u'', since=None, number=(-1), etag=None):
| url = self._build_url(u'issues')
params = issue_params(filter, state, labels, sort, direction, since)
return self._iter(int(number), url, Issue, params, etag)
|
'List issues on owner/repository. Only owner and repository are
required.
.. versionchanged:: 0.9.0
- The ``state`` parameter now accepts \'all\' in addition to \'open\'
and \'closed\'.
:param str username: login of the owner of the repository
:param str repository: name of the repository
:param int milestone: None, \'... | def issues_on(self, username, repository, milestone=None, state=None, assignee=None, mentioned=None, labels=None, sort=None, direction=None, since=None, number=(-1), etag=None):
| if (username and repository):
url = self._build_url(u'repos', username, repository, u'issues')
params = repo_issue_params(milestone, state, assignee, mentioned, labels, sort, direction, since)
return self._iter(int(number), url, Issue, params=params, etag=etag)
return iter([])
|
'Gets the authenticated user\'s key specified by id_num.
:param int id_num: (required), unique id of the key
:returns: :class:`Key <github3.users.Key>`'
| @requires_auth
def key(self, id_num):
| json = None
if (int(id_num) > 0):
url = self._build_url(u'user', u'keys', str(id_num))
json = self._json(self._get(url), 200)
return self._instance_or_null(users.Key, json)
|
'Iterate over public keys for the authenticated user.
:param int number: (optional), number of keys to return. Default: -1
returns all your keys
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Key <github3.users.Key>`\ s'
| @requires_auth
def keys(self, number=(-1), etag=None):
| url = self._build_url(u'user', u'keys')
return self._iter(int(number), url, users.Key, etag=etag)
|
'Retrieve the license specified by the name.
:param string name: (required), name of license
:returns: :class:`License <github3.licenses.License>`'
| def license(self, name):
| url = self._build_url(u'licenses', name)
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS), 200)
return self._instance_or_null(License, json)
|
'Iterate over open source licenses.
:returns: generator of :class:`License <github3.licenses.License>`'
| def licenses(self, number=(-1), etag=None):
| url = self._build_url(u'licenses')
return self._iter(int(number), url, License, etag=etag, headers=License.CUSTOM_HEADERS)
|
'Logs the user into GitHub for protected API calls.
:param str username: login name
:param str password: password for the login
:param str token: OAuth token
:param func two_factor_callback: (optional), function you implement to
provide the Two Factor Authentication code to GitHub when necessary'
| def login(self, username=None, password=None, token=None, two_factor_callback=None):
| if (username and password):
self.session.basic_auth(username, password)
elif token:
self.session.token_auth(token)
self.session.two_factor_auth_callback(two_factor_callback)
|
'Render an arbitrary markdown document.
:param str text: (required), the text of the document to render
:param str mode: (optional), \'markdown\' or \'gfm\'
:param str context: (optional), only important when using mode \'gfm\',
this is the repository to use as the context for the rendering
:param bool raw: (optional),... | def markdown(self, text, mode=u'', context=u'', raw=False):
| data = None
json = False
headers = {}
if raw:
url = self._build_url(u'markdown', u'raw')
data = text
headers[u'content-type'] = u'text/plain'
else:
url = self._build_url(u'markdown')
data = {}
if text:
data[u'text'] = text
if (mode ... |
'Retrieve the info for the authenticated user.
.. versionadded:: 1.0
This was separated from the ``user`` method.
:returns: The representation of the authenticated user.
:rtype: :class:`~github3.users.AuthenticatedUser`'
| @requires_auth
def me(self):
| url = self._build_url(u'user')
json = self._json(self._get(url), 200)
return self._instance_or_null(users.AuthenticatedUser, json)
|
'Retrieve the user\'s membership in the specified organization.'
| @requires_auth
def membership_in(self, organization):
| url = self._build_url(u'user', u'memberships', u'orgs', str(organization))
json = self._json(self._get(url), 200)
return self._instance_or_null(Membership, json)
|
'Returns a dictionary with arrays of addresses in CIDR format
specifying theaddresses that the incoming service hooks will originate
from.
.. versionadded:: 0.5'
| def meta(self):
| url = self._build_url(u'meta')
return (self._json(self._get(url), 200) or {})
|
'Iterate over the user\'s notification.
:param bool all: (optional), iterate over all notifications
:param bool participating: (optional), only iterate over notifications
in which the user is participating
:param int number: (optional), how many notifications to return
:param str etag: (optional), ETag from a previous ... | @requires_auth
def notifications(self, all=False, participating=False, number=(-1), etag=None):
| params = None
if (all is True):
params = {u'all': u'true'}
elif (participating is True):
params = {u'participating': u'true'}
url = self._build_url(u'notifications')
return self._iter(int(number), url, Thread, params, etag=etag)
|
'Returns an easter egg of the API.
:params str say: (optional), pass in what you\'d like Octocat to say
:returns: ascii art of Octocat
:rtype: str (or unicode on Python 3)'
| def octocat(self, say=None):
| url = self._build_url(u'octocat')
req = self._get(url, params={u's': say})
return (req.text if req.ok else u'')
|
'Returns a Organization object for the login name
:param str username: (required), login name of the org
:returns: :class:`Organization <github3.orgs.Organization>`'
| def organization(self, username):
| url = self._build_url(u'orgs', username)
json = self._json(self._get(url), 200)
return self._instance_or_null(Organization, json)
|
'Iterate over the organization\'s issues if the authenticated user
belongs to it.
:param str name: (required), name of the organization
:param str filter: accepted values:
(\'assigned\', \'created\', \'mentioned\', \'subscribed\')
api-default: \'assigned\'
:param str state: accepted values: (\'open\', \'closed\')
api-d... | @requires_auth
def organization_issues(self, name, filter=u'', state=u'', labels=u'', sort=u'', direction=u'', since=None, number=(-1), etag=None):
| url = self._build_url(u'orgs', name, u'issues')
params = issue_params(filter, state, labels, sort, direction, since)
return self._iter(int(number), url, Issue, params, etag)
|
'Iterate over all organizations the authenticated user belongs to.
This will display both the private memberships and the publicized
memberships.
:param int number: (optional), number of organizations to return.
Default: -1 returns all available organizations
:param str etag: (optional), ETag from a previous request to... | @requires_auth
def organizations(self, number=(-1), etag=None):
| url = self._build_url(u'user', u'orgs')
return self._iter(int(number), url, Organization, etag=etag)
|
'Iterate over organizations with ``username`` as a public member.
.. versionadded:: 1.0.0
Replaces ``iter_orgs(\'sigmavirus24\')``.
:param str username: (optional), user whose orgs you wish to list
:param int number: (optional), number of organizations to return.
Default: -1 returns all available organizations
:param s... | def organizations_with(self, username, number=(-1), etag=None):
| if username:
url = self._build_url(u'users', username, u'orgs')
return self._iter(int(number), url, Organization, etag=etag)
return iter([])
|
'Retrieve all public gists and iterate over them.
.. versionadded:: 1.0
:param int number: (optional), number of gists to return. Default: -1
returns all available gists
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Gist <github3.gists.Gist>`\ s'
| def public_gists(self, number=(-1), etag=None):
| url = self._build_url(u'gists', u'public')
return self._iter(int(number), url, Gist, etag=etag)
|
'List organizations of which the user is a current or pending member.
:param str state: (option), state of the membership, i.e., active,
pending
:returns: iterator of :class:`Membership <github3.orgs.Membership>`'
| @requires_auth
def organization_memberships(self, state=None, number=(-1), etag=None):
| params = None
url = self._build_url(u'user', u'memberships', u'orgs')
if ((state is not None) and (state.lower() in (u'active', u'pending'))):
params = {u'state': state.lower()}
return self._iter(int(number), url, Membership, params=params, etag=etag)
|
'Create/update a pubsubhubbub hook.
:param str mode: (required), accepted values: (\'subscribe\',
\'unsubscribe\')
:param str topic: (required), form:
https://github.com/:user/:repo/events/:event
:param str callback: (required), the URI that receives the updates
:param str secret: (optional), shared secret key that gen... | @requires_auth
def pubsubhubbub(self, mode, topic, callback, secret=u''):
| from re import match
m = match(u'https?://[\\w\\d\\-\\.\\:]+/\\w[\\w-]+\\w/[\\w\\._-]+/events/\\w+', topic)
status = False
if (mode and topic and callback and m):
data = [(u'hub.mode', mode), (u'hub.topic', topic), (u'hub.callback', callback)]
if secret:
data.append((u'hub.se... |
'Fetch pull_request #:number: from :owner:/:repository
:param str owner: (required), owner of the repository
:param str repository: (required), name of the repository
:param int number: (required), issue number
:return: :class:`~github.pulls.PullRequest`'
| def pull_request(self, owner, repository, number):
| json = None
if (int(number) > 0):
url = self._build_url(u'repos', owner, repository, u'pulls', str(number))
json = self._json(self._get(url), 200)
return self._instance_or_null(PullRequest, json)
|
'Returns a dictionary with information from /rate_limit.
The dictionary has two keys: ``resources`` and ``rate``. In
``resources`` you can access information about ``core`` or ``search``.
Note: the ``rate`` key will be deprecated before version 3 of the
GitHub API is finalized. Do not rely on that key. Instead, make yo... | def rate_limit(self):
| url = self._build_url(u'rate_limit')
return self._json(self._get(url), 200)
|
'List repositories for the authenticated user, filterable by ``type``.
.. versionchanged:: 0.6
Removed the login parameter for correctness. Use repositories_by
instead
:param str type: (optional), accepted values:
(\'all\', \'owner\', \'public\', \'private\', \'member\')
API default: \'all\'
:param str sort: (optional)... | @requires_auth
def repositories(self, type=None, sort=None, direction=None, number=(-1), etag=None):
| url = self._build_url(u'user', u'repos')
params = {}
if (type in (u'all', u'owner', u'public', u'private', u'member')):
params.update(type=type)
if (sort in (u'created', u'updated', u'pushed', u'full_name')):
params.update(sort=sort)
if (direction in (u'asc', u'desc')):
param... |
'List public repositories for the specified ``username``.
.. versionadded:: 0.6
:param str username: (required), username
:param str type: (optional), accepted values:
(\'all\', \'owner\', \'member\')
API default: \'all\'
:param str sort: (optional), accepted values:
(\'created\', \'updated\', \'pushed\', \'full_name\'... | def repositories_by(self, username, type=None, sort=None, direction=None, number=(-1), etag=None):
| url = self._build_url(u'users', username, u'repos')
params = {}
if (type in (u'all', u'owner', u'member')):
params.update(type=type)
if (sort in (u'created', u'updated', u'pushed', u'full_name')):
params.update(sort=sort)
if (direction in (u'asc', u'desc')):
params.update(dir... |
'Returns a Repository object for the specified combination of
owner and repository
:param str owner: (required)
:param str repository: (required)
:returns: :class:`Repository <github3.repos.Repository>`'
| def repository(self, owner, repository):
| json = None
if (owner and repository):
url = self._build_url(u'repos', owner, repository)
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS), 200)
return self._instance_or_null(Repository, json)
|
'Returns the Repository with id ``number``.
:param int number: id of the repository
:returns: :class:`Repository <github3.repos.Repository>`'
| def repository_with_id(self, number):
| number = int(number)
json = None
if (number > 0):
url = self._build_url(u'repositories', str(number))
json = self._json(self._get(url), 200)
return self._instance_or_null(Repository, json)
|
'Revoke specified authorization for an OAuth application.
Revoke all authorization tokens created by your application. This will
only work if you have already called ``set_client_id``.
:param str access_token: (required), the access_token to revoke
:returns: bool -- True if successful, False otherwise'
| @requires_app_credentials
def revoke_authorization(self, access_token):
| (client_id, client_secret) = self.session.retrieve_client_credentials()
url = self._build_url(u'applications', str(client_id), u'tokens', access_token)
with self.session.temporary_basic_auth(client_id, client_secret):
response = self._delete(url, params={u'client_id': None, u'client_secret': None})
... |
'Revoke all authorizations for an OAuth application.
Revoke all authorization tokens created by your application. This will
only work if you have already called ``set_client_id``.
:param str client_id: (required), the client_id of your application
:returns: bool -- True if successful, False otherwise'
| @requires_app_credentials
def revoke_authorizations(self):
| (client_id, client_secret) = self.session.retrieve_client_credentials()
url = self._build_url(u'applications', str(client_id), u'tokens')
with self.session.temporary_basic_auth(client_id, client_secret):
response = self._delete(url, params={u'client_id': None, u'client_secret': None})
return sel... |
'Proxy access to stored JSON.'
| def __getattr__(self, attribute):
| if (attribute not in self._json_data):
raise AttributeError(attribute)
value = self._json_data.get(attribute)
setattr(self, attribute, value)
return value
|
'Return the attributes for this object as a dictionary.
This is equivalent to calling::
json.loads(obj.as_json())
:returns: this object\'s attributes serialized to a dictionary
:rtype: dict'
| def as_dict(self):
| return self._json_data
|
'Return the json data for this object.
This is equivalent to calling::
json.dumps(obj.as_dict())
:returns: this object\'s attributes as a JSON string
:rtype: str'
| def as_json(self):
| return dumps(self._json_data)
|
'Return the attribute from the json data.
:param dict data: dictionary used to put together the model
:param str attribute: key of the attribute
:param any fallback: return value if original return value is falsy
:returns: value paired with key in dict, fallback'
| @classmethod
def _get_attribute(cls, data, attribute, fallback=None):
| if ((data is None) or (not isinstance(data, dict))):
return None
result = data.get(attribute)
if (result is None):
return fallback
return result
|
'Return the attribute from the json data and instantiate the class.
:param dict data: dictionary used to put together the model or None
:param str attribute: key of the attribute
:param class cl: class that will be instantiated
:returns: instantiated class or None
:rtype: object or None'
| @classmethod
def _class_attribute(cls, data, attribute, cl, *args, **kwargs):
| value = cls._get_attribute(data, attribute)
if value:
return cl(value, *args, **kwargs)
return value
|
'Get a datetime object from a dict, return None if it wan\'t found.
This is equivalent to calling::
cls._strptime(data[attribute]) if attribute in data else None
:param dict data: dictionary used to put together the model
:param str attribute: key of the attribute
:returns: timezone-aware datetime object
:rtype: dateti... | @classmethod
def _strptime_attribute(cls, data, attribute):
| result = cls._get_attribute(data, attribute)
if result:
return cls._strptime(result)
return result
|
'Convert an ISO 8601 formatted string to a datetime object.
We assume that the ISO 8601 formatted string is in UTC and we create
the datetime object so that it is timezone-aware.
:param str time_str: ISO 8601 formatted string
:returns: timezone-aware datetime object
:rtype: datetime or None'
| @classmethod
def _strptime(cls, time_str):
| if time_str:
dt = datetime.strptime(time_str, __timeformat__)
return dt.replace(tzinfo=UTC())
return None
|
'Return an instance of this class formed from ``json_dict``.'
| @classmethod
def from_dict(cls, json_dict):
| return cls(json_dict)
|
'Return an instance of this class formed from ``json``.'
| @classmethod
def from_json(cls, json):
| return cls(loads(json))
|
'Builds a new API url from scratch.'
| def _build_url(self, *args, **kwargs):
| return self.session.build_url(*args, **kwargs)
|
'Generic iterator for this project.
:param int count: How many items to return.
:param int url: First URL to start with
:param class cls: cls to return an object of
:param params dict: (optional) Parameters for the request
:param str etag: (optional), ETag from the last call
:param dict headers: (optional) HTTP Headers... | def _iter(self, count, url, cls, params=None, etag=None, headers=None):
| from .structs import GitHubIterator
return GitHubIterator(count, url, cls, self, params, etag, headers)
|
'Number of requests before GitHub imposes a ratelimit.
:returns: int'
| @property
def ratelimit_remaining(self):
| json = self._json(self._get((self._github_url + u'/rate_limit')), 200)
core = json.get(u'resources', {}).get(u'core', {})
self._remaining = core.get(u'remaining', 0)
return self._remaining
|
'Re-retrieve the information for this object.
The reasoning for the return value is the following example: ::
repos = [r.refresh() for r in g.repositories_by(\'kennethreitz\')]
Without the return value, that would be an array of ``None``\'s and you
would otherwise have to do: ::
repos = [r for i in g.repositories_by(\'... | def refresh(self, conditional=False):
| headers = getattr(self, u'CUSTOM_HEADERS', {})
if conditional:
if self.last_modified:
headers[u'If-Modified-Since'] = self.last_modified
elif self.etag:
headers[u'If-None-Match'] = self.etag
headers = (headers or None)
json = self._json(self._get(self._api, header... |
'Delete this comment.
:returns: bool'
| @requires_auth
def delete(self):
| return self._boolean(self._delete(self._api), 204, 404)
|
'Edit this comment.
:param str body: (required), new body of the comment, Markdown
formatted
:returns: bool'
| @requires_auth
def edit(self, body):
| if body:
json = self._json(self._patch(self._api, data=dumps({u'body': body})), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Set the Basic Auth credentials on this Session.
:param str username: Your GitHub username
:param str password: Your GitHub password'
| def basic_auth(self, username, password):
| if (not (username and password)):
return
self.auth = (username, password)
self.headers.pop('Authorization', None)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.