Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Search users #59

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ docs/_build
dist/
build/
*egg-info
.idea/
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Patches and Suggestions
- Ralph Bean <[email protected]>
- Jason A. Donenfeld <[email protected]>
- Brad Montgomery <http://about.me/bkmontgomery>
- Abderrahmane Benbachir <[email protected]>
2 changes: 1 addition & 1 deletion pygithub3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-

__title__ = 'pygithub3'
__version__ = '0.5'
__version__ = '0.5.1'
__author__ = 'David Medina'
__email__ = '[email protected]'
__license__ = 'ISC'
Expand Down
5 changes: 2 additions & 3 deletions pygithub3/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def set_credentials(self, login, password):

def set_token(self, token):
if token:
self.requester.params.append(('access_token', token))
self.requester.params['access_token'] = token

def __set_params(self, config):
per_page = ('per_page', config.get('per_page'))
self.requester.params.append(per_page)
self.requester.params['per_page'] = config.get('per_page')
if config.get('verbose'):
self.requester.config = {'verbose': config['verbose']}
if config.get('timeout'):
Expand Down
9 changes: 9 additions & 0 deletions pygithub3/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, **config):
from pygithub3.services.pull_requests import PullRequests
from pygithub3.services.orgs import Org
from pygithub3.services.issues import Issue
from pygithub3.services.search import Search
self._users = User(**config)
self._repos = Repo(**config)
self._gists = Gist(**config)
Expand All @@ -30,6 +31,7 @@ def __init__(self, **config):
self._orgs = Org(**config)
self._issues = Issue(**config)
self._events = Event(**config)
self._search = Search(**config)

@property
def remaining_requests(self):
Expand Down Expand Up @@ -92,3 +94,10 @@ def events(self):
:ref:`Events service <Events service>`
"""
return self._events

@property
def search(self):
"""
:ref:`Search service <Search service>`
"""
return self._search
3 changes: 3 additions & 0 deletions pygithub3/requests/search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- encoding: utf-8 -*-

from pygithub3.requests.base import Request, ValidationError
12 changes: 12 additions & 0 deletions pygithub3/requests/search/search_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from . import Request
from pygithub3.resources.search import SearchUsers


class List(Request):

resource = SearchUsers
uri = 'search/users'

21 changes: 21 additions & 0 deletions pygithub3/resources/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from .base import Resource
from .users import User

__all__ = ('SearchUsers', 'SearchIssues')


class SearchUsers(Resource):
_maps = {'user': User}
def __str__(self):
return '<SearchUsers (%s)>' % getattr(self, 'login', '')


class SearchIssues(Resource):

def __str__(self):
return '<SearchIssues (%s)>' % getattr(self, 'title', '')


11 changes: 2 additions & 9 deletions pygithub3/services/issues/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def __init__(self, **config):
self.milestones = Milestones(**config)
super(Issue, self).__init__(**config)

def list(self, filter='assigned', state='open', labels='', sort='created',
direction='desc', since=None):
def list(self, **params):
""" List your issues

:param str filter: 'assigned', 'created', 'mentioned' or 'subscribed'
Expand All @@ -33,14 +32,10 @@ def list(self, filter='assigned', state='open', labels='', sort='created',
.. warning::
You must be authenticated
"""
params = dict(filter=filter, state=state, labels=labels, sort=sort,
direction=direction)
request = self.request_builder('issues.list')
return self._get_result(request, **params)

def list_by_repo(self, user=None, repo=None, milestone='*', state='open',
assignee='*', mentioned='', labels='', sort='created',
direction='desc', since=None):
def list_by_repo(self, user=None, repo=None, **params):
""" List issues for a repo

:param str milestone: Milestone ID, 'none' or '*'
Expand All @@ -57,8 +52,6 @@ def list_by_repo(self, user=None, repo=None, milestone='*', state='open',
.. note::
Remember :ref:`config precedence`
"""
params = dict(milestone=milestone, state=state, assignee=assignee,
mentioned=mentioned, labels=labels, sort=sort, direction=direction)
request = self.make_request('issues.list_by_repo', user=user,
repo=repo)
return self._get_result(request, **params)
Expand Down
6 changes: 2 additions & 4 deletions pygithub3/services/issues/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class Milestones(Service):
""" Consume `Milestones API
<http://developer.github.com/v3/issues/milestones>`_ """

def list(self, user=None, repo=None, state='open', sort='due_date',
direction='desc'):
def list(self, user=None, repo=None, **params):
""" List milestones for a repo

:param str user: Username
Expand All @@ -24,8 +23,7 @@ def list(self, user=None, repo=None, state='open', sort='due_date',
"""
request = self.make_request('issues.milestones.list', user=user,
repo=repo)
return self._get_result(request, state=state, sort=sort,
direction=direction)
return self._get_result(request, **params)

def get(self, number, user=None, repo=None):
""" Get a single milestone
Expand Down
15 changes: 15 additions & 0 deletions pygithub3/services/search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from pygithub3.services.base import Service
from .search_users import SearchUsers


class Search(Service):
""" Consume `Users API <http://developer.github.com/v3/search>`_ """

def __init__(self, **config):
super(Search, self).__init__(**config)
self.search_users = SearchUsers(**config)


20 changes: 20 additions & 0 deletions pygithub3/services/search/search_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from pygithub3.services.base import Service
from pprint import pprint

class SearchUsers(Service):
""" Consume `Followers API
<https://developer.github.com/v3/search/#search-users>`_
"""

def list(self, query=None, sort=None, order=None):

request = self.request_builder('search.search_users.list', query=query, sort=sort, order=order)

return self._get(request, q=query)




33 changes: 33 additions & 0 deletions pygithub3/tests/services/test_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- encoding: utf-8 -*-

import requests
from pprint import pprint
from mock import patch

from pygithub3.core.client import Client
from pygithub3.exceptions import ValidationError
from pygithub3.services.search.search_users import SearchUsers
from pygithub3.tests.utils.base import (dummy_json, mock_response,
mock_response_result)
from pygithub3.tests.utils.core import TestCase
from pygithub3.tests.utils.services import _


@dummy_json
@patch.object(requests.sessions.Session, 'request')
class TestSearchUsersService(TestCase):

def setUp(self):
self.search_users = SearchUsers()

# def test_GET_without_user(self, request_method):
# request_method.return_value = mock_response()
# self.us.get()
# self.assertEqual(request_method.call_args[0], ('get', _('user')))

def test_GET_LIST(self, request_method):
request_method.return_value = mock_response()
result = self.search_users.list(query='abder')
# self.assertEqual(request_method.call_args[0], ('get', _('users/octocat')))


2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==0.14.0
requests>=2.0.0