public
Description: Python interface for talking to the github API
Clone URL: git://github.com/dustin/py-github.git
Support for the search API.
dustin (author)
Sat May 24 12:22:18 -0700 2008
commit  599cd864ea345af6f9e0ee59aba840f13e5d201f
tree    1cbfbc6dcff5dc49b2c017b84ad65b38b834798f
parent  1f9c99aeb941e3cc59e4db9ec56b15f248ec3412
...
72
73
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
76
77
...
145
146
147
 
 
 
 
 
 
 
148
149
150
...
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
168
169
170
171
172
173
174
175
176
177
178
179
180
0
@@ -72,6 +72,29 @@ class Person(object):
0
     def __repr__(self):
0
         return "<<Person %s <%s>>>" % (self.name, self.email)
0
 
0
+class SearchResults(object):
0
+ """Search results."""
0
+
0
+ def __init__(self, el):
0
+ ch=el.firstChild
0
+ self.repos=[Repository(el)
0
+ for el in el.getElementsByTagName('repository')]
0
+
0
+ def __iter__(self):
0
+ return iter(self.repos)
0
+
0
+ def __getitem__(self, which):
0
+ return self.repos[which]
0
+
0
+ def __getslice__(self, i, j):
0
+ return self.repos[i:j]
0
+
0
+ def __len__(self):
0
+ return len(self.repos)
0
+
0
+ def __repr__(self):
0
+ return "<<SearchResults with %d repos>>" % len(self.repos)
0
+
0
 class User(Person):
0
     """A github user."""
0
 
0
@@ -145,6 +168,13 @@ class GitHub(object):
0
         doc=xml.dom.minidom.parseString(x)
0
         return User(doc)
0
 
0
+ def search(self, keywords):
0
+ """Search for repositories."""
0
+ x=self.fetcher("http://github.com/api/v1/xml/search/%s"
0
+ % keywords.replace(' ', '+')).read()
0
+ doc=xml.dom.minidom.parseString(x)
0
+ return SearchResults(doc)
0
+
0
     def commits(self, username, repo, branch):
0
         """Get the recent commits for the given repo."""
0
         x=self.fetcher("http://github.com/api/v1/xml/%s/%s/commits/%s"
...
20
21
22
 
 
 
 
23
24
25
...
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
...
20
21
22
23
24
25
26
27
28
29
...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
0
@@ -20,6 +20,10 @@ class GitHubTest(unittest.TestCase):
0
         return self.__gh('http://github.com/api/v1/xml/dustin',
0
             'data/user.xml').user('dustin')
0
 
0
+ def __loadSearch(self):
0
+ return self.__gh('http://github.com/api/v1/xml/search/merb+stuff',
0
+ 'data/search.xml').search('merb stuff')
0
+
0
     def __loadCommits(self):
0
         return self.__gh(
0
             'http://github.com/api/v1/xml/caged/gitnub/commits/master',
0
@@ -64,6 +68,41 @@ class GitHubTest(unittest.TestCase):
0
         u=self.__loadUser()
0
         self.assertEquals(3, u.repos['java-memcached-client'].forks)
0
 
0
+ def testSearchLen(self):
0
+ """Test search results len"""
0
+ res=self.__loadSearch()
0
+ self.assertEquals(30, len(res))
0
+
0
+ def testSearchSplicing(self):
0
+ """Test search results splicing operator"""
0
+ res=self.__loadSearch()
0
+ self.assertEquals(3, len(res[:3]))
0
+ self.assertEquals(3, len(res[3:6]))
0
+
0
+ self.assertEquals('merb-installer', res[-2:][0].name)
0
+
0
+ def testSearchIteration(self):
0
+ """Test search results iteration"""
0
+ res=self.__loadSearch()
0
+ c=0
0
+ for r in res:
0
+ c += 1
0
+ self.assertTrue(isinstance(r.forks, int))
0
+ self.assertEquals(30, c)
0
+
0
+ def testSearchGetItem(self):
0
+ """Test search results get item"""
0
+ res=self.__loadSearch()
0
+
0
+ self.assertEquals('merb-simple-model', res[1].name)
0
+ self.assertEquals('merb_active_admin', res[-3].name)
0
+
0
+ def testSearchRepr(self):
0
+ """Test search results repr"""
0
+ res=self.__loadSearch()
0
+
0
+ self.assertEquals('<<SearchResults with 30 repos>>', `res`)
0
+
0
     def testCommitsBase(self):
0
         commits=self.__loadCommits()
0
         self.assertEquals(30, len(commits))

Comments

    No one has commented yet.