gist 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gist.rb +12 -4
- data/lib/gist/version.rb +1 -1
- metadata +3 -3
data/lib/gist.rb
CHANGED
@@ -141,8 +141,9 @@ module Gist
|
|
141
141
|
req = Net::HTTP::Post.new(url.path)
|
142
142
|
req.body = JSON.generate(data(files, private_gist, description))
|
143
143
|
|
144
|
-
|
145
|
-
|
144
|
+
user, password = auth()
|
145
|
+
if user && password
|
146
|
+
req.basic_auth(user, password)
|
146
147
|
end
|
147
148
|
|
148
149
|
response = http.start{|h| h.request(req) }
|
@@ -212,15 +213,22 @@ private
|
|
212
213
|
|
213
214
|
# Returns a basic auth string of the user's GitHub credentials if set.
|
214
215
|
# http://github.com/guides/local-github-config
|
216
|
+
#
|
217
|
+
# Returns an Array of Strings if auth is found: [user, password]
|
218
|
+
# Returns nil if no auth is found.
|
215
219
|
def auth
|
216
220
|
user = config("github.user")
|
217
221
|
password = config("github.password")
|
218
222
|
|
223
|
+
token = config("github.token")
|
224
|
+
if password.to_s.empty? && !token.to_s.empty?
|
225
|
+
abort "Please set GITHUB_PASSWORD or github.password instead of using a token."
|
226
|
+
end
|
227
|
+
|
219
228
|
if user.to_s.empty? || password.to_s.empty?
|
220
229
|
nil
|
221
230
|
else
|
222
|
-
|
223
|
-
"Basic #{auth_str}"
|
231
|
+
[ user, password ]
|
224
232
|
end
|
225
233
|
end
|
226
234
|
|
data/lib/gist/version.rb
CHANGED
metadata
CHANGED