hubba 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +1 -0
- data/lib/hubba/cache.rb +5 -4
- data/lib/hubba/client.rb +12 -2
- data/lib/hubba/github.rb +39 -4
- data/lib/hubba/version.rb +1 -2
- data/test/test_config.rb +23 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 994797c48a03ee5124ff6944fcfd739e9e4134e9
|
4
|
+
data.tar.gz: 1b4b3c91652f82ff471129047feb39dc14bdb1cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98716f3b302d8a86c77c1c6dd9b6ea29e6bd9f9106d8f63197e5960f30ff78006fd92ff3114a7c60af9ff1517999af5279934165f0173c4773192db3e167e15b
|
7
|
+
data.tar.gz: 2171a770f43ce878fea802d1bb2dc0345ea4aa3e0f4efaf0dda086668ad285d7117068a89944951d1820ae0309c8b3743a4322a865c1f4edaf4dd450ce8b20f0
|
data/Manifest.txt
CHANGED
data/lib/hubba/cache.rb
CHANGED
@@ -16,16 +16,17 @@ class Cache ## lets you work with GitHub api "offline" using just a local ca
|
|
16
16
|
if File.exist?( path )
|
17
17
|
text = File.read( path ) ## todo/fix: use File.read_utf8
|
18
18
|
json = JSON.parse( text )
|
19
|
+
json
|
19
20
|
else
|
20
21
|
nil ## todo/fix: raise exception - why? why not??
|
21
|
-
end
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def put( request_uri, obj )
|
25
26
|
basename = request_uri_to_basename( request_uri )
|
26
27
|
path = "#{@dir}/#{basename}.json"
|
27
|
-
|
28
|
-
if obj.is_a?( Resource ) ## note: for convenience support Resource obj too
|
28
|
+
|
29
|
+
if obj.is_a?( Resource ) ## note: for convenience support Resource obj too
|
29
30
|
data = obj.data
|
30
31
|
else
|
31
32
|
data = obj # assume Hash or Array -- todo: add support for String - why? why not??
|
@@ -33,7 +34,7 @@ class Cache ## lets you work with GitHub api "offline" using just a local ca
|
|
33
34
|
|
34
35
|
File.open( path, 'w' ) do |f|
|
35
36
|
f.write JSON.pretty_generate( data )
|
36
|
-
end
|
37
|
+
end
|
37
38
|
end
|
38
39
|
|
39
40
|
|
data/lib/hubba/client.rb
CHANGED
@@ -5,11 +5,15 @@ module Hubba
|
|
5
5
|
|
6
6
|
class Client
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize( user: nil, password: nil )
|
9
9
|
uri = URI.parse( "https://api.github.com" )
|
10
10
|
@http = Net::HTTP.new(uri.host, uri.port)
|
11
11
|
@http.use_ssl = true
|
12
12
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
13
|
+
|
14
|
+
## add support for basic auth - defaults to no auth (nil/nil)
|
15
|
+
@user = user ## use login like Oktokit - why? why not?
|
16
|
+
@password = password
|
13
17
|
end # method initialize
|
14
18
|
|
15
19
|
def get( request_uri )
|
@@ -18,9 +22,15 @@ def get( request_uri )
|
|
18
22
|
req = Net::HTTP::Get.new( request_uri )
|
19
23
|
## req = Net::HTTP::Get.new( "/users/geraldb" )
|
20
24
|
## req = Net::HTTP::Get.new( "/users/geraldb/repos" )
|
21
|
-
req["User-Agent"] = "ruby/
|
25
|
+
req["User-Agent"] = "ruby/hubba" ## required by GitHub API
|
22
26
|
req["Accept" ] = "application/vnd.github.v3+json" ## recommend by GitHub API
|
23
27
|
|
28
|
+
## check if credentials (user/password) present - if yes, use basic auth
|
29
|
+
if @user && @password
|
30
|
+
puts " using basic auth - user: #{@user}, password: ***"
|
31
|
+
req.basic_auth( @user && @password )
|
32
|
+
end
|
33
|
+
|
24
34
|
res = @http.request(req)
|
25
35
|
|
26
36
|
# Get specific header
|
data/lib/hubba/github.rb
CHANGED
@@ -2,6 +2,38 @@
|
|
2
2
|
|
3
3
|
module Hubba
|
4
4
|
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :user
|
7
|
+
attr_accessor :password
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
# try default setup via ENV variables
|
11
|
+
@user = ENV[ 'HUBBA_USER' ] ## use HUBBA_LOGIN - why? why not?
|
12
|
+
@password = ENV[ 'HUBBA_PASSWORD' ]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
## lets you use
|
17
|
+
## Hubba.configure do |config|
|
18
|
+
## config.user = 'testdada'
|
19
|
+
## config.password = 'secret'
|
20
|
+
## end
|
21
|
+
##
|
22
|
+
## move configure block to GitHub class - why? why not?
|
23
|
+
## e.g. GitHub.configure do |config|
|
24
|
+
## ...
|
25
|
+
## end
|
26
|
+
|
27
|
+
|
28
|
+
def self.configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure
|
33
|
+
yield( configuration )
|
34
|
+
end
|
35
|
+
|
36
|
+
|
5
37
|
class Resource
|
6
38
|
attr_reader :data
|
7
39
|
def initialize( data )
|
@@ -29,13 +61,16 @@ class Github
|
|
29
61
|
|
30
62
|
def initialize( cache_dir: './cache' )
|
31
63
|
@cache = Cache.new( cache_dir )
|
32
|
-
@client = Client.new
|
33
|
-
|
64
|
+
@client = Client.new( user: Hubba.configuration.user,
|
65
|
+
password: Hubba.configuration.password )
|
66
|
+
|
34
67
|
@offline = false
|
35
68
|
end
|
36
69
|
|
37
|
-
def offline!() @offline = true;
|
38
|
-
def
|
70
|
+
def offline!() @offline = true; end ## switch to offline - todo: find a "better" way - why? why not?
|
71
|
+
def online!() @offline = false; end
|
72
|
+
def offline?() @offline == true; end
|
73
|
+
def online?() @offline == false; end
|
39
74
|
|
40
75
|
|
41
76
|
def user( name )
|
data/lib/hubba/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Hubba
|
4
4
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
5
5
|
MINOR = 1
|
6
|
-
PATCH =
|
6
|
+
PATCH = 1
|
7
7
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
8
8
|
|
9
9
|
def self.version
|
@@ -18,4 +18,3 @@ module Hubba
|
|
18
18
|
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
19
19
|
end
|
20
20
|
end # module Hubba
|
21
|
-
|
data/test/test_config.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_config.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestConfig < MiniTest::Test
|
12
|
+
|
13
|
+
def test_config
|
14
|
+
Hubba.configure do |config|
|
15
|
+
config.user = 'user1'
|
16
|
+
config.password = 'password1'
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal 'user1', Hubba.configuration.user
|
20
|
+
assert_equal 'password1', Hubba.configuration.password
|
21
|
+
end
|
22
|
+
|
23
|
+
end # class TestConfig
|
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.1.
|
4
|
+
version: 0.1.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: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- test/cache/users~geraldb~repos.json
|
75
75
|
- test/helper.rb
|
76
76
|
- test/test_cache.rb
|
77
|
+
- test/test_config.rb
|
77
78
|
homepage: https://github.com/rubylibs/hubba
|
78
79
|
licenses:
|
79
80
|
- Public Domain
|