Skip to content

Commit 5f9c6d3

Browse files
authored
Merge pull request #305 from rajasegar/read-gist
[BUGFIX] read_gist to behave like api
2 parents d854c15 + be271a8 commit 5f9c6d3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

bin/gist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ begin
173173

174174
if options.key? :read
175175
file_name = ARGV.first
176-
Gist.read_gist(options[:read], file_name)
176+
output = Gist.read_gist(options[:read], file_name)
177+
puts output if output
177178
exit
178179
end
179180

lib/gist.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,13 @@ def list_all_gists(user = "")
212212
get_gist_pages(url, auth_token())
213213
end
214214

215-
def read_gist(id, file_name=nil)
215+
def read_gist(id, file_name=nil, options={})
216216
url = "#{base_path}/gists/#{id}"
217217

218-
access_token = auth_token()
218+
access_token = (options[:access_token] || auth_token())
219+
if access_token.to_s != ''
220+
url << "?access_token=" << CGI.escape(access_token)
221+
end
219222

220223
request = Net::HTTP::Get.new(url)
221224
request['Authorization'] = "token #{access_token}" if access_token.to_s != ''
@@ -232,7 +235,7 @@ def read_gist(id, file_name=nil)
232235
file = files.values.first
233236
end
234237

235-
puts file["content"]
238+
file["content"]
236239
else
237240
raise Error, "Gist with id of #{id} does not exist."
238241
end

0 commit comments

Comments
 (0)