@@ -1416,7 +1416,7 @@ module Gist
1416
1416
def multi_gist ( files , options = { } )
1417
1417
if options [ :anonymous ]
1418
1418
raise 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
1419
- '(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
1419
+ '(GitHub now requires credentials to gist https://bit.ly/2GBBxKw)'
1420
1420
else
1421
1421
access_token = ( options [ :access_token ] || auth_token ( ) )
1422
1422
end
@@ -1442,9 +1442,9 @@ module Gist
1442
1442
1443
1443
url = "#{ base_path } /gists"
1444
1444
url << "/" << CGI . escape ( existing_gist ) if existing_gist . to_s != ''
1445
- url << "?access_token=" << CGI . escape ( access_token ) if access_token . to_s != ''
1446
1445
1447
1446
request = Net ::HTTP ::Post . new ( url )
1447
+ request [ 'Authorization' ] = "token #{ access_token } " if access_token . to_s != ''
1448
1448
request . body = JSON . dump ( json )
1449
1449
request . content_type = 'application/json'
1450
1450
@@ -1480,9 +1480,10 @@ module Gist
1480
1480
if user == ""
1481
1481
access_token = auth_token ( )
1482
1482
if access_token . to_s != ''
1483
- url << "/gists?access_token=" << CGI . escape ( access_token )
1483
+ url << "/gists"
1484
1484
1485
1485
request = Net ::HTTP ::Get . new ( url )
1486
+ request [ 'Authorization' ] = "token #{ access_token } "
1486
1487
response = http ( api_url , request )
1487
1488
1488
1489
pretty_gist ( response )
@@ -1507,8 +1508,8 @@ module Gist
1507
1508
if user == ""
1508
1509
access_token = auth_token ( )
1509
1510
if access_token . to_s != ''
1510
- url << "/gists?per_page=100&access_token=" << CGI . escape ( access_token )
1511
- get_gist_pages ( url )
1511
+ url << "/gists?per_page=100"
1512
+ get_gist_pages ( url , access_token )
1512
1513
else
1513
1514
raise Error , "Not authenticated. Use 'gist --login' to login or 'gist -l username' to view public gists."
1514
1515
end
@@ -1524,11 +1525,9 @@ module Gist
1524
1525
url = "#{ base_path } /gists/#{ id } "
1525
1526
1526
1527
access_token = auth_token ( )
1527
- if access_token . to_s != ''
1528
- url << "?access_token=" << CGI . escape ( access_token )
1529
- end
1530
1528
1531
1529
request = Net ::HTTP ::Get . new ( url )
1530
+ request [ 'Authorization' ] = "token #{ access_token } " if access_token . to_s != ''
1532
1531
response = http ( api_url , request )
1533
1532
1534
1533
if response . code == '200'
@@ -1554,9 +1553,8 @@ module Gist
1554
1553
1555
1554
access_token = auth_token ( )
1556
1555
if access_token . to_s != ''
1557
- url << "?access_token=" << CGI . escape ( access_token )
1558
-
1559
1556
request = Net ::HTTP ::Delete . new ( url )
1557
+ request [ "Authorization" ] = "token #{ access_token } "
1560
1558
response = http ( api_url , request )
1561
1559
else
1562
1560
raise Error , "Not authenticated. Use 'gist --login' to login."
@@ -1569,17 +1567,18 @@ module Gist
1569
1567
end
1570
1568
end
1571
1569
1572
- def get_gist_pages ( url )
1570
+ def get_gist_pages ( url , access_token = "" )
1573
1571
1574
1572
request = Net ::HTTP ::Get . new ( url )
1573
+ request [ 'Authorization' ] = "token #{ access_token } " if access_token . to_s != ''
1575
1574
response = http ( api_url , request )
1576
1575
pretty_gist ( response )
1577
1576
1578
1577
link_header = response . header [ 'link' ]
1579
1578
1580
1579
if link_header
1581
1580
links = Hash [ link_header . gsub ( /(<|>|")/ , "" ) . split ( ',' ) . map { |link | link . split ( '; rel=' ) } ] . invert
1582
- get_gist_pages ( links [ 'next' ] ) if links [ 'next' ]
1581
+ get_gist_pages ( links [ 'next' ] , access_token ) if links [ 'next' ]
1583
1582
end
1584
1583
1585
1584
end
@@ -1652,7 +1651,7 @@ module Gist
1652
1651
# @option credentials [String] :password
1653
1652
# @see http://developer.github.com/v3/oauth/
1654
1653
def login! ( credentials = { } )
1655
- puts "Obtaining OAuth2 access_token from github ."
1654
+ puts "Obtaining OAuth2 access_token from GitHub ."
1656
1655
loop do
1657
1656
print "GitHub username: "
1658
1657
username = credentials [ :username ] || $stdin. gets . strip
@@ -1906,7 +1905,7 @@ filenames can be overridden by repeating the "-f" flag. The most useful reason
1906
1905
to do this is to change the syntax highlighting.
1907
1906
1908
1907
All gists must to be associated with a GitHub account, so you will need to login with
1909
- `gist --login` to obtain an Oauth2 access token. This is stored and used by gist in the future.
1908
+ `gist --login` to obtain an OAuth2 access token. This is stored and used by gist in the future.
1910
1909
1911
1910
Private gists do not have guessable URLs and can be created with "-p", you can
1912
1911
also set the description at the top of the gist by passing "-d".
@@ -2023,7 +2022,7 @@ end.parse!
2023
2022
begin
2024
2023
if Gist . auth_token . nil?
2025
2024
puts 'Please log in with `gist --login`. ' \
2026
- '(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
2025
+ '(GitHub now requires credentials to gist https://bit.ly/2GBBxKw)'
2027
2026
exit ( 1 )
2028
2027
end
2029
2028
0 commit comments