hubba 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Hubba
4
-
5
- class Cache ## lets you work with GitHub api "offline" using just a local cache of stored json
6
-
7
- def initialize( dir )
8
- @dir = dir
9
- end
10
-
11
- ## fix/todo: cut of query string e.g. ?per_page=100 why? why not?
12
- def get( request_uri )
13
- ## check if request_uri exists in local cache
14
- basename = request_uri_to_basename( request_uri )
15
- path = "#{@dir}/#{basename}.json"
16
- if File.exist?( path )
17
- text = File.read( path ) ## todo/fix: use File.read_utf8
18
- json = JSON.parse( text )
19
- json
20
- else
21
- nil ## todo/fix: raise exception - why? why not??
22
- end
23
- end
24
-
25
- def put( request_uri, obj )
26
- basename = request_uri_to_basename( request_uri )
27
- path = "#{@dir}/#{basename}.json"
28
-
29
- if obj.is_a?( Resource ) ## note: for convenience support Resource obj too
30
- data = obj.data
31
- else
32
- data = obj # assume Hash or Array -- todo: add support for String - why? why not??
33
- end
34
-
35
- File.open( path, 'w' ) do |f|
36
- f.write JSON.pretty_generate( data )
37
- end
38
- end
39
-
40
-
41
- def request_uri_to_basename( request_uri )
42
- ## 1) cut off leading /
43
- ## 2) convert / to ~
44
- ## 3) remove (optional) query string (for now) - why? why not?
45
- ##
46
- ## e.g.
47
- ## '/users/geraldb' => 'users~geraldb',
48
- ## '/users/geraldb/repos' => 'users~geraldb~repos',
49
- ## '/users/geraldb/orgs' => 'users~geraldb~orgs',
50
- ## '/orgs/wikiscript/repos' => 'orgs~wikiscript~repos',
51
- ## '/orgs/planetjekyll/repos' => 'orgs~planetjekyll~repos',
52
- ## '/orgs/vienna-rb/repos' => 'orgs~vienna~rb.repos',
53
-
54
- basename = request_uri[1..-1]
55
- basename = basename.gsub( '/', '~')
56
- basename = basename.sub( /\?.*\z/, '' ) ## note: must escape ? (use \z for $)
57
- basename
58
- end
59
-
60
- end ## class Cache
61
-
62
- end ## module Hubba
@@ -1,46 +0,0 @@
1
- [
2
- {
3
- "login": "vienna-rb",
4
- "id": 3541331,
5
- "url": "https://api.github.com/orgs/vienna-rb",
6
- "repos_url": "https://api.github.com/orgs/vienna-rb/repos",
7
- "events_url": "https://api.github.com/orgs/vienna-rb/events",
8
- "members_url": "https://api.github.com/orgs/vienna-rb/members{/member}",
9
- "public_members_url": "https://api.github.com/orgs/vienna-rb/public_members{/member}",
10
- "avatar_url": "https://avatars.githubusercontent.com/u/3541331?v=3",
11
- "description": null
12
- },
13
- {
14
- "login": "openbeer",
15
- "id": 4464191,
16
- "url": "https://api.github.com/orgs/openbeer",
17
- "repos_url": "https://api.github.com/orgs/openbeer/repos",
18
- "events_url": "https://api.github.com/orgs/openbeer/events",
19
- "members_url": "https://api.github.com/orgs/openbeer/members{/member}",
20
- "public_members_url": "https://api.github.com/orgs/openbeer/public_members{/member}",
21
- "avatar_url": "https://avatars.githubusercontent.com/u/4464191?v=3",
22
- "description": "Open Public Domain Beer, Brewery n Brewpub Data - Incl. The Free World Beer Book"
23
- },
24
- {
25
- "login": "slideshow-s9",
26
- "id": 4464373,
27
- "url": "https://api.github.com/orgs/slideshow-s9",
28
- "repos_url": "https://api.github.com/orgs/slideshow-s9/repos",
29
- "events_url": "https://api.github.com/orgs/slideshow-s9/events",
30
- "members_url": "https://api.github.com/orgs/slideshow-s9/members{/member}",
31
- "public_members_url": "https://api.github.com/orgs/slideshow-s9/public_members{/member}",
32
- "avatar_url": "https://avatars.githubusercontent.com/u/4464373?v=3",
33
- "description": "Free Web Alternative to PowerPoint and Keynote Using Easy-to-Write and Easy-to-Read Plain Text Wiki-Style Markup"
34
- },
35
- {
36
- "login": "openfootball",
37
- "id": 4477026,
38
- "url": "https://api.github.com/orgs/openfootball",
39
- "repos_url": "https://api.github.com/orgs/openfootball/repos",
40
- "events_url": "https://api.github.com/orgs/openfootball/events",
41
- "members_url": "https://api.github.com/orgs/openfootball/members{/member}",
42
- "public_members_url": "https://api.github.com/orgs/openfootball/public_members{/member}",
43
- "avatar_url": "https://avatars.githubusercontent.com/u/4477026?v=3",
44
- "description": "Open Public Domain Football Data - Incl. The Free World Football Almanac"
45
- }
46
- ]
@@ -1,263 +0,0 @@
1
- [
2
- {
3
- "id": 33192631,
4
- "name": "austria",
5
- "full_name": "geraldb/austria",
6
- "owner": {
7
- "login": "geraldb",
8
- "id": 53281,
9
- "avatar_url": "https://avatars.githubusercontent.com/u/53281?v=3",
10
- "gravatar_id": "",
11
- "url": "https://api.github.com/users/geraldb",
12
- "html_url": "https://github.com/geraldb",
13
- "followers_url": "https://api.github.com/users/geraldb/followers",
14
- "following_url": "https://api.github.com/users/geraldb/following{/other_user}",
15
- "gists_url": "https://api.github.com/users/geraldb/gists{/gist_id}",
16
- "starred_url": "https://api.github.com/users/geraldb/starred{/owner}{/repo}",
17
- "subscriptions_url": "https://api.github.com/users/geraldb/subscriptions",
18
- "organizations_url": "https://api.github.com/users/geraldb/orgs",
19
- "repos_url": "https://api.github.com/users/geraldb/repos",
20
- "events_url": "https://api.github.com/users/geraldb/events{/privacy}",
21
- "received_events_url": "https://api.github.com/users/geraldb/received_events",
22
- "type": "User",
23
- "site_admin": false
24
- },
25
- "private": false,
26
- "html_url": "https://github.com/geraldb/austria",
27
- "description": "open data and scripts for austria (österreich)",
28
- "fork": false,
29
- "url": "https://api.github.com/repos/geraldb/austria",
30
- "forks_url": "https://api.github.com/repos/geraldb/austria/forks",
31
- "keys_url": "https://api.github.com/repos/geraldb/austria/keys{/key_id}",
32
- "collaborators_url": "https://api.github.com/repos/geraldb/austria/collaborators{/collaborator}",
33
- "teams_url": "https://api.github.com/repos/geraldb/austria/teams",
34
- "hooks_url": "https://api.github.com/repos/geraldb/austria/hooks",
35
- "issue_events_url": "https://api.github.com/repos/geraldb/austria/issues/events{/number}",
36
- "events_url": "https://api.github.com/repos/geraldb/austria/events",
37
- "assignees_url": "https://api.github.com/repos/geraldb/austria/assignees{/user}",
38
- "branches_url": "https://api.github.com/repos/geraldb/austria/branches{/branch}",
39
- "tags_url": "https://api.github.com/repos/geraldb/austria/tags",
40
- "blobs_url": "https://api.github.com/repos/geraldb/austria/git/blobs{/sha}",
41
- "git_tags_url": "https://api.github.com/repos/geraldb/austria/git/tags{/sha}",
42
- "git_refs_url": "https://api.github.com/repos/geraldb/austria/git/refs{/sha}",
43
- "trees_url": "https://api.github.com/repos/geraldb/austria/git/trees{/sha}",
44
- "statuses_url": "https://api.github.com/repos/geraldb/austria/statuses/{sha}",
45
- "languages_url": "https://api.github.com/repos/geraldb/austria/languages",
46
- "stargazers_url": "https://api.github.com/repos/geraldb/austria/stargazers",
47
- "contributors_url": "https://api.github.com/repos/geraldb/austria/contributors",
48
- "subscribers_url": "https://api.github.com/repos/geraldb/austria/subscribers",
49
- "subscription_url": "https://api.github.com/repos/geraldb/austria/subscription",
50
- "commits_url": "https://api.github.com/repos/geraldb/austria/commits{/sha}",
51
- "git_commits_url": "https://api.github.com/repos/geraldb/austria/git/commits{/sha}",
52
- "comments_url": "https://api.github.com/repos/geraldb/austria/comments{/number}",
53
- "issue_comment_url": "https://api.github.com/repos/geraldb/austria/issues/comments{/number}",
54
- "contents_url": "https://api.github.com/repos/geraldb/austria/contents/{+path}",
55
- "compare_url": "https://api.github.com/repos/geraldb/austria/compare/{base}...{head}",
56
- "merges_url": "https://api.github.com/repos/geraldb/austria/merges",
57
- "archive_url": "https://api.github.com/repos/geraldb/austria/{archive_format}{/ref}",
58
- "downloads_url": "https://api.github.com/repos/geraldb/austria/downloads",
59
- "issues_url": "https://api.github.com/repos/geraldb/austria/issues{/number}",
60
- "pulls_url": "https://api.github.com/repos/geraldb/austria/pulls{/number}",
61
- "milestones_url": "https://api.github.com/repos/geraldb/austria/milestones{/number}",
62
- "notifications_url": "https://api.github.com/repos/geraldb/austria/notifications{?since,all,participating}",
63
- "labels_url": "https://api.github.com/repos/geraldb/austria/labels{/name}",
64
- "releases_url": "https://api.github.com/repos/geraldb/austria/releases{/id}",
65
- "created_at": "2015-03-31T15:16:05Z",
66
- "updated_at": "2015-03-31T21:03:02Z",
67
- "pushed_at": "2015-03-31T21:03:02Z",
68
- "git_url": "git://github.com/geraldb/austria.git",
69
- "ssh_url": "git@github.com:geraldb/austria.git",
70
- "clone_url": "https://github.com/geraldb/austria.git",
71
- "svn_url": "https://github.com/geraldb/austria",
72
- "homepage": null,
73
- "size": 552,
74
- "stargazers_count": 1,
75
- "watchers_count": 1,
76
- "language": "Ruby",
77
- "has_issues": true,
78
- "has_downloads": true,
79
- "has_wiki": false,
80
- "has_pages": false,
81
- "forks_count": 0,
82
- "mirror_url": null,
83
- "open_issues_count": 0,
84
- "forks": 0,
85
- "open_issues": 0,
86
- "watchers": 1,
87
- "default_branch": "master"
88
- },
89
- {
90
- "id": 31158327,
91
- "name": "auto",
92
- "full_name": "geraldb/auto",
93
- "owner": {
94
- "login": "geraldb",
95
- "id": 53281,
96
- "avatar_url": "https://avatars.githubusercontent.com/u/53281?v=3",
97
- "gravatar_id": "",
98
- "url": "https://api.github.com/users/geraldb",
99
- "html_url": "https://github.com/geraldb",
100
- "followers_url": "https://api.github.com/users/geraldb/followers",
101
- "following_url": "https://api.github.com/users/geraldb/following{/other_user}",
102
- "gists_url": "https://api.github.com/users/geraldb/gists{/gist_id}",
103
- "starred_url": "https://api.github.com/users/geraldb/starred{/owner}{/repo}",
104
- "subscriptions_url": "https://api.github.com/users/geraldb/subscriptions",
105
- "organizations_url": "https://api.github.com/users/geraldb/orgs",
106
- "repos_url": "https://api.github.com/users/geraldb/repos",
107
- "events_url": "https://api.github.com/users/geraldb/events{/privacy}",
108
- "received_events_url": "https://api.github.com/users/geraldb/received_events",
109
- "type": "User",
110
- "site_admin": false
111
- },
112
- "private": false,
113
- "html_url": "https://github.com/geraldb/auto",
114
- "description": "auto - scripts to automate building databases, books, etc.",
115
- "fork": false,
116
- "url": "https://api.github.com/repos/geraldb/auto",
117
- "forks_url": "https://api.github.com/repos/geraldb/auto/forks",
118
- "keys_url": "https://api.github.com/repos/geraldb/auto/keys{/key_id}",
119
- "collaborators_url": "https://api.github.com/repos/geraldb/auto/collaborators{/collaborator}",
120
- "teams_url": "https://api.github.com/repos/geraldb/auto/teams",
121
- "hooks_url": "https://api.github.com/repos/geraldb/auto/hooks",
122
- "issue_events_url": "https://api.github.com/repos/geraldb/auto/issues/events{/number}",
123
- "events_url": "https://api.github.com/repos/geraldb/auto/events",
124
- "assignees_url": "https://api.github.com/repos/geraldb/auto/assignees{/user}",
125
- "branches_url": "https://api.github.com/repos/geraldb/auto/branches{/branch}",
126
- "tags_url": "https://api.github.com/repos/geraldb/auto/tags",
127
- "blobs_url": "https://api.github.com/repos/geraldb/auto/git/blobs{/sha}",
128
- "git_tags_url": "https://api.github.com/repos/geraldb/auto/git/tags{/sha}",
129
- "git_refs_url": "https://api.github.com/repos/geraldb/auto/git/refs{/sha}",
130
- "trees_url": "https://api.github.com/repos/geraldb/auto/git/trees{/sha}",
131
- "statuses_url": "https://api.github.com/repos/geraldb/auto/statuses/{sha}",
132
- "languages_url": "https://api.github.com/repos/geraldb/auto/languages",
133
- "stargazers_url": "https://api.github.com/repos/geraldb/auto/stargazers",
134
- "contributors_url": "https://api.github.com/repos/geraldb/auto/contributors",
135
- "subscribers_url": "https://api.github.com/repos/geraldb/auto/subscribers",
136
- "subscription_url": "https://api.github.com/repos/geraldb/auto/subscription",
137
- "commits_url": "https://api.github.com/repos/geraldb/auto/commits{/sha}",
138
- "git_commits_url": "https://api.github.com/repos/geraldb/auto/git/commits{/sha}",
139
- "comments_url": "https://api.github.com/repos/geraldb/auto/comments{/number}",
140
- "issue_comment_url": "https://api.github.com/repos/geraldb/auto/issues/comments{/number}",
141
- "contents_url": "https://api.github.com/repos/geraldb/auto/contents/{+path}",
142
- "compare_url": "https://api.github.com/repos/geraldb/auto/compare/{base}...{head}",
143
- "merges_url": "https://api.github.com/repos/geraldb/auto/merges",
144
- "archive_url": "https://api.github.com/repos/geraldb/auto/{archive_format}{/ref}",
145
- "downloads_url": "https://api.github.com/repos/geraldb/auto/downloads",
146
- "issues_url": "https://api.github.com/repos/geraldb/auto/issues{/number}",
147
- "pulls_url": "https://api.github.com/repos/geraldb/auto/pulls{/number}",
148
- "milestones_url": "https://api.github.com/repos/geraldb/auto/milestones{/number}",
149
- "notifications_url": "https://api.github.com/repos/geraldb/auto/notifications{?since,all,participating}",
150
- "labels_url": "https://api.github.com/repos/geraldb/auto/labels{/name}",
151
- "releases_url": "https://api.github.com/repos/geraldb/auto/releases{/id}",
152
- "created_at": "2015-02-22T09:27:17Z",
153
- "updated_at": "2015-04-06T14:16:32Z",
154
- "pushed_at": "2015-04-06T14:16:32Z",
155
- "git_url": "git://github.com/geraldb/auto.git",
156
- "ssh_url": "git@github.com:geraldb/auto.git",
157
- "clone_url": "https://github.com/geraldb/auto.git",
158
- "svn_url": "https://github.com/geraldb/auto",
159
- "homepage": null,
160
- "size": 288,
161
- "stargazers_count": 1,
162
- "watchers_count": 1,
163
- "language": "Ruby",
164
- "has_issues": true,
165
- "has_downloads": true,
166
- "has_wiki": false,
167
- "has_pages": false,
168
- "forks_count": 0,
169
- "mirror_url": null,
170
- "open_issues_count": 0,
171
- "forks": 0,
172
- "open_issues": 0,
173
- "watchers": 1,
174
- "default_branch": "master"
175
- },
176
- {
177
- "id": 33404369,
178
- "name": "backup",
179
- "full_name": "geraldb/backup",
180
- "owner": {
181
- "login": "geraldb",
182
- "id": 53281,
183
- "avatar_url": "https://avatars.githubusercontent.com/u/53281?v=3",
184
- "gravatar_id": "",
185
- "url": "https://api.github.com/users/geraldb",
186
- "html_url": "https://github.com/geraldb",
187
- "followers_url": "https://api.github.com/users/geraldb/followers",
188
- "following_url": "https://api.github.com/users/geraldb/following{/other_user}",
189
- "gists_url": "https://api.github.com/users/geraldb/gists{/gist_id}",
190
- "starred_url": "https://api.github.com/users/geraldb/starred{/owner}{/repo}",
191
- "subscriptions_url": "https://api.github.com/users/geraldb/subscriptions",
192
- "organizations_url": "https://api.github.com/users/geraldb/orgs",
193
- "repos_url": "https://api.github.com/users/geraldb/repos",
194
- "events_url": "https://api.github.com/users/geraldb/events{/privacy}",
195
- "received_events_url": "https://api.github.com/users/geraldb/received_events",
196
- "type": "User",
197
- "site_admin": false
198
- },
199
- "private": false,
200
- "html_url": "https://github.com/geraldb/backup",
201
- "description": "backup - scripts to backup repos, etc.",
202
- "fork": false,
203
- "url": "https://api.github.com/repos/geraldb/backup",
204
- "forks_url": "https://api.github.com/repos/geraldb/backup/forks",
205
- "keys_url": "https://api.github.com/repos/geraldb/backup/keys{/key_id}",
206
- "collaborators_url": "https://api.github.com/repos/geraldb/backup/collaborators{/collaborator}",
207
- "teams_url": "https://api.github.com/repos/geraldb/backup/teams",
208
- "hooks_url": "https://api.github.com/repos/geraldb/backup/hooks",
209
- "issue_events_url": "https://api.github.com/repos/geraldb/backup/issues/events{/number}",
210
- "events_url": "https://api.github.com/repos/geraldb/backup/events",
211
- "assignees_url": "https://api.github.com/repos/geraldb/backup/assignees{/user}",
212
- "branches_url": "https://api.github.com/repos/geraldb/backup/branches{/branch}",
213
- "tags_url": "https://api.github.com/repos/geraldb/backup/tags",
214
- "blobs_url": "https://api.github.com/repos/geraldb/backup/git/blobs{/sha}",
215
- "git_tags_url": "https://api.github.com/repos/geraldb/backup/git/tags{/sha}",
216
- "git_refs_url": "https://api.github.com/repos/geraldb/backup/git/refs{/sha}",
217
- "trees_url": "https://api.github.com/repos/geraldb/backup/git/trees{/sha}",
218
- "statuses_url": "https://api.github.com/repos/geraldb/backup/statuses/{sha}",
219
- "languages_url": "https://api.github.com/repos/geraldb/backup/languages",
220
- "stargazers_url": "https://api.github.com/repos/geraldb/backup/stargazers",
221
- "contributors_url": "https://api.github.com/repos/geraldb/backup/contributors",
222
- "subscribers_url": "https://api.github.com/repos/geraldb/backup/subscribers",
223
- "subscription_url": "https://api.github.com/repos/geraldb/backup/subscription",
224
- "commits_url": "https://api.github.com/repos/geraldb/backup/commits{/sha}",
225
- "git_commits_url": "https://api.github.com/repos/geraldb/backup/git/commits{/sha}",
226
- "comments_url": "https://api.github.com/repos/geraldb/backup/comments{/number}",
227
- "issue_comment_url": "https://api.github.com/repos/geraldb/backup/issues/comments{/number}",
228
- "contents_url": "https://api.github.com/repos/geraldb/backup/contents/{+path}",
229
- "compare_url": "https://api.github.com/repos/geraldb/backup/compare/{base}...{head}",
230
- "merges_url": "https://api.github.com/repos/geraldb/backup/merges",
231
- "archive_url": "https://api.github.com/repos/geraldb/backup/{archive_format}{/ref}",
232
- "downloads_url": "https://api.github.com/repos/geraldb/backup/downloads",
233
- "issues_url": "https://api.github.com/repos/geraldb/backup/issues{/number}",
234
- "pulls_url": "https://api.github.com/repos/geraldb/backup/pulls{/number}",
235
- "milestones_url": "https://api.github.com/repos/geraldb/backup/milestones{/number}",
236
- "notifications_url": "https://api.github.com/repos/geraldb/backup/notifications{?since,all,participating}",
237
- "labels_url": "https://api.github.com/repos/geraldb/backup/labels{/name}",
238
- "releases_url": "https://api.github.com/repos/geraldb/backup/releases{/id}",
239
- "created_at": "2015-04-04T12:14:24Z",
240
- "updated_at": "2015-06-28T11:55:10Z",
241
- "pushed_at": "2015-11-10T08:58:28Z",
242
- "git_url": "git://github.com/geraldb/backup.git",
243
- "ssh_url": "git@github.com:geraldb/backup.git",
244
- "clone_url": "https://github.com/geraldb/backup.git",
245
- "svn_url": "https://github.com/geraldb/backup",
246
- "homepage": null,
247
- "size": 184,
248
- "stargazers_count": 1,
249
- "watchers_count": 1,
250
- "language": "Ruby",
251
- "has_issues": true,
252
- "has_downloads": true,
253
- "has_wiki": true,
254
- "has_pages": false,
255
- "forks_count": 0,
256
- "mirror_url": null,
257
- "open_issues_count": 0,
258
- "forks": 0,
259
- "open_issues": 0,
260
- "watchers": 1,
261
- "default_branch": "master"
262
- }
263
- ]
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_cache.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestCache < MiniTest::Test
12
-
13
- def setup
14
- @cache = Hubba::Cache.new( "#{Hubba.root}/test/cache" )
15
- end
16
-
17
- def test_basename
18
- mappings = [['/users/geraldb', 'users~geraldb'],
19
- ['/users/geraldb/repos', 'users~geraldb~repos'],
20
- ['/users/geraldb/repos?per_page=100', 'users~geraldb~repos'],
21
- ['/users/geraldb/orgs', 'users~geraldb~orgs'],
22
- ['/users/geraldb/orgs?per_page=100', 'users~geraldb~orgs'],
23
- ['/orgs/wikiscript/repos', 'orgs~wikiscript~repos'],
24
- ['/orgs/planetjekyll/repos', 'orgs~planetjekyll~repos'],
25
- ['/orgs/vienna-rb/repos', 'orgs~vienna-rb~repos']]
26
-
27
- mappings.each do |mapping|
28
- assert_equal mapping[1], @cache.request_uri_to_basename( mapping[0] )
29
- end
30
- end # method test_basename
31
-
32
- def test_cache
33
- orgs = @cache.get( '/users/geraldb/orgs' )
34
- assert_equal 4, orgs.size
35
-
36
- repos = @cache.get( '/users/geraldb/repos' )
37
- assert_equal 3, repos.size
38
- end # method test_cache
39
-
40
- def test_cache_miss
41
- assert_equal nil, @cache.get( '/test/hello' )
42
- assert_equal nil, @cache.get( '/test/hola' )
43
- end # method test_cache_miss
44
-
45
- end # class TestCache
46
-