github-v3-api 0.0.3 → 0.0.4
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/.rvmrc +1 -1
- data/VERSION +1 -1
- data/bin/github-v3-api-get-token +55 -0
- data/github-v3-api.gemspec +5 -3
- data/lib/github_v3_api.rb +8 -0
- data/lib/github_v3_api/repo.rb +4 -0
- data/lib/github_v3_api/repos_api.rb +2 -0
- data/spec/github_v3_api_spec.rb +6 -0
- data/spec/org_spec.rb +1 -1
- data/spec/repo_spec.rb +9 -1
- data/spec/repos_api_spec.rb +8 -0
- metadata +31 -77
- data/get_access_token_sinatra_app.rb.template +0 -25
data/.rvmrc
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
rvm use
|
1
|
+
rvm use ruby-1.9.2-p180@github-v3-api --create --install
|
2
2
|
bundle check
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
puts <<EOF
|
4
|
+
This script will start a sinatra web app on your machine that can log you in to
|
5
|
+
GitHub and show you your access token. This access token can then be used with
|
6
|
+
the GitHubV3API.
|
7
|
+
|
8
|
+
Once the server has started, just browse to http://localhost:4567. You may be
|
9
|
+
prompted to log in to GitHub and/or authorize the app. After that, your access
|
10
|
+
token will be displayed to you.
|
11
|
+
|
12
|
+
You will need to create a GitHub Application in order to use this. Just go to
|
13
|
+
https://github.com/account/applications/new and fill out the form. Pick any name
|
14
|
+
you want, and use http://localhost:4567 and
|
15
|
+
http://localhost:4567/auth/github/callback for the Main and Callback URLs,
|
16
|
+
respectively. After creating the application, use the generated client id and
|
17
|
+
client secret by running this script with the OAUTH_GITHUB_CLIENT_ID and
|
18
|
+
OATH_GITHUB_CLIENT_SECRET environment variables set.
|
19
|
+
EOF
|
20
|
+
|
21
|
+
print "Ready to go? (y/N): "
|
22
|
+
|
23
|
+
answer = STDIN.gets.chomp
|
24
|
+
|
25
|
+
unless answer =~ /^y(es)?$/i
|
26
|
+
exit(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
unless ENV['OAUTH_GITHUB_CLIENT_ID'] && ENV['OAUTH_GITHUB_CLIENT_SECRET']
|
30
|
+
raise "Please set the OAUTH_GITHUB_CLIENT_ID and OAUTH_GITHUB_CLIENT_SECRET " \
|
31
|
+
+ "environment variables before running this."
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'rubygems'
|
35
|
+
require 'bundler/setup'
|
36
|
+
Bundler.setup(:sinatra)
|
37
|
+
require 'sinatra'
|
38
|
+
require 'openssl'
|
39
|
+
require 'omniauth'
|
40
|
+
|
41
|
+
enable :sessions
|
42
|
+
|
43
|
+
use OmniAuth::Builder do
|
44
|
+
provider :github, ENV['OAUTH_GITHUB_CLIENT_ID'], ENV['OAUTH_GITHUB_CLIENT_SECRET'],
|
45
|
+
:scope => 'user,repo,gist'
|
46
|
+
end
|
47
|
+
|
48
|
+
get '/' do
|
49
|
+
redirect '/auth/github'
|
50
|
+
end
|
51
|
+
|
52
|
+
get '/auth/github/callback' do
|
53
|
+
token = request.env['omniauth.auth']['credentials']['token']
|
54
|
+
"Your GitHub Access Token is #{token}"
|
55
|
+
end
|
data/github-v3-api.gemspec
CHANGED
@@ -5,13 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{github-v3-api}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Wilger"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-03}
|
13
|
+
s.default_executable = %q{github-v3-api-get-token}
|
13
14
|
s.description = %q{Ponies}
|
14
15
|
s.email = %q{johnwilger@gmail.com}
|
16
|
+
s.executables = ["github-v3-api-get-token"]
|
15
17
|
s.extra_rdoc_files = [
|
16
18
|
"LICENSE.txt",
|
17
19
|
"README.rdoc"
|
@@ -26,7 +28,7 @@ Gem::Specification.new do |s|
|
|
26
28
|
"README.rdoc",
|
27
29
|
"Rakefile",
|
28
30
|
"VERSION",
|
29
|
-
"
|
31
|
+
"bin/github-v3-api-get-token",
|
30
32
|
"github-v3-api.gemspec",
|
31
33
|
"lib/github-v3-api.rb",
|
32
34
|
"lib/github_v3_api.rb",
|
data/lib/github_v3_api.rb
CHANGED
@@ -17,6 +17,12 @@ require 'github_v3_api/repo'
|
|
17
17
|
# #=> an instance of GitHubV3API::OrgsAPI
|
18
18
|
#
|
19
19
|
class GitHubV3API
|
20
|
+
# Raised when an API request returns a 404 error
|
21
|
+
NotFound = Class.new(RuntimeError)
|
22
|
+
|
23
|
+
# Raised when an API request uses an invalid access token
|
24
|
+
Unauthorized = Class.new(RuntimeError)
|
25
|
+
|
20
26
|
# Returns a GitHubV3API instance that is able to access github with the
|
21
27
|
# +access_token+ owner's authorization.
|
22
28
|
#
|
@@ -46,5 +52,7 @@ class GitHubV3API
|
|
46
52
|
{:accept => :json,
|
47
53
|
:authorization => "token #{@access_token}"})
|
48
54
|
JSON.parse(result)
|
55
|
+
rescue RestClient::Unauthorized
|
56
|
+
raise Unauthorized, "The access token is invalid according to GitHub"
|
49
57
|
end
|
50
58
|
end
|
data/lib/github_v3_api/repo.rb
CHANGED
@@ -40,6 +40,8 @@ class GitHubV3API
|
|
40
40
|
def get(user, repo_name)
|
41
41
|
org_data = @connection.get("/repos/#{user}/#{repo_name}")
|
42
42
|
GitHubV3API::Repo.new_with_all_data(self, org_data)
|
43
|
+
rescue RestClient::ResourceNotFound
|
44
|
+
raise NotFound, "The repository #{user}/#{repo_name} does not exist or is not visible to the user."
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
data/spec/github_v3_api_spec.rb
CHANGED
@@ -33,5 +33,11 @@ describe GitHubV3API do
|
|
33
33
|
api = GitHubV3API.new('abcde')
|
34
34
|
api.get('/something').should == [{"foo" => "bar"}]
|
35
35
|
end
|
36
|
+
|
37
|
+
it 'raises GitHubV3API::Unauthorized instead of RestClient::Unauthorized' do
|
38
|
+
RestClient.stub!(:get).and_raise(RestClient::Unauthorized)
|
39
|
+
api = GitHubV3API.new('abcde')
|
40
|
+
lambda { api.get('/something') }.should raise_error(GitHubV3API::Unauthorized)
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
data/spec/org_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe GitHubV3API::Org do
|
|
10
10
|
total_private_repos type url)
|
11
11
|
fields.each do |f|
|
12
12
|
org = GitHubV3API::Org.new_with_all_data(stub('api'), {f.to_s => 'foo'})
|
13
|
-
org.methods.should include(f)
|
13
|
+
org.methods.should include(f.to_sym)
|
14
14
|
org.send(f).should == 'foo'
|
15
15
|
end
|
16
16
|
end
|
data/spec/repo_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe GitHubV3API::Repo do
|
|
8
8
|
organization owner parent private pushed_at size source url watchers)
|
9
9
|
fields.each do |f|
|
10
10
|
repo = GitHubV3API::Repo.new_with_all_data(stub('api'), {f.to_s => 'foo'})
|
11
|
-
repo.methods.should include(f)
|
11
|
+
repo.methods.should include(f.to_sym)
|
12
12
|
repo.send(f).should == 'foo'
|
13
13
|
end
|
14
14
|
end
|
@@ -32,4 +32,12 @@ describe GitHubV3API::Repo do
|
|
32
32
|
repo['private'].should == true
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
describe '#owner_login' do
|
37
|
+
it 'returns the login name of the repo owner' do
|
38
|
+
api = stub(GitHubV3API::ReposAPI)
|
39
|
+
repo = GitHubV3API::Repo.new_with_all_data(api, 'owner' => {'login' => 'octocat'})
|
40
|
+
repo.owner_login.should == 'octocat'
|
41
|
+
end
|
42
|
+
end
|
35
43
|
end
|
data/spec/repos_api_spec.rb
CHANGED
@@ -21,5 +21,13 @@ describe GitHubV3API::ReposAPI do
|
|
21
21
|
GitHubV3API::Repo.should_receive(:new_with_all_data).with(api, :repo_hash).and_return(:repo)
|
22
22
|
api.get('octocat', 'hello-world').should == :repo
|
23
23
|
end
|
24
|
+
|
25
|
+
it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
|
26
|
+
connection = mock(GitHubV3API)
|
27
|
+
connection.should_receive(:get) \
|
28
|
+
.and_raise(RestClient::ResourceNotFound)
|
29
|
+
api = GitHubV3API::ReposAPI.new(connection)
|
30
|
+
lambda { api.get('octocat', 'hello-world') }.should raise_error(GitHubV3API::NotFound)
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-v3-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
5
|
+
version: 0.0.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- John Wilger
|
@@ -15,139 +10,101 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-07-03 00:00:00 -07:00
|
14
|
+
default_executable: github-v3-api-get-token
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
17
|
+
name: rest-client
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
20
|
requirements:
|
26
21
|
- - ~>
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 9
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 6
|
32
|
-
- 3
|
33
23
|
version: 1.6.3
|
34
|
-
|
35
|
-
version_requirements: *id001
|
24
|
+
type: :runtime
|
36
25
|
prerelease: false
|
26
|
+
version_requirements: *id001
|
37
27
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
28
|
+
name: json
|
39
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
30
|
none: false
|
41
31
|
requirements:
|
42
32
|
- - ~>
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 5
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 5
|
48
|
-
- 3
|
49
34
|
version: 1.5.3
|
50
|
-
|
51
|
-
version_requirements: *id002
|
35
|
+
type: :runtime
|
52
36
|
prerelease: false
|
37
|
+
version_requirements: *id002
|
53
38
|
- !ruby/object:Gem::Dependency
|
54
|
-
|
39
|
+
name: rspec
|
55
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
41
|
none: false
|
57
42
|
requirements:
|
58
43
|
- - ~>
|
59
44
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 2
|
63
|
-
- 3
|
64
|
-
- 0
|
65
45
|
version: 2.3.0
|
66
|
-
|
67
|
-
version_requirements: *id003
|
46
|
+
type: :development
|
68
47
|
prerelease: false
|
48
|
+
version_requirements: *id003
|
69
49
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
50
|
+
name: bundler
|
71
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
52
|
none: false
|
73
53
|
requirements:
|
74
54
|
- - ~>
|
75
55
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 23
|
77
|
-
segments:
|
78
|
-
- 1
|
79
|
-
- 0
|
80
|
-
- 0
|
81
56
|
version: 1.0.0
|
82
|
-
|
83
|
-
version_requirements: *id004
|
57
|
+
type: :development
|
84
58
|
prerelease: false
|
59
|
+
version_requirements: *id004
|
85
60
|
- !ruby/object:Gem::Dependency
|
86
|
-
|
61
|
+
name: jeweler
|
87
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
88
63
|
none: false
|
89
64
|
requirements:
|
90
65
|
- - ~>
|
91
66
|
- !ruby/object:Gem::Version
|
92
|
-
hash: 15
|
93
|
-
segments:
|
94
|
-
- 1
|
95
|
-
- 6
|
96
|
-
- 0
|
97
67
|
version: 1.6.0
|
98
|
-
|
99
|
-
version_requirements: *id005
|
68
|
+
type: :development
|
100
69
|
prerelease: false
|
70
|
+
version_requirements: *id005
|
101
71
|
- !ruby/object:Gem::Dependency
|
102
|
-
|
72
|
+
name: rcov
|
103
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
104
74
|
none: false
|
105
75
|
requirements:
|
106
76
|
- - ">="
|
107
77
|
- !ruby/object:Gem::Version
|
108
|
-
hash: 3
|
109
|
-
segments:
|
110
|
-
- 0
|
111
78
|
version: "0"
|
112
|
-
|
113
|
-
version_requirements: *id006
|
79
|
+
type: :development
|
114
80
|
prerelease: false
|
81
|
+
version_requirements: *id006
|
115
82
|
- !ruby/object:Gem::Dependency
|
116
|
-
|
83
|
+
name: reek
|
117
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
118
85
|
none: false
|
119
86
|
requirements:
|
120
87
|
- - ~>
|
121
88
|
- !ruby/object:Gem::Version
|
122
|
-
hash: 15
|
123
|
-
segments:
|
124
|
-
- 1
|
125
|
-
- 2
|
126
|
-
- 8
|
127
89
|
version: 1.2.8
|
128
|
-
|
129
|
-
version_requirements: *id007
|
90
|
+
type: :development
|
130
91
|
prerelease: false
|
92
|
+
version_requirements: *id007
|
131
93
|
- !ruby/object:Gem::Dependency
|
132
|
-
|
94
|
+
name: roodi
|
133
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
134
96
|
none: false
|
135
97
|
requirements:
|
136
98
|
- - ~>
|
137
99
|
- !ruby/object:Gem::Version
|
138
|
-
hash: 11
|
139
|
-
segments:
|
140
|
-
- 2
|
141
|
-
- 1
|
142
|
-
- 0
|
143
100
|
version: 2.1.0
|
144
|
-
|
145
|
-
version_requirements: *id008
|
101
|
+
type: :development
|
146
102
|
prerelease: false
|
103
|
+
version_requirements: *id008
|
147
104
|
description: Ponies
|
148
105
|
email: johnwilger@gmail.com
|
149
|
-
executables:
|
150
|
-
|
106
|
+
executables:
|
107
|
+
- github-v3-api-get-token
|
151
108
|
extensions: []
|
152
109
|
|
153
110
|
extra_rdoc_files:
|
@@ -163,7 +120,7 @@ files:
|
|
163
120
|
- README.rdoc
|
164
121
|
- Rakefile
|
165
122
|
- VERSION
|
166
|
-
-
|
123
|
+
- bin/github-v3-api-get-token
|
167
124
|
- github-v3-api.gemspec
|
168
125
|
- lib/github-v3-api.rb
|
169
126
|
- lib/github_v3_api.rb
|
@@ -192,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
149
|
requirements:
|
193
150
|
- - ">="
|
194
151
|
- !ruby/object:Gem::Version
|
195
|
-
hash:
|
152
|
+
hash: 1496179745078912717
|
196
153
|
segments:
|
197
154
|
- 0
|
198
155
|
version: "0"
|
@@ -201,9 +158,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
158
|
requirements:
|
202
159
|
- - ">="
|
203
160
|
- !ruby/object:Gem::Version
|
204
|
-
hash: 3
|
205
|
-
segments:
|
206
|
-
- 0
|
207
161
|
version: "0"
|
208
162
|
requirements: []
|
209
163
|
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
Bundler.setup(:sinatra)
|
4
|
-
require 'sinatra'
|
5
|
-
require 'openssl'
|
6
|
-
require 'omniauth'
|
7
|
-
|
8
|
-
# Because fuck you, Apple
|
9
|
-
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
10
|
-
|
11
|
-
enable :sessions
|
12
|
-
|
13
|
-
use OmniAuth::Builder do
|
14
|
-
provider :github, YOUR_APP_ID, YOUR_APP_SECRET,
|
15
|
-
:scope => 'user,repo,gist'
|
16
|
-
end
|
17
|
-
|
18
|
-
get '/' do
|
19
|
-
redirect '/auth/github'
|
20
|
-
end
|
21
|
-
|
22
|
-
get '/auth/github/callback' do
|
23
|
-
token = request.env['omniauth.auth']['credentials']['token']
|
24
|
-
"Your GitHub Access Token is #{token}"
|
25
|
-
end
|