warden-github 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/warden-github/user.rb +55 -1
- data/lib/warden-github/version.rb +1 -1
- data/spec/user_spec.rb +14 -0
- data/warden-github.gemspec +1 -0
- metadata +43 -25
data/lib/warden-github/user.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yajl'
|
2
|
+
require 'octokit'
|
2
3
|
require 'rest-client'
|
3
4
|
|
4
5
|
module Warden
|
@@ -61,6 +62,58 @@ module Warden
|
|
61
62
|
false
|
62
63
|
end
|
63
64
|
|
65
|
+
# Send a V3 API PUT request to path and parses the response body
|
66
|
+
#
|
67
|
+
# path - the path on api.github.com to hit
|
68
|
+
# params - extra params for calling the api
|
69
|
+
#
|
70
|
+
def get(path, params)
|
71
|
+
github_request(path, params)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Send a V3 API PUT request to path and parses the response body
|
75
|
+
#
|
76
|
+
# path - the path on api.github.com to hit
|
77
|
+
# params - extra params for calling the api
|
78
|
+
#
|
79
|
+
def post(path, params)
|
80
|
+
headers = {:Authorization => "token #{user.token}", :content_type => :json, :accept => :json}
|
81
|
+
res = RestClient.post("#{github_api_uri}/#{path}", params.to_json, headers)
|
82
|
+
Yajl.load(res)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Send a V3 API PUT request to path and parses the response body
|
86
|
+
#
|
87
|
+
# path - the path on api.github.com to hit
|
88
|
+
# params - extra params for calling the api
|
89
|
+
#
|
90
|
+
def put(path, params)
|
91
|
+
headers = {:Authorization => "token #{user.token}", :content_type => :json, :accept => :json}
|
92
|
+
res = RestClient.put("#{github_api_uri}/#{path}", params.to_json, headers)
|
93
|
+
Yajl.load(res)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Send a V3 API DELETE request to path and parses the response body
|
97
|
+
#
|
98
|
+
# path - the path on api.github.com to hit
|
99
|
+
# params - extra params for calling the api
|
100
|
+
#
|
101
|
+
def delete(path, params)
|
102
|
+
headers = {:Authorization => "token #{user.token}", :content_type => :json, :accept => :json}
|
103
|
+
res = RestClient.delete("#{github_api_uri}/#{path}", params.to_json, headers)
|
104
|
+
Yajl.load(res)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Access the GitHub API from Octokit
|
108
|
+
#
|
109
|
+
# Octokit is a robust client library for the GitHub API
|
110
|
+
# https://github.com/pengwynn/octokit
|
111
|
+
#
|
112
|
+
# Returns a cached client object for easy use
|
113
|
+
def api
|
114
|
+
@api ||= Octokit::Client.new(:login => login, :oauth_token => token)
|
115
|
+
end
|
116
|
+
|
64
117
|
# Send a V3 API GET request to path and parse the response body
|
65
118
|
#
|
66
119
|
# path - the path on api.github.com to hit
|
@@ -91,7 +144,8 @@ module Warden
|
|
91
144
|
# github_raw_request("/user/repos", {:page => 3})
|
92
145
|
# # => RestClient::Response
|
93
146
|
def github_raw_request(path, params = {})
|
94
|
-
|
147
|
+
headers = {:Authorization => "token #{token}", :accept => :json}
|
148
|
+
RestClient.get("#{github_api_uri}/#{path}", headers.merge(:params => params))
|
95
149
|
end
|
96
150
|
|
97
151
|
private
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Warden::Github" do
|
4
|
+
let(:user) do
|
5
|
+
Warden::Github::Oauth::User.new({'login' => 'atmos'}, 'abcde')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "knows the token" do
|
9
|
+
user.token.should eql('abcde')
|
10
|
+
end
|
11
|
+
it "can access the octokit object to make api calls" do
|
12
|
+
user.api.should_not be_nil
|
13
|
+
end
|
14
|
+
end
|
data/warden-github.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency "json", "~>1.5"
|
19
19
|
s.add_dependency "warden", "~>1.0"
|
20
20
|
s.add_dependency "oauth2", "~>0.5.2"
|
21
|
+
s.add_dependency "octokit", "~>1.4.0"
|
21
22
|
s.add_dependency "rest-client", "~>1.6.1"
|
22
23
|
s.add_dependency "yajl-ruby", "~>1.1"
|
23
24
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Corey Donohoe
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-04 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -65,9 +65,25 @@ dependencies:
|
|
65
65
|
type: :runtime
|
66
66
|
version_requirements: *id003
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
68
|
+
name: octokit
|
69
69
|
prerelease: false
|
70
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 7
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 4
|
79
|
+
- 0
|
80
|
+
version: 1.4.0
|
81
|
+
type: :runtime
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
71
87
|
none: false
|
72
88
|
requirements:
|
73
89
|
- - ~>
|
@@ -79,11 +95,11 @@ dependencies:
|
|
79
95
|
- 1
|
80
96
|
version: 1.6.1
|
81
97
|
type: :runtime
|
82
|
-
version_requirements: *
|
98
|
+
version_requirements: *id005
|
83
99
|
- !ruby/object:Gem::Dependency
|
84
100
|
name: yajl-ruby
|
85
101
|
prerelease: false
|
86
|
-
requirement: &
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
87
103
|
none: false
|
88
104
|
requirements:
|
89
105
|
- - ~>
|
@@ -94,11 +110,11 @@ dependencies:
|
|
94
110
|
- 1
|
95
111
|
version: "1.1"
|
96
112
|
type: :runtime
|
97
|
-
version_requirements: *
|
113
|
+
version_requirements: *id006
|
98
114
|
- !ruby/object:Gem::Dependency
|
99
115
|
name: rack
|
100
116
|
prerelease: false
|
101
|
-
requirement: &
|
117
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
102
118
|
none: false
|
103
119
|
requirements:
|
104
120
|
- - ~>
|
@@ -110,11 +126,11 @@ dependencies:
|
|
110
126
|
- 0
|
111
127
|
version: 1.4.0
|
112
128
|
type: :development
|
113
|
-
version_requirements: *
|
129
|
+
version_requirements: *id007
|
114
130
|
- !ruby/object:Gem::Dependency
|
115
131
|
name: rake
|
116
132
|
prerelease: false
|
117
|
-
requirement: &
|
133
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
118
134
|
none: false
|
119
135
|
requirements:
|
120
136
|
- - ">="
|
@@ -124,11 +140,11 @@ dependencies:
|
|
124
140
|
- 0
|
125
141
|
version: "0"
|
126
142
|
type: :development
|
127
|
-
version_requirements: *
|
143
|
+
version_requirements: *id008
|
128
144
|
- !ruby/object:Gem::Dependency
|
129
145
|
name: rspec
|
130
146
|
prerelease: false
|
131
|
-
requirement: &
|
147
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
132
148
|
none: false
|
133
149
|
requirements:
|
134
150
|
- - ~>
|
@@ -140,11 +156,11 @@ dependencies:
|
|
140
156
|
- 0
|
141
157
|
version: 2.8.0
|
142
158
|
type: :development
|
143
|
-
version_requirements: *
|
159
|
+
version_requirements: *id009
|
144
160
|
- !ruby/object:Gem::Dependency
|
145
161
|
name: webrat
|
146
162
|
prerelease: false
|
147
|
-
requirement: &
|
163
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
148
164
|
none: false
|
149
165
|
requirements:
|
150
166
|
- - ">="
|
@@ -154,11 +170,11 @@ dependencies:
|
|
154
170
|
- 0
|
155
171
|
version: "0"
|
156
172
|
type: :development
|
157
|
-
version_requirements: *
|
173
|
+
version_requirements: *id010
|
158
174
|
- !ruby/object:Gem::Dependency
|
159
175
|
name: sinatra
|
160
176
|
prerelease: false
|
161
|
-
requirement: &
|
177
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
162
178
|
none: false
|
163
179
|
requirements:
|
164
180
|
- - ">="
|
@@ -168,11 +184,11 @@ dependencies:
|
|
168
184
|
- 0
|
169
185
|
version: "0"
|
170
186
|
type: :development
|
171
|
-
version_requirements: *
|
187
|
+
version_requirements: *id011
|
172
188
|
- !ruby/object:Gem::Dependency
|
173
189
|
name: shotgun
|
174
190
|
prerelease: false
|
175
|
-
requirement: &
|
191
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
176
192
|
none: false
|
177
193
|
requirements:
|
178
194
|
- - ">="
|
@@ -182,11 +198,11 @@ dependencies:
|
|
182
198
|
- 0
|
183
199
|
version: "0"
|
184
200
|
type: :development
|
185
|
-
version_requirements: *
|
201
|
+
version_requirements: *id012
|
186
202
|
- !ruby/object:Gem::Dependency
|
187
203
|
name: addressable
|
188
204
|
prerelease: false
|
189
|
-
requirement: &
|
205
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
190
206
|
none: false
|
191
207
|
requirements:
|
192
208
|
- - ~>
|
@@ -198,11 +214,11 @@ dependencies:
|
|
198
214
|
- 0
|
199
215
|
version: 2.2.0
|
200
216
|
type: :development
|
201
|
-
version_requirements: *
|
217
|
+
version_requirements: *id013
|
202
218
|
- !ruby/object:Gem::Dependency
|
203
219
|
name: rack-test
|
204
220
|
prerelease: false
|
205
|
-
requirement: &
|
221
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
206
222
|
none: false
|
207
223
|
requirements:
|
208
224
|
- - ~>
|
@@ -214,7 +230,7 @@ dependencies:
|
|
214
230
|
- 3
|
215
231
|
version: 0.5.3
|
216
232
|
type: :development
|
217
|
-
version_requirements: *
|
233
|
+
version_requirements: *id014
|
218
234
|
description: A warden strategy for easy oauth integration with github
|
219
235
|
email:
|
220
236
|
- atmos@atmos.org
|
@@ -242,6 +258,7 @@ files:
|
|
242
258
|
- spec/oauth_spec.rb
|
243
259
|
- spec/proxy_spec.rb
|
244
260
|
- spec/spec_helper.rb
|
261
|
+
- spec/user_spec.rb
|
245
262
|
- warden-github.gemspec
|
246
263
|
has_rdoc: true
|
247
264
|
homepage: http://github.com/atmos/warden-github
|
@@ -282,3 +299,4 @@ test_files:
|
|
282
299
|
- spec/oauth_spec.rb
|
283
300
|
- spec/proxy_spec.rb
|
284
301
|
- spec/spec_helper.rb
|
302
|
+
- spec/user_spec.rb
|