hubba 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{HISTORY.md → CHANGELOG.md} +0 -0
- data/Manifest.txt +1 -1
- data/README.md +20 -20
- data/Rakefile +4 -4
- data/lib/hubba.rb +3 -15
- data/lib/hubba/cache.rb +4 -5
- data/lib/hubba/client.rb +43 -20
- data/lib/hubba/github.rb +16 -4
- data/lib/hubba/stats.rb +0 -2
- data/lib/hubba/version.rb +1 -3
- data/test/helper.rb +0 -2
- data/test/test_cache.rb +0 -2
- data/test/test_config.rb +0 -2
- data/test/test_stats.rb +0 -2
- data/test/test_stats_tmp.rb +2 -4
- metadata +19 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84577f7d76ee6b6e2b0c1dd2c747536bede539fe
|
4
|
+
data.tar.gz: 9f42b72e4402d148eaccbfd635f316161a50a857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94e26559d4d814411a5537f879f58132c906ef7a3b2f7a61cc8f83d0e5f282b143d68f37a5462e5aef5e25daa86072b40e94c1b5177ab57023b80260f503b054
|
7
|
+
data.tar.gz: b9f03dba1f8861edbec94fb3411b2383dc1e12744387b9c6480b43a75ee6fa7331b57d81199a084cec742f0b35abf09167409d0328fd00a7da4fe3f15343a167
|
data/{HISTORY.md → CHANGELOG.md}
RENAMED
File without changes
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
# hubba
|
2
|
-
|
3
|
-
hubba gem - (yet) another (lite) GitHub HTTP API client / library
|
4
|
-
|
5
|
-
* home :: [github.com/
|
6
|
-
* bugs :: [github.com/
|
7
|
-
* gem :: [rubygems.org/gems/hubba](https://rubygems.org/gems/hubba)
|
8
|
-
* rdoc :: [rubydoc.info/gems/hubba](http://rubydoc.info/gems/hubba)
|
9
|
-
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
TBD
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
## License
|
18
|
-
|
19
|
-
The `hubba` scripts are dedicated to the public domain.
|
20
|
-
Use it as you please with no restrictions whatsoever.
|
1
|
+
# hubba
|
2
|
+
|
3
|
+
hubba gem - (yet) another (lite) GitHub HTTP API client / library
|
4
|
+
|
5
|
+
* home :: [github.com/rubycoco/git](https://github.com/rubycoco/git)
|
6
|
+
* bugs :: [github.com/rubycoco/git/issues](https://github.com/rubycoco/git/issues)
|
7
|
+
* gem :: [rubygems.org/gems/hubba](https://rubygems.org/gems/hubba)
|
8
|
+
* rdoc :: [rubydoc.info/gems/hubba](http://rubydoc.info/gems/hubba)
|
9
|
+
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TBD
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
The `hubba` scripts are dedicated to the public domain.
|
20
|
+
Use it as you please with no restrictions whatsoever.
|
data/Rakefile
CHANGED
@@ -8,23 +8,23 @@ Hoe.spec 'hubba' do
|
|
8
8
|
self.summary = 'hubba - (yet) another (lite) GitHub HTTP API client / library'
|
9
9
|
self.description = summary
|
10
10
|
|
11
|
-
self.urls =
|
11
|
+
self.urls = { home: 'https://github.com/rubycoco/git' }
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
14
|
self.email = 'ruby-talk@ruby-lang.org'
|
15
15
|
|
16
16
|
# switch extension to .markdown for gihub formatting
|
17
17
|
self.readme_file = 'README.md'
|
18
|
-
self.history_file = '
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
-
['
|
21
|
+
['webclient', '>= 0.1.1']
|
22
22
|
]
|
23
23
|
|
24
24
|
self.licenses = ['Public Domain']
|
25
25
|
|
26
26
|
self.spec_extras = {
|
27
|
-
required_ruby_version: '>= 2.
|
27
|
+
required_ruby_version: '>= 2.2.2'
|
28
28
|
}
|
29
29
|
|
30
30
|
end
|
data/lib/hubba.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'net/http'
|
4
|
-
require "net/https"
|
5
|
-
require 'uri'
|
6
|
-
|
7
|
-
require 'pp'
|
8
|
-
require 'json'
|
9
|
-
require 'yaml'
|
10
|
-
require 'time'
|
11
|
-
|
12
|
-
|
13
|
-
# 3rd party gems/libs
|
14
|
-
require 'logutils'
|
1
|
+
# 3rd party (our own)
|
2
|
+
require 'webclient'
|
15
3
|
|
16
4
|
# our own code
|
17
5
|
require 'hubba/version' # note: let version always go first
|
@@ -22,4 +10,4 @@ require 'hubba/stats'
|
|
22
10
|
|
23
11
|
|
24
12
|
# say hello
|
25
|
-
puts Hubba.banner if defined?($
|
13
|
+
puts Hubba.banner if defined?($RUBYCOCO_DEBUG)
|
data/lib/hubba/cache.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Hubba
|
4
2
|
|
5
3
|
class Cache ## lets you work with GitHub api "offline" using just a local cache of stored json
|
@@ -14,7 +12,7 @@ class Cache ## lets you work with GitHub api "offline" using just a local ca
|
|
14
12
|
basename = request_uri_to_basename( request_uri )
|
15
13
|
path = "#{@dir}/#{basename}.json"
|
16
14
|
if File.exist?( path )
|
17
|
-
text = File.
|
15
|
+
text = File.open( path, 'r:utf-8') { |f| f.read }
|
18
16
|
json = JSON.parse( text )
|
19
17
|
json
|
20
18
|
else
|
@@ -32,8 +30,8 @@ class Cache ## lets you work with GitHub api "offline" using just a local ca
|
|
32
30
|
data = obj # assume Hash or Array -- todo: add support for String - why? why not??
|
33
31
|
end
|
34
32
|
|
35
|
-
File.open( path, 'w' ) do |f|
|
36
|
-
f.write JSON.pretty_generate( data )
|
33
|
+
File.open( path, 'w:utf-8' ) do |f|
|
34
|
+
f.write( JSON.pretty_generate( data ))
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
@@ -42,6 +40,7 @@ class Cache ## lets you work with GitHub api "offline" using just a local ca
|
|
42
40
|
## 1) cut off leading /
|
43
41
|
## 2) convert / to ~
|
44
42
|
## 3) remove (optional) query string (for now) - why? why not?
|
43
|
+
## e.g. /users/#{name}/orgs?per_page=100 or such
|
45
44
|
##
|
46
45
|
## e.g.
|
47
46
|
## '/users/geraldb' => 'users~geraldb',
|
data/lib/hubba/client.rb
CHANGED
@@ -1,53 +1,76 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Hubba
|
4
2
|
|
5
3
|
|
6
4
|
class Client
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
BASE_URL = 'https://api.github.com'
|
7
|
+
|
8
|
+
|
9
|
+
def initialize( token: nil,
|
10
|
+
user: nil, password: nil )
|
11
|
+
## add support for (personal access) token
|
12
|
+
@token = token
|
13
13
|
|
14
14
|
## add support for basic auth - defaults to no auth (nil/nil)
|
15
|
+
## remove - deprecated (use token) - why? why not?
|
15
16
|
@user = user ## use login like Oktokit - why? why not?
|
16
17
|
@password = password
|
17
18
|
end # method initialize
|
18
19
|
|
20
|
+
|
21
|
+
|
19
22
|
def get( request_uri )
|
23
|
+
###
|
24
|
+
# e.g. /users/geraldb
|
25
|
+
# /users/geraldb/repos
|
26
|
+
|
20
27
|
puts "GET #{request_uri}"
|
28
|
+
url = "#{BASE_URL}/#{request_uri}"
|
21
29
|
|
22
|
-
|
23
|
-
##
|
24
|
-
##
|
25
|
-
req["User-Agent"] = "ruby/hubba" ## required by GitHub API
|
26
|
-
req["Accept" ] = "application/vnd.github.v3+json" ## recommend by GitHub API
|
30
|
+
headers = {}
|
31
|
+
headers['User-Agent'] = 'ruby/hubba' ## required by GitHub API
|
32
|
+
headers['Accept'] = 'application/vnd.github.v3+json' ## recommend by GitHub API
|
27
33
|
|
34
|
+
auth = []
|
28
35
|
## check if credentials (user/password) present - if yes, use basic auth
|
29
|
-
if @
|
36
|
+
if @token
|
37
|
+
puts " using (personal access) token - starting with: #{@token[0..6]}**********"
|
38
|
+
headers['Authorization'] = "token #{@token}"
|
39
|
+
## token works like:
|
40
|
+
## curl -H 'Authorization: token my_access_token' https://api.github.com/user/repos
|
41
|
+
elsif @user && @password
|
30
42
|
puts " using basic auth - user: #{@user}, password: ***"
|
31
|
-
|
43
|
+
## use credential auth "tuple" (that is, array with two string items) for now
|
44
|
+
## or use Webclient::HttpBasicAuth or something - why? why not?
|
45
|
+
auth = [@user, @password]
|
46
|
+
# req.basic_auth( @user, @password )
|
47
|
+
else
|
48
|
+
puts " using no credentials (no token, no user/password)"
|
32
49
|
end
|
33
50
|
|
34
|
-
res =
|
51
|
+
res = Webclient.get( url,
|
52
|
+
headers: headers,
|
53
|
+
auth: auth )
|
35
54
|
|
36
55
|
# Get specific header
|
37
56
|
# response["content-type"]
|
38
57
|
# => "text/html; charset=UTF-8"
|
39
58
|
|
40
59
|
# Iterate all response headers.
|
41
|
-
res.
|
42
|
-
|
60
|
+
res.headers.each do |key, value|
|
61
|
+
puts "#{key} => #{value}"
|
43
62
|
end
|
44
63
|
# => "location => http://www.google.com/"
|
45
64
|
# => "content-type => text/html; charset=UTF-8"
|
46
65
|
# ...
|
47
66
|
|
48
|
-
|
49
|
-
|
50
|
-
|
67
|
+
if res.status.ok?
|
68
|
+
res.json
|
69
|
+
else
|
70
|
+
puts "!! HTTP ERROR: #{res.status.code} #{res.status.message}:"
|
71
|
+
pp res.raw
|
72
|
+
exit 1
|
73
|
+
end
|
51
74
|
end # methdo get
|
52
75
|
|
53
76
|
end ## class Client
|
data/lib/hubba/github.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Hubba
|
4
2
|
|
5
3
|
class Configuration
|
4
|
+
attr_accessor :token
|
5
|
+
|
6
6
|
attr_accessor :user
|
7
7
|
attr_accessor :password
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
# try default setup via ENV variables
|
11
|
+
@token = ENV[ 'HUBBA_TOKEN' ]
|
12
|
+
|
11
13
|
@user = ENV[ 'HUBBA_USER' ] ## use HUBBA_LOGIN - why? why not?
|
12
14
|
@password = ENV[ 'HUBBA_PASSWORD' ]
|
13
15
|
end
|
@@ -15,6 +17,8 @@ end
|
|
15
17
|
|
16
18
|
## lets you use
|
17
19
|
## Hubba.configure do |config|
|
20
|
+
## config.token = 'secret'
|
21
|
+
## #-or-
|
18
22
|
## config.user = 'testdada'
|
19
23
|
## config.password = 'secret'
|
20
24
|
## end
|
@@ -61,8 +65,16 @@ class Github
|
|
61
65
|
|
62
66
|
def initialize( cache_dir: './cache' )
|
63
67
|
@cache = Cache.new( cache_dir )
|
64
|
-
|
65
|
-
|
68
|
+
|
69
|
+
@client = if Hubba.configuration.token
|
70
|
+
Client.new( token: Hubba.configuration.token )
|
71
|
+
elsif Hubba.configuration.user &&
|
72
|
+
Hubba.configuration.password
|
73
|
+
Client.new( user: Hubba.configuration.user,
|
74
|
+
password: Hubba.configuration.password )
|
75
|
+
else
|
76
|
+
Client.new
|
77
|
+
end
|
66
78
|
|
67
79
|
@offline = false
|
68
80
|
end
|
data/lib/hubba/stats.rb
CHANGED
data/lib/hubba/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_cache.rb
CHANGED
data/test/test_config.rb
CHANGED
data/test/test_stats.rb
CHANGED
data/test/test_stats_tmp.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
###
|
4
2
|
# to run use
|
5
3
|
# ruby -I ./lib -I ./test test/test_stats_tmp.rb
|
@@ -16,14 +14,14 @@ class TestStatsTmp < MiniTest::Test
|
|
16
14
|
|
17
15
|
def test_stats
|
18
16
|
repos = [
|
19
|
-
'henrythemes/jekyll-starter-theme',
|
20
17
|
'poole/hyde',
|
21
18
|
'jekyll/minima'
|
22
19
|
]
|
23
20
|
|
24
21
|
repos.each do |repo|
|
25
22
|
stats = Hubba::Stats.new( repo )
|
26
|
-
stats.read( data_dir: './tmp' )
|
23
|
+
# stats.read( data_dir: './tmp' )
|
24
|
+
stats.read( data_dir: "#{Hubba.root}/test/stats" )
|
27
25
|
|
28
26
|
puts "stars before fetch: #{stats.stars}"
|
29
27
|
puts "size before fetch: #{stats.size} kb"
|
metadata
CHANGED
@@ -1,67 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: webclient
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '4.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '7'
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '4.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: hoe
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
53
|
+
version: '3.22'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
60
|
+
version: '3.22'
|
55
61
|
description: hubba - (yet) another (lite) GitHub HTTP API client / library
|
56
62
|
email: ruby-talk@ruby-lang.org
|
57
63
|
executables: []
|
58
64
|
extensions: []
|
59
65
|
extra_rdoc_files:
|
60
|
-
-
|
66
|
+
- CHANGELOG.md
|
61
67
|
- Manifest.txt
|
62
68
|
- README.md
|
63
69
|
files:
|
64
|
-
-
|
70
|
+
- CHANGELOG.md
|
65
71
|
- Manifest.txt
|
66
72
|
- README.md
|
67
73
|
- Rakefile
|
@@ -82,7 +88,7 @@ files:
|
|
82
88
|
- test/test_config.rb
|
83
89
|
- test/test_stats.rb
|
84
90
|
- test/test_stats_tmp.rb
|
85
|
-
homepage: https://github.com/
|
91
|
+
homepage: https://github.com/rubycoco/git
|
86
92
|
licenses:
|
87
93
|
- Public Domain
|
88
94
|
metadata: {}
|
@@ -96,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
102
|
requirements:
|
97
103
|
- - ">="
|
98
104
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
105
|
+
version: 2.2.2
|
100
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
107
|
requirements:
|
102
108
|
- - ">="
|