hubba 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8362d3b3f03aadf2fb3708be499e3daeccfe343d
4
- data.tar.gz: ce865016b107b78fbd72d3817364040551d61596
3
+ metadata.gz: 63505774303ed6881c5650478eb76a1df7a3d412
4
+ data.tar.gz: 517173da9e008bd5d9ea74d2e9d8d1622edf7fdf
5
5
  SHA512:
6
- metadata.gz: 37c9ed873b55c67f5db957ea663222f3a6c0bb9ee8e4b5c58ca52917159407e1cf88e2bba9f86bcf63d42431a531dc09c0954bd9e9f1c66a0b4dab724c34534d
7
- data.tar.gz: 9fbb4951feade4506e5721c9cb635856227f346def9f11d50557048f8acb41e1e927901617de5177d9c8363c2513b9bfa3b354b7bc5f532c77f1b53e6d0dd525
6
+ metadata.gz: 8a806d4ee314cc13c1605781cbc6af7192600d2c34ec9ebccc949541a800a41d93d43def28600aa0d27e7526a47afa1e319bc2184ec4cee1c917196cc080ca91
7
+ data.tar.gz: bcc42747f508c0acab55a8f652be1103afef20d9409172081bba34a530a9bbc441a2d5ec109bcd4b43e3049a3b3f74fc1c478d17e9c84a7e7ce41e7dabd11014
@@ -3,19 +3,16 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/hubba.rb
6
- lib/hubba/cache.rb
7
6
  lib/hubba/client.rb
7
+ lib/hubba/config.rb
8
8
  lib/hubba/github.rb
9
9
  lib/hubba/stats.rb
10
10
  lib/hubba/version.rb
11
- test/cache/users~geraldb~orgs.json
12
- test/cache/users~geraldb~repos.json
13
11
  test/helper.rb
14
12
  test/stats/jekyll~minima.json
15
13
  test/stats/openblockchains~awesome-blockchains.json
16
14
  test/stats/opendatajson~factbook.json.json
17
15
  test/stats/poole~hyde.json
18
- test/test_cache.rb
19
16
  test/test_config.rb
20
17
  test/test_stats.rb
21
18
  test/test_stats_tmp.rb
@@ -3,11 +3,18 @@ require 'webclient'
3
3
 
4
4
  # our own code
5
5
  require 'hubba/version' # note: let version always go first
6
- require 'hubba/cache'
6
+ require 'hubba/config'
7
7
  require 'hubba/client'
8
8
  require 'hubba/github'
9
9
  require 'hubba/stats'
10
10
 
11
11
 
12
+ ############
13
+ # add convenience alias for alternate spelling - why? why not?
14
+ module Hubba
15
+ GitHub = Github
16
+ end
17
+
18
+
12
19
  # say hello
13
20
  puts Hubba.banner if defined?($RUBYCOCO_DEBUG)
@@ -0,0 +1,46 @@
1
+ module Hubba
2
+
3
+ class Configuration
4
+ def data_dir() @data_dir || './data'; end
5
+ def data_dir=( value ) @data_dir = value; end
6
+
7
+ # try default setup via ENV variables
8
+ def token() @token || ENV[ 'HUBBA_TOKEN' ]; end
9
+ def token=( value ) @token = value; end
10
+
11
+ # todo/check: use HUBBA_LOGIN - why? why not?
12
+ def user() @user || ENV[ 'HUBBA_USER' ]; end
13
+ def password() @password || ENV[ 'HUBBA_PASSWORD' ]; end
14
+ def user=( value ) @user = value; end
15
+ def password=( value ) @password = value; end
16
+
17
+ end # class Configuration
18
+
19
+
20
+ ## lets you use
21
+ ## Hubba.configure do |config|
22
+ ## config.token = 'secret'
23
+ ## -or-
24
+ ## config.user = 'testdada'
25
+ ## config.password = 'secret'
26
+ ## end
27
+ ##
28
+ ## move configure block to GitHub class - why? why not?
29
+ ## e.g. GitHub.configure do |config|
30
+ ## ...
31
+ ## end
32
+
33
+
34
+ def self.configuration
35
+ @configuration ||= Configuration.new
36
+ end
37
+ class << self
38
+ alias_method :config, :configuration
39
+ end
40
+
41
+
42
+ def self.configure
43
+ yield( configuration )
44
+ end
45
+
46
+ end # module Hubba
@@ -1,42 +1,5 @@
1
1
  module Hubba
2
2
 
3
- class Configuration
4
- attr_accessor :token
5
-
6
- attr_accessor :user
7
- attr_accessor :password
8
-
9
- def initialize
10
- # try default setup via ENV variables
11
- @token = ENV[ 'HUBBA_TOKEN' ]
12
-
13
- @user = ENV[ 'HUBBA_USER' ] ## use HUBBA_LOGIN - why? why not?
14
- @password = ENV[ 'HUBBA_PASSWORD' ]
15
- end
16
- end
17
-
18
- ## lets you use
19
- ## Hubba.configure do |config|
20
- ## config.token = 'secret'
21
- ## #-or-
22
- ## config.user = 'testdada'
23
- ## config.password = 'secret'
24
- ## end
25
- ##
26
- ## move configure block to GitHub class - why? why not?
27
- ## e.g. GitHub.configure do |config|
28
- ## ...
29
- ## end
30
-
31
-
32
- def self.configuration
33
- @configuration ||= Configuration.new
34
- end
35
-
36
- def self.configure
37
- yield( configuration )
38
- end
39
-
40
3
 
41
4
  class Resource
42
5
  attr_reader :data
@@ -64,9 +27,7 @@ end
64
27
 
65
28
  class Github
66
29
 
67
- def initialize( cache_dir: './cache' )
68
- @cache = Cache.new( cache_dir )
69
-
30
+ def initialize
70
31
  @client = if Hubba.configuration.token
71
32
  Client.new( token: Hubba.configuration.token )
72
33
  elsif Hubba.configuration.user &&
@@ -76,15 +37,8 @@ def initialize( cache_dir: './cache' )
76
37
  else
77
38
  Client.new
78
39
  end
79
-
80
- @offline = false
81
40
  end
82
41
 
83
- def offline!() @offline = true; end ## switch to offline - todo: find a "better" way - why? why not?
84
- def online!() @offline = false; end
85
- def offline?() @offline == true; end
86
- def online?() @offline == false; end
87
-
88
42
 
89
43
  def user( name )
90
44
  Resource.new( get "/users/#{name}" )
@@ -108,6 +62,7 @@ def user_orgs( name )
108
62
  end
109
63
 
110
64
 
65
+
111
66
  def org( name )
112
67
  Resource.new( get "/orgs/#{name}" )
113
68
  end
@@ -127,20 +82,28 @@ def repo_commits( full_name )
127
82
  end
128
83
 
129
84
 
130
- private
131
- def get( request_uri )
132
- if offline?
133
- @cache.get( request_uri )
85
+
86
+ ####
87
+ # more
88
+ def update( obj )
89
+ if obj.is_a?( Stats )
90
+ full_name = obj.full_name
91
+ puts "[update 1/2] fetching repo >#{full_name}<..."
92
+ repo = repo( full_name )
93
+ puts "[update 2/2] fetching repo >#{full_name}< commits ..."
94
+ commits = repo_commits( full_name )
95
+
96
+ obj.update( repo, commits )
134
97
  else
135
- @client.get( request_uri )
98
+ raise ArgumentError, "unknown source object passed in - expected Hubba::Stats; got #{obj.class.name}"
136
99
  end
137
100
  end
138
101
 
139
- end # class Github
140
-
141
- ############
142
- # add convenience alias for alternate spelling - why? why not?
143
- GitHub = Github
144
102
 
103
+ private
104
+ def get( request_uri )
105
+ @client.get( request_uri )
106
+ end
145
107
 
146
- end # module Hubba
108
+ end # class Github
109
+ end # module Hubba
@@ -10,56 +10,73 @@ module Hubba
10
10
  def initialize( full_name )
11
11
  @data = {}
12
12
  @data['full_name'] = full_name # e.g. poole/hyde etc.
13
+
14
+ @cache = {}
13
15
  end
14
16
 
15
17
 
16
- def full_name() @full_name ||= @data['full_name']; end
18
+ def full_name() @data['full_name']; end
19
+
17
20
 
18
21
  ## note: return datetime objects (NOT strings); if not present/available return nil/null
19
- def created_at() @created_at ||= @data['created_at'] ? DateTime.strptime( @data['created_at'], '%Y-%m-%dT%H:%M:%S') : nil; end
20
- def updated_at() @updated_at ||= @data['updated_at'] ? DateTime.strptime( @data['updated_at'], '%Y-%m-%dT%H:%M:%S') : nil; end
21
- def pushed_at() @pushed_at ||= @data['pushed_at'] ? DateTime.strptime( @data['pushed_at'], '%Y-%m-%dT%H:%M:%S') : nil; end
22
+ def created_at() @cache['created_at'] ||= parse_datetime( @data['created_at'] ); end
23
+ def updated_at() @cache['updated_at'] ||= parse_datetime( @data['updated_at'] ); end
24
+ def pushed_at() @cache['pushed_at'] ||= parse_datetime( @data['pushed_at'] ); end
22
25
 
23
26
  ## date (only) versions
24
- def created() @created ||= @data['created_at'] ? Date.strptime( @data['created_at'], '%Y-%m-%d') : nil; end
25
- def updated() @updated ||= @data['updated_at'] ? Date.strptime( @data['updated_at'], '%Y-%m-%d') : nil; end
26
- def pushed() @pushed ||= @data['pushed_at'] ? Date.strptime( @data['pushed_at'], '%Y-%m-%d') : nil; end
27
-
28
-
29
-
30
- def history() @history ||= @data['history'] ? build_history( @data['history'] ) : nil; end
27
+ def created() @cache['created'] ||= parse_date( @data['created_at'] ); end
28
+ def updated() @cache['updated'] ||= parse_date( @data['updated_at'] ); end
29
+ def pushed() @cache['pushed'] ||= parse_date( @data['pushed_at'] ); end
31
30
 
32
31
  def size
33
32
  # size of repo in kb (as reported by github api)
34
- @size ||= @data['size'] || 0 ## return 0 if not found - why? why not? (return nil - why? why not??)
33
+ @data['size'] || 0 ## return 0 if not found - why? why not? (return nil - why? why not??)
35
34
  end
36
35
 
36
+
37
+ def history
38
+ @cache['history'] ||= begin
39
+ if @data['history']
40
+ build_history( @data['history'] )
41
+ else
42
+ nil
43
+ end
44
+ end
45
+ end
46
+
47
+
37
48
  def stars
38
49
  ## return last stargazers_count entry (as number; 0 if not found)
39
- @stars ||= history ? history[0].stars : 0
50
+ @cache['stars'] ||= history ? history[0].stars : 0
40
51
  end
41
52
 
42
53
 
43
54
  def commits() @data['commits']; end
44
55
 
45
- def last_commit() ## convenience shortcut; get first/last commit (use [0]) or nil
56
+ def last_commit ## convenience shortcut; get first/last commit (use [0]) or nil
46
57
  if @data['commits'] && @data['commits'][0]
47
58
  @data['commits'][0]
48
59
  else
49
- nil
60
+ nil
50
61
  end
51
62
  end
52
63
 
53
- def committed() ## last commit date (from author NOT committer)
54
- @committed ||= last_commit ? Date.strptime( last_commit['author']['date'], '%Y-%m-%d') : nil
64
+
65
+ def committed ## last commit date (from author NOT committer)
66
+ @cache['committed'] ||= parse_date( last_commit_author_date )
55
67
  end
56
68
 
57
69
  def committed_at() ## last commit date (from author NOT committer)
58
- @committed_at ||= last_commit ? DateTime.strptime( last_commit['author']['date'], '%Y-%m-%dT%H:%M:%S') : nil
70
+ @cache['committed_at'] ||= parse_datetime( last_commit_author_date )
71
+ end
72
+
73
+ def last_commit_author_date
74
+ h = last_commit
75
+ h ? h['author']['date'] : nil
59
76
  end
60
77
 
61
78
 
62
- def last_commit_message() ## convenience shortcut; last commit message
79
+ def last_commit_message ## convenience shortcut; last commit message
63
80
  h = last_commit
64
81
 
65
82
  committer_name = h['committer']['name']
@@ -77,20 +94,10 @@ module Hubba
77
94
 
78
95
 
79
96
 
80
- def reset_cache
81
- ## reset (invalidate) cached values from data hash
82
- ## use after reading or fetching
83
- @full_name = nil
84
- @created_at = @updated_at = @pushed_at = nil
85
- @created = @updated = @pused = nil
86
- @history = nil
87
- @size = nil
88
- @stars = nil
89
-
90
- @committed_at = nil
91
- @committed = nil
92
- end
93
-
97
+ ###
98
+ # helpers
99
+ def parse_datetime( str ) str ? DateTime.strptime( str, '%Y-%m-%dT%H:%M:%S') : nil; end
100
+ def parse_date( str ) str ? Date.strptime( str, '%Y-%m-%d') : nil; end
94
101
 
95
102
  ########
96
103
  ## build history items (structs)
@@ -187,7 +194,8 @@ module Hubba
187
194
  end
188
195
  end
189
196
 
190
- def history_str
197
+
198
+ def history_str ## todo/check: rename/change to format_history or fmt_history - why? why not?
191
199
  ## returns "pretty printed" history as string buffer
192
200
  buf = ''
193
201
  buf << "[#{history.size}]: "
@@ -214,12 +222,13 @@ module Hubba
214
222
  end # method history_str
215
223
 
216
224
 
225
+
217
226
  ###############################
218
227
  ## fetch / read / write methods
219
228
 
220
- def fetch( gh ) ## update stats / fetch data from github via api
221
- puts "fetching #{full_name}..."
222
- repo = gh.repo( full_name )
229
+ def update( repo, commits ) ## update stats / fetch data from github via api
230
+ raise ArgumentError, "Hubba::Resource expected; got #{repo.class.name}" unless repo.is_a?( Resource )
231
+ raise ArgumentError, "Hubba::Resource expected; got #{commits.class.name}" unless commits.is_a?( Resource )
223
232
 
224
233
  ## e.g. 2015-05-11T20:21:43Z
225
234
  ## puts Time.iso8601( repo.data['created_at'] )
@@ -244,7 +253,6 @@ module Hubba
244
253
 
245
254
  ##########################
246
255
  ## also check / keep track of (latest) commit
247
- commits = gh.repo_commits( full_name )
248
256
  puts "last commit/update:"
249
257
  ## pp commits
250
258
  commit = {
@@ -264,15 +272,21 @@ module Hubba
264
272
 
265
273
  pp @data
266
274
 
267
- reset_cache
275
+ ## reset (invalidate) cached values from data hash
276
+ ## use after reading or fetching
277
+ @cache = {}
278
+
268
279
  self ## return self for (easy chaining)
269
280
  end
270
281
 
271
282
 
272
283
 
273
- def write( data_dir: './data' )
284
+ def write
274
285
  basename = full_name.gsub( '/', '~' ) ## e.g. poole/hyde become poole~hyde
275
- puts "writing stats to #{basename}..."
286
+ data_dir = Hubba.config.data_dir
287
+ puts "writing stats to #{basename} (#{data_dir})..."
288
+
289
+ ## todo/fix: add FileUtils.makepath_r or such!!!
276
290
  File.open( "#{data_dir}/#{basename}.json", 'w:utf-8' ) do |f|
277
291
  f.write JSON.pretty_generate( data )
278
292
  end
@@ -280,17 +294,22 @@ module Hubba
280
294
  end
281
295
 
282
296
 
283
- def read( data_dir: './data' )
297
+ def read
284
298
  ## note: skip reading if file not present
285
299
  basename = full_name.gsub( '/', '~' ) ## e.g. poole/hyde become poole~hyde
286
- filename = "#{data_dir}/#{basename}.json"
287
- if File.exist?( filename )
288
- puts "reading stats from #{basename}..."
289
- json = File.open( filename, 'r:utf-8' ) { |file| file.read } ## todo/fix: use read_utf8
300
+ data_dir = Hubba.config.data_dir
301
+ path = "#{data_dir}/#{basename}.json"
302
+
303
+ if File.exist?( path )
304
+ puts "reading stats from #{basename} (#{data_dir})..."
305
+ json = File.open( path, 'r:utf-8' ) { |f| f.read }
290
306
  @data = JSON.parse( json )
291
- reset_cache
307
+
308
+ ## reset (invalidate) cached values from data hash
309
+ ## use after reading or fetching
310
+ @cache = {}
292
311
  else
293
- puts "skipping reading stats from #{basename} -- file not found"
312
+ puts "!! WARN: - skipping reading stats from #{basename} -- file not found"
294
313
  end
295
314
  self ## return self for (easy chaining)
296
315
  end
@@ -1,7 +1,7 @@
1
1
  module Hubba
2
2
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
3
- MINOR = 5
4
- PATCH = 2
3
+ MINOR = 6
4
+ PATCH = 0
5
5
  VERSION = [MAJOR,MINOR,PATCH].join('.')
6
6
 
7
7
  def self.version
@@ -12,10 +12,20 @@ class TestConfig < MiniTest::Test
12
12
  Hubba.configure do |config|
13
13
  config.user = 'user1'
14
14
  config.password = 'password1'
15
+ # -or-
16
+ config.token = 'token1'
15
17
  end
16
18
 
17
19
  assert_equal 'user1', Hubba.configuration.user
18
20
  assert_equal 'password1', Hubba.configuration.password
21
+ assert_equal 'token1', Hubba.configuration.token
22
+
23
+ assert_equal 'user1', Hubba.config.user
24
+ assert_equal 'password1', Hubba.config.password
25
+ assert_equal 'token1', Hubba.config.token
26
+
27
+ assert_equal './data', Hubba.configuration.data_dir
28
+ assert_equal './data', Hubba.config.data_dir
19
29
  end
20
30
 
21
31
  end # class TestConfig
@@ -17,7 +17,8 @@ class TestStats < MiniTest::Test
17
17
  assert_equal 0, stats.stars
18
18
  assert_nil stats.history
19
19
 
20
- stats.read( data_dir: "#{Hubba.root}/test/stats" )
20
+ Hubba.config.data_dir = "#{Hubba.root}/test/stats"
21
+ stats.read
21
22
 
22
23
  assert_equal 321, stats.size
23
24
  assert_equal 717, stats.stars
@@ -54,7 +55,8 @@ class TestStats < MiniTest::Test
54
55
  assert_equal 0, stats.stars
55
56
  assert_nil stats.history
56
57
 
57
- stats.read( data_dir: "#{Hubba.root}/test/stats" )
58
+ Hubba.config.data_dir = "#{Hubba.root}/test/stats"
59
+ stats.read
58
60
 
59
61
  assert_equal 1620, stats.size
60
62
  assert_equal 1526, stats.stars
@@ -91,7 +93,8 @@ class TestStats < MiniTest::Test
91
93
  assert_equal 0, stats.stars
92
94
  assert_nil stats.history
93
95
 
94
- stats.read( data_dir: "#{Hubba.root}/test/stats" )
96
+ Hubba.config.data_dir = "#{Hubba.root}/test/stats"
97
+ stats.read
95
98
 
96
99
  assert_equal 7355, stats.size
97
100
  assert_equal 539, stats.stars
@@ -99,7 +102,7 @@ class TestStats < MiniTest::Test
99
102
  assert_equal 536, stats.history[1].stars
100
103
  assert_equal 533, stats.history[2].stars
101
104
  assert_equal 457, stats.history[-1].stars
102
- assert_equal 7, stats.history.size
105
+ assert_equal 7, stats.history.size
103
106
 
104
107
  assert_equal Date.new(2018, 2, 8 ), stats.history[0].date
105
108
  assert_equal Date.new(2018, 1, 28 ), stats.history[1].date
@@ -9,7 +9,7 @@ require 'helper'
9
9
  class TestStatsTmp < MiniTest::Test
10
10
 
11
11
  def setup
12
- @gh = Hubba::Github.new( cache_dir: "#{Hubba.root}/test/cache" )
12
+ @gh = Hubba::Github.new
13
13
  end
14
14
 
15
15
  def test_stats
@@ -18,21 +18,24 @@ class TestStatsTmp < MiniTest::Test
18
18
  'jekyll/minima'
19
19
  ]
20
20
 
21
+
21
22
  repos.each do |repo|
22
23
  stats = Hubba::Stats.new( repo )
23
- # stats.read( data_dir: './tmp' )
24
- stats.read( data_dir: "#{Hubba.root}/test/stats" )
24
+
25
+ Hubba.config.data_dir = "#{Hubba.root}/test/stats"
26
+ stats.read()
25
27
 
26
28
  puts "stars before fetch: #{stats.stars}"
27
29
  puts "size before fetch: #{stats.size} kb"
28
30
 
29
31
  ## note/todo: enable for "live" online testing
30
- ## stats.fetch( @gh )
32
+ ## @gh.update( stats )
31
33
 
32
34
  puts "stars after fetch: #{stats.stars}"
33
35
  puts "size after fetch: #{stats.size} kb"
34
36
 
35
- stats.write( data_dir: './tmp' )
37
+ Hubba.config.data_dir = './tmp'
38
+ stats.write()
36
39
  end
37
40
 
38
41
  assert true # for now everything ok if we get here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webclient
@@ -72,19 +72,16 @@ files:
72
72
  - README.md
73
73
  - Rakefile
74
74
  - lib/hubba.rb
75
- - lib/hubba/cache.rb
76
75
  - lib/hubba/client.rb
76
+ - lib/hubba/config.rb
77
77
  - lib/hubba/github.rb
78
78
  - lib/hubba/stats.rb
79
79
  - lib/hubba/version.rb
80
- - test/cache/users~geraldb~orgs.json
81
- - test/cache/users~geraldb~repos.json
82
80
  - test/helper.rb
83
81
  - test/stats/jekyll~minima.json
84
82
  - test/stats/openblockchains~awesome-blockchains.json
85
83
  - test/stats/opendatajson~factbook.json.json
86
84
  - test/stats/poole~hyde.json
87
- - test/test_cache.rb
88
85
  - test/test_config.rb
89
86
  - test/test_stats.rb
90
87
  - test/test_stats_tmp.rb
@@ -1,61 +0,0 @@
1
- module Hubba
2
-
3
- class Cache ## lets you work with GitHub api "offline" using just a local cache of stored json
4
-
5
- def initialize( dir )
6
- @dir = dir
7
- end
8
-
9
- ## fix/todo: cut of query string e.g. ?per_page=100 why? why not?
10
- def get( request_uri )
11
- ## check if request_uri exists in local cache
12
- basename = request_uri_to_basename( request_uri )
13
- path = "#{@dir}/#{basename}.json"
14
- if File.exist?( path )
15
- text = File.open( path, 'r:utf-8') { |f| f.read }
16
- json = JSON.parse( text )
17
- json
18
- else
19
- nil ## todo/fix: raise exception - why? why not??
20
- end
21
- end
22
-
23
- def put( request_uri, obj )
24
- basename = request_uri_to_basename( request_uri )
25
- path = "#{@dir}/#{basename}.json"
26
-
27
- if obj.is_a?( Resource ) ## note: for convenience support Resource obj too
28
- data = obj.data
29
- else
30
- data = obj # assume Hash or Array -- todo: add support for String - why? why not??
31
- end
32
-
33
- File.open( path, 'w:utf-8' ) do |f|
34
- f.write( JSON.pretty_generate( data ))
35
- end
36
- end
37
-
38
-
39
- def request_uri_to_basename( request_uri )
40
- ## 1) cut off leading /
41
- ## 2) convert / to ~
42
- ## 3) remove (optional) query string (for now) - why? why not?
43
- ## e.g. /users/#{name}/orgs?per_page=100 or such
44
- ##
45
- ## e.g.
46
- ## '/users/geraldb' => 'users~geraldb',
47
- ## '/users/geraldb/repos' => 'users~geraldb~repos',
48
- ## '/users/geraldb/orgs' => 'users~geraldb~orgs',
49
- ## '/orgs/wikiscript/repos' => 'orgs~wikiscript~repos',
50
- ## '/orgs/planetjekyll/repos' => 'orgs~planetjekyll~repos',
51
- ## '/orgs/vienna-rb/repos' => 'orgs~vienna~rb.repos',
52
-
53
- basename = request_uri[1..-1]
54
- basename = basename.gsub( '/', '~')
55
- basename = basename.sub( /\?.*\z/, '' ) ## note: must escape ? (use \z for $)
56
- basename
57
- end
58
-
59
- end ## class Cache
60
-
61
- 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,43 +0,0 @@
1
- ###
2
- # to run use
3
- # ruby -I ./lib -I ./test test/test_cache.rb
4
-
5
-
6
- require 'helper'
7
-
8
-
9
- class TestCache < MiniTest::Test
10
-
11
- def setup
12
- @cache = Hubba::Cache.new( "#{Hubba.root}/test/cache" )
13
- end
14
-
15
- def test_basename
16
- mappings = [['/users/geraldb', 'users~geraldb'],
17
- ['/users/geraldb/repos', 'users~geraldb~repos'],
18
- ['/users/geraldb/repos?per_page=100', 'users~geraldb~repos'],
19
- ['/users/geraldb/orgs', 'users~geraldb~orgs'],
20
- ['/users/geraldb/orgs?per_page=100', 'users~geraldb~orgs'],
21
- ['/orgs/wikiscript/repos', 'orgs~wikiscript~repos'],
22
- ['/orgs/planetjekyll/repos', 'orgs~planetjekyll~repos'],
23
- ['/orgs/vienna-rb/repos', 'orgs~vienna-rb~repos']]
24
-
25
- mappings.each do |mapping|
26
- assert_equal mapping[1], @cache.request_uri_to_basename( mapping[0] )
27
- end
28
- end # method test_basename
29
-
30
- def test_cache
31
- orgs = @cache.get( '/users/geraldb/orgs' )
32
- assert_equal 4, orgs.size
33
-
34
- repos = @cache.get( '/users/geraldb/repos' )
35
- assert_equal 3, repos.size
36
- end # method test_cache
37
-
38
- def test_cache_miss
39
- assert_nil @cache.get( '/test/hello' )
40
- assert_nil @cache.get( '/test/hola' )
41
- end # method test_cache_miss
42
-
43
- end # class TestCache