scroauth 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -5
- data/lib/scro/auth.rb +31 -6
- data/lib/scro/auth/key.rb +38 -0
- data/lib/scro/auth/repository.rb +16 -2
- data/lib/scro/auth/user.rb +17 -25
- metadata +9 -8
data/README.md
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
scroauth
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
4
|
+
Simplify shipping configuration via [github oauth]
|
5
5
|
|
6
6
|
Developing
|
7
7
|
==========
|
8
8
|
% gem install bundler
|
9
9
|
% bundle install
|
10
|
+
% cp spec/config.rb.example spec/config.rb
|
11
|
+
... modify variables so you can really test it yourself
|
10
12
|
% bundle exec rake
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
Using the Library
|
15
|
+
=================
|
14
16
|
require 'scro/auth'
|
17
|
+
|
15
18
|
include Scro::Auth
|
16
19
|
|
17
|
-
user
|
20
|
+
user = User.new('atmos', '76c2f7a2181236921fcc2185109661f9d69ad894')
|
21
|
+
repos = user.watched_repos
|
18
22
|
|
19
|
-
|
23
|
+
[github oauth]: http://gist.github.com/419219
|
data/lib/scro/auth.rb
CHANGED
@@ -5,16 +5,41 @@ module Scro
|
|
5
5
|
module Auth
|
6
6
|
class RequestError < StandardError; end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
class << self
|
9
|
+
attr_accessor :endpoint_host, :endpoint_path
|
10
10
|
end
|
11
|
+
self.endpoint_host = 'https://github.com'
|
12
|
+
self.endpoint_path = '/api/v2/json/'
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
class Request
|
15
|
+
def initialize(token)
|
16
|
+
raise RequestError, "Token not configured" if token.nil? || token.empty?
|
17
|
+
@token = token
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(path)
|
21
|
+
response = RestClient.get(uri_for(path), {:accept => :json})
|
22
|
+
raise RequestError, response.inspect unless response.code == 200
|
23
|
+
JSON.parse(response.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def post(path, params)
|
27
|
+
response = RestClient.post(uri_for(path), params.to_json, {:content_type => :json, :accept => :json})
|
28
|
+
raise RequestError, response.inspect unless response.code == 200
|
29
|
+
JSON.parse(response.to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
def uri_for(path)
|
33
|
+
"#{endpoint}#{path}?access_token=#{@token}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def endpoint
|
37
|
+
"#{Scro::Auth.endpoint_host}#{Scro::Auth.endpoint_path}"
|
38
|
+
end
|
16
39
|
end
|
17
40
|
end
|
18
41
|
end
|
19
42
|
|
43
|
+
require "scro/auth/key"
|
20
44
|
require "scro/auth/user"
|
45
|
+
require "scro/auth/repository"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Scro
|
2
|
+
module Auth
|
3
|
+
class Key
|
4
|
+
def initialize(keygen = 'ssh-keygen')
|
5
|
+
@keygen = keygen
|
6
|
+
@filename = Digest::SHA1.hexdigest(Time.now.to_f.to_s)
|
7
|
+
|
8
|
+
generate
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate
|
12
|
+
ensure_ssh_keygen_present
|
13
|
+
`#{@keygen} -f #{private_key} -P '' > #{stdout} 2>#{stderr}`
|
14
|
+
end
|
15
|
+
|
16
|
+
def ensure_ssh_keygen_present
|
17
|
+
`which #{@keygen}`
|
18
|
+
raise ArgumentError, "Unable to find the ssh-keygen executable" unless $?.success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def private_key
|
22
|
+
"#{Dir.tmpdir}/#{@filename}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def public_key
|
26
|
+
"#{private_key}.pub"
|
27
|
+
end
|
28
|
+
|
29
|
+
def stderr
|
30
|
+
stdout('error')
|
31
|
+
end
|
32
|
+
|
33
|
+
def stdout(suffix = 'out')
|
34
|
+
"#{private_key}.#{suffix}.log"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/scro/auth/repository.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
module Scro
|
2
2
|
module Auth
|
3
|
-
class Repository
|
4
|
-
def initialize(
|
3
|
+
class Repository < Request
|
4
|
+
def initialize(token, user, name)
|
5
|
+
super(token)
|
6
|
+
@user, @name = user, name
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_deploy_key(title, key)
|
10
|
+
post("repos/key/#{@name}/add", {:title => title, :key => key})
|
11
|
+
end
|
12
|
+
|
13
|
+
def deploy_keys
|
14
|
+
get("repos/keys/#{@name}")["public_keys"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def info
|
18
|
+
@info ||= get("repos/show/#{@user}/#{@name}")["repository"]
|
5
19
|
end
|
6
20
|
end
|
7
21
|
end
|
data/lib/scro/auth/user.rb
CHANGED
@@ -1,43 +1,35 @@
|
|
1
1
|
module Scro
|
2
2
|
module Auth
|
3
|
-
class
|
4
|
-
|
5
|
-
class User
|
6
|
-
attr_reader :id, :login, :name, :company, :location, :email, :blog,
|
7
|
-
:following_count, :followers_count, :disk_usage,
|
8
|
-
:public_gist_count, :public_repo_count, :collaborators,
|
9
|
-
:private_gist_count, :owned_private_repo_count, :total_private_repo_count
|
10
|
-
:plan
|
11
|
-
|
3
|
+
class User < Request
|
12
4
|
attr_reader :user_json
|
13
5
|
|
14
|
-
def initialize(
|
15
|
-
|
16
|
-
@login
|
6
|
+
def initialize(token, login)
|
7
|
+
super(token)
|
8
|
+
@login = login
|
9
|
+
end
|
17
10
|
|
18
|
-
|
11
|
+
def [](key)
|
12
|
+
info[key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def ssh_keys
|
16
|
+
@ssh_keys ||= get("user/keys")["public_keys"]
|
19
17
|
end
|
20
18
|
|
21
19
|
def repos
|
22
|
-
@repos ||= get("repos/show/#{@login}")[
|
20
|
+
@repos ||= get("repos/show/#{@login}")["repositories"]
|
23
21
|
end
|
24
22
|
|
25
23
|
def watched_repos
|
26
|
-
@watched_repos ||= get("repos/watched/#{@login}")[
|
24
|
+
@watched_repos ||= get("repos/watched/#{@login}")["repositories"]
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
def discover
|
32
|
-
@user_json = get("user/show/#{@login}")['user']
|
33
|
-
|
34
|
-
user_json.each do |key, value|
|
35
|
-
instance_variable_set("@key", value)
|
36
|
-
end
|
27
|
+
def pushable_repos
|
28
|
+
@pushable_repos ||= get("repos/pushable")["repositories"]
|
37
29
|
end
|
38
30
|
|
39
|
-
def
|
40
|
-
|
31
|
+
def info
|
32
|
+
@info ||= get("user/show/#{@login}")["user"]
|
41
33
|
end
|
42
34
|
end
|
43
35
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scroauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Corey Donohoe
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
type: :runtime
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
- 3
|
33
33
|
version: 1.4.3
|
34
34
|
requirement: *id001
|
35
|
-
type: :runtime
|
36
35
|
name: json
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
36
|
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :runtime
|
39
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
@@ -48,8 +48,8 @@ dependencies:
|
|
48
48
|
- 0
|
49
49
|
version: 1.5.0
|
50
50
|
requirement: *id002
|
51
|
-
type: :runtime
|
52
51
|
name: rest-client
|
52
|
+
prerelease: false
|
53
53
|
description: Authenticated scros
|
54
54
|
email: atmos@atmos.org
|
55
55
|
executables: []
|
@@ -61,6 +61,7 @@ extra_rdoc_files:
|
|
61
61
|
files:
|
62
62
|
- LICENSE
|
63
63
|
- README.md
|
64
|
+
- lib/scro/auth/key.rb
|
64
65
|
- lib/scro/auth/repository.rb
|
65
66
|
- lib/scro/auth/user.rb
|
66
67
|
- lib/scro/auth.rb
|