Skip to content

Commit 13c5fb2

Browse files
committed
HTTPS support for the newer, safer Github
1 parent dfc5325 commit 13c5fb2

File tree

5 files changed

+141
-226
lines changed

5 files changed

+141
-226
lines changed

gist

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ module Gist
7979
end
8080
end
8181
module Gist
82-
VERSION = Version = '1.2.1'
82+
VERSION = Version = '1.3.0'
8383
end
8484
require 'open-uri'
85-
require 'net/http'
85+
require 'net/https'
8686
require 'optparse'
8787

8888
require 'gist/manpage' unless defined?(Gist::Manpage)
@@ -91,8 +91,8 @@ require 'gist/version' unless defined?(Gist::Version)
9191
module Gist
9292
extend self
9393

94-
GIST_URL = 'http://gist.github.com/%s.txt'
95-
CREATE_URL = 'http://gist.github.com/gists'
94+
GIST_URL = 'https://gist.github.com/%s.txt'
95+
CREATE_URL = 'https://gist.github.com/gists'
9696

9797
PROXY = ENV['HTTP_PROXY'] ? URI(ENV['HTTP_PROXY']) : nil
9898
PROXY_HOST = PROXY ? PROXY.host : nil
@@ -168,11 +168,19 @@ module Gist
168168
def write(content, private_gist = false, gist_extension = nil, gist_filename = nil)
169169
url = URI.parse(CREATE_URL)
170170

171-
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
172-
req = proxy.post_form(url,
173-
data(gist_filename, gist_extension, content, private_gist))
171+
if PROXY_HOST
172+
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
173+
http = proxy.new(url.host, url.port)
174+
else
175+
http = Net::HTTP.new(url.host, url.port)
176+
end
177+
178+
http.use_ssl = true
179+
180+
req = Net::HTTP::Post.new(url.path)
181+
req.form_data = data(gist_filename, gist_extension, content, private_gist)
174182

175-
req['Location']
183+
http.start{|h| h.request(req) }['Location']
176184
end
177185

178186
def read(gist_id)
@@ -259,10 +267,10 @@ private
259267
end
260268
Gist.execute(*ARGV)
261269
__END__
262-
.\" generated with Ronn/v0.5
263-
.\" http://github.com/rtomayko/ronn/
270+
.\" generated with Ronn/v0.7.3
271+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
264272
.
265-
.TH "GIST" "1" "June 2010" "GITHUB" "Gist Manual"
273+
.TH "GIST" "1" "November 2010" "GITHUB" "Gist Manual"
266274
.
267275
.SH "NAME"
268276
\fBgist\fR \- gist on the command line
@@ -271,51 +279,42 @@ __END__
271279
\fBgist\fR [\fB\-p\fR] [\fB\-t extension\fR] \fIFILE\fR
272280
.
273281
.SH "DESCRIPTION"
274-
\fBgist\fR can be used to create gists on gist.github.com from the command
275-
line. There are two primary methods of creating gists.
282+
\fBgist\fR can be used to create gists on gist\.github\.com from the command line\. There are two primary methods of creating gists\.
276283
.
277284
.P
278-
If standard input is supplied, it will be used as the content of the
279-
new gist. If \fIFILE\fR is provided, the content of that file will be used
280-
to create the gist.
285+
If standard input is supplied, it will be used as the content of the new gist\. If \fIFILE\fR is provided, the content of that file will be used to create the gist\.
281286
.
282287
.P
283-
Once your gist is successfully created, the URL will be copied to your
284-
clipboard. If you are on OS X, \fBgist\fR will open the gist in your
285-
browser, too.
288+
Once your gist is successfully created, the URL will be copied to your clipboard\. If you are on OS X, \fBgist\fR will open the gist in your browser, too\.
286289
.
287290
.SH "OPTIONS"
288-
\fBgist\fR's default mode of operation is to read content from standard
289-
input and create a public, text gist from it, tied to your GitHub
290-
account if you user and token are provided (see \fBCONFIGURATION\fR).
291+
\fBgist\fR\'s default mode of operation is to read content from standard input and create a public, text gist from it, tied to your GitHub account if you user and token are provided (see \fBCONFIGURATION\fR)\.
291292
.
292293
.P
293294
These options can be used to change this behavior:
294295
.
295296
.TP
296297
\fB\-p\fR, \fB\-\-private\fR
297-
Create a private gist instead of a public gist.
298+
Create a private gist instead of a public gist\.
298299
.
299300
.TP
300301
\fB\-t\fR, \fB\-\-type\fR
301-
Set the file extension explicitly. Passing a type of \fBrb\fR ensure
302-
the gist is created as a Ruby file.
302+
Set the file extension explicitly\. Passing a type of \fBrb\fR ensure the gist is created as a Ruby file\.
303303
.
304304
.TP
305305
\fB\-o\fR, \fB\-\-[no\-]open\fR
306-
Open the gist in your browser after creation. Or don't. Defaults
307-
to \-\-open
306+
Open the gist in your browser after creation\. Or don\'t\. Defaults to \-\-open
308307
.
309308
.P
310309
You may additionally ask for help:
311310
.
312311
.TP
313312
\fB\-h\fR, \fB\-\-help\fR
314-
Print help.
313+
Print help\.
315314
.
316315
.TP
317316
\fB\-m\fR, \fB\-\-man\fR
318-
Display this man page.
317+
Display this man page\.
319318
.
320319
.SH "AUTHENTICATION"
321320
There are two ways to set GitHub user and token info:
@@ -324,9 +323,7 @@ There are two ways to set GitHub user and token info:
324323
Using env vars GITHUB_USER and GITHUB_TOKEN
325324
.
326325
.IP
327-
$ export GITHUB_USER=johndoe
328-
$ export GITHUB_TOKEN=mysecretgithubtoken
329-
$ gist ~/example
326+
$ export GITHUB_USER=johndoe $ export GITHUB_TOKEN=mysecretgithubtoken $ gist ~/example
330327
.
331328
.IP "\(bu" 4
332329
Using git\-config(1)
@@ -340,7 +337,7 @@ Use git\-config(1) to display the currently configured GitHub username:
340337
.
341338
.nf
342339

343-
$ git config \-\-global github.user
340+
$ git config \-\-global github\.user
344341
.
345342
.fi
346343
.
@@ -353,57 +350,53 @@ Or, set the GitHub username with:
353350
.
354351
.nf
355352

356-
$ git config \-\-global github.user <username>
353+
$ git config \-\-global github\.user <username>
357354
.
358355
.fi
359356
.
360357
.IP "" 0
361358
.
362359
.P
363-
See \fIhttp://github.com/guides/local\-github\-config\fR for more
364-
information.
360+
See \fIhttp://github\.com/guides/local\-github\-config\fR for more information\.
365361
.
366362
.SH "CONFIGURATION"
367-
You can set a few options in your git config (using git\-config(1)) to
368-
control the default behavior of gist(1).
363+
You can set a few options in your git config (using git\-config(1)) to control the default behavior of gist(1)\.
369364
.
370365
.IP "\(bu" 4
371-
gist.private \- boolean (yes or no) \- Determines whether to make a gist
372-
private by default
366+
gist\.private \- boolean (yes or no) \- Determines whether to make a gist private by default
373367
.
374368
.IP "\(bu" 4
375-
gist.extension \- string \- Default extension for gists you create.
369+
gist\.extension \- string \- Default extension for gists you create\.
376370
.
377371
.IP "\(bu" 4
378-
gist.browse \- boolean (yes or no) \- Whether to open the gist in your
379-
browser after creation. Default: yes
372+
gist\.browse \- boolean (yes or no) \- Whether to open the gist in your browser after creation\. Default: yes
380373
.
381374
.IP "" 0
382375
.
383376
.SH "ENVIRONMENT"
384377
The following environment variables affect the execution of \fBgist\fR:
385378
.
386379
.IP "\(bu" 4
387-
HTTP_PROXY \- Proxy to use when Gisting. Should be "http://host:port/"
380+
HTTP_PROXY \- Proxy to use when Gisting\. Should be "http://host:port/"
388381
.
389382
.IP "" 0
390383
.
391384
.SH "EXAMPLES"
392385
.
393386
.nf
394387

395-
$ gist < file.txt
388+
$ gist < file\.txt
396389
$ echo secret | gist \-\-private
397390
$ echo "puts :hi" | gist \-t rb
398-
$ gist script.py
391+
$ gist script\.py
399392
.
400393
.fi
401394
.
402395
.SH "BUGS"
403-
\fIhttp://github.com/defunkt/gist/issues\fR
396+
\fIhttp://github\.com/defunkt/gist/issues\fR
404397
.
405398
.SH "AUTHOR"
406-
Chris Wanstrath :: chris@ozmm.org
399+
Chris Wanstrath :: chris@ozmm\.org
407400
.
408401
.SH "SEE ALSO"
409-
hub(1), git(1), git\-clone(1), \fIhttp://github.com\fR, \fIhttp://github.com/defunkt/gist\fR
402+
hub(1), git(1), git\-clone(1), \fIhttp://github\.com\fR, \fIhttp://github\.com/defunkt/gist\fR

lib/gist.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'open-uri'
2-
require 'net/http'
2+
require 'net/https'
33
require 'optparse'
44

55
require 'gist/manpage' unless defined?(Gist::Manpage)
@@ -23,8 +23,8 @@
2323
module Gist
2424
extend self
2525

26-
GIST_URL = 'http://gist.github.com/%s.txt'
27-
CREATE_URL = 'http://gist.github.com/gists'
26+
GIST_URL = 'https://gist.github.com/%s.txt'
27+
CREATE_URL = 'https://gist.github.com/gists'
2828

2929
PROXY = ENV['HTTP_PROXY'] ? URI(ENV['HTTP_PROXY']) : nil
3030
PROXY_HOST = PROXY ? PROXY.host : nil
@@ -106,12 +106,19 @@ def execute(*args)
106106
def write(content, private_gist = false, gist_extension = nil, gist_filename = nil)
107107
url = URI.parse(CREATE_URL)
108108

109-
# Net::HTTP::Proxy returns Net::HTTP if PROXY_HOST is nil
110-
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
111-
req = proxy.post_form(url,
112-
data(gist_filename, gist_extension, content, private_gist))
109+
if PROXY_HOST
110+
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
111+
http = proxy.new(url.host, url.port)
112+
else
113+
http = Net::HTTP.new(url.host, url.port)
114+
end
115+
116+
http.use_ssl = true
117+
118+
req = Net::HTTP::Post.new(url.path)
119+
req.form_data = data(gist_filename, gist_extension, content, private_gist)
113120

114-
req['Location']
121+
http.start{|h| h.request(req) }['Location']
115122
end
116123

117124
# Given a gist id, returns its content.

lib/gist/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Gist
2-
VERSION = Version = '1.2.1'
2+
VERSION = Version = '1.3.0'
33
end

0 commit comments

Comments
 (0)