gist 4.4.1 → 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/build/gist +67 -18
  3. data/build/gist.1 +3 -3
  4. data/lib/gist.rb +2 -2
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c154966f285a79263f14498695afd85e8db74292
4
- data.tar.gz: 85d674e7b3aea4dc2f43a021b14452cbcd0c0d00
3
+ metadata.gz: e12581fd7b9192039f572f5db1410b6bdab6f0db
4
+ data.tar.gz: 8a4610f6c68462becff34e98313008156e45c5c7
5
5
  SHA512:
6
- metadata.gz: 7462a1f302e37d2ae64805e95cfe6783c9f50b5c1c3668e4f24adf30e872bb806f176370da575f84a1f06d46d53528dfdb550e99017ced2593ad87db7ee08cef
7
- data.tar.gz: fb8981e8d31d31f7549b3da10dd3d6c2d5a3321fbcb8faac11457afce188eaa076683c846146c8933d6d7334abd4dcbba8a1debd40513a407c7ff57518ee1bc8
6
+ metadata.gz: 17306b9e02e386fa63a545fa704298a1a6564736f4939752f68ca0c56176a16e17aa4817d57bc1a25098e86b05e979f03dae084c675f867a635d3667c43f4fab
7
+ data.tar.gz: ebd268363f70e892bb7b4bca00df423cb95afe2e54cefd53682628a9a1d4be6c146efcbbacb53664067d40ee3b5ae234883547eca29ebb8b67c68d9ef033e366
data/build/gist CHANGED
@@ -1318,12 +1318,12 @@ end
1318
1318
  module Gist
1319
1319
  extend self
1320
1320
 
1321
- VERSION = '4.3.0'
1321
+ VERSION = '4.4.2'
1322
1322
 
1323
1323
  # A list of clipboard commands with copy and paste support.
1324
1324
  CLIPBOARD_COMMANDS = {
1325
1325
  'xclip' => 'xclip -o',
1326
- 'xsel -i' => 'xsel -o',
1326
+ 'xsel -i' => 'xsel -o',
1327
1327
  'pbcopy' => 'pbpaste',
1328
1328
  'putclip' => 'getclip'
1329
1329
  }
@@ -1346,11 +1346,32 @@ module Gist
1346
1346
  end
1347
1347
  class ClipboardError < RuntimeError; include Error end
1348
1348
 
1349
+ # helper module for authentication token actions
1350
+ module AuthTokenFile
1351
+ def self.filename
1352
+ if ENV.key?(URL_ENV_NAME)
1353
+ File.expand_path "~/.gist.#{ENV[URL_ENV_NAME].gsub(/[^a-z.]/, '')}"
1354
+ else
1355
+ File.expand_path "~/.gist"
1356
+ end
1357
+ end
1358
+
1359
+ def self.read
1360
+ File.read(filename).chomp
1361
+ end
1362
+
1363
+ def self.write(token)
1364
+ File.open(filename, 'w', 0600) do |f|
1365
+ f.write token
1366
+ end
1367
+ end
1368
+ end
1369
+
1349
1370
  # auth token for authentication
1350
1371
  #
1351
1372
  # @return [String] string value of access token or `nil`, if not found
1352
1373
  def auth_token
1353
- @token ||= File.read(auth_token_file) rescue nil
1374
+ @token ||= AuthTokenFile.read rescue nil
1354
1375
  end
1355
1376
 
1356
1377
  # Upload a gist to https://gist.github.com
@@ -1437,6 +1458,7 @@ module Gist
1437
1458
  # otherwise list public gists for given username (optional argument)
1438
1459
  #
1439
1460
  # @param [String] user
1461
+ # @deprecated
1440
1462
  #
1441
1463
  # see https://developer.github.com/v3/gists/#list-gists
1442
1464
  def list_gists(user = "")
@@ -1466,6 +1488,40 @@ module Gist
1466
1488
  end
1467
1489
  end
1468
1490
 
1491
+ def list_all_gists(user = "")
1492
+ url = "#{base_path}"
1493
+
1494
+ if user == ""
1495
+ access_token = auth_token()
1496
+ if access_token.to_s != ''
1497
+ url << "/gists?per_page=100&access_token=" << CGI.escape(access_token)
1498
+ get_gist_pages(url)
1499
+ else
1500
+ raise Error, "Not authenticated. Use 'gist --login' to login or 'gist -l username' to view public gists."
1501
+ end
1502
+
1503
+ else
1504
+ url << "/users/#{user}/gists?per_page=100"
1505
+ get_gist_pages(url)
1506
+ end
1507
+
1508
+ end
1509
+
1510
+ def get_gist_pages(url)
1511
+
1512
+ request = Net::HTTP::Get.new(url)
1513
+ response = http(api_url, request)
1514
+ pretty_gist(response)
1515
+
1516
+ link_header = response.header['link']
1517
+
1518
+ if link_header
1519
+ links = Hash[ link_header.gsub(/(<|>|")/, "").split(',').map { |link| link.split('; rel=') } ].invert
1520
+ get_gist_pages(links['next']) if links['next']
1521
+ end
1522
+
1523
+ end
1524
+
1469
1525
  # return prettified string result of response body for all gists
1470
1526
  #
1471
1527
  # @params [Net::HTTPResponse] response
@@ -1476,7 +1532,9 @@ module Gist
1476
1532
  body = JSON.parse(response.body)
1477
1533
  if response.code == '200'
1478
1534
  body.each do |gist|
1479
- puts "#{gist['html_url']} #{gist['description'] || gist['files'].keys.join(" ")} #{gist['public'] ? '' : '(secret)'}\n"
1535
+ description = "#{gist['description'] || gist['files'].keys.join(" ")} #{gist['public'] ? '' : '(secret)'}"
1536
+ puts "#{gist['html_url']} #{description.tr("\n", " ")}\n"
1537
+ $stdout.flush
1480
1538
  end
1481
1539
 
1482
1540
  else
@@ -1564,9 +1622,7 @@ module Gist
1564
1622
  end
1565
1623
 
1566
1624
  if Net::HTTPCreated === response
1567
- File.open(auth_token_file, 'w', 0600) do |f|
1568
- f.write JSON.parse(response.body)['token']
1569
- end
1625
+ AuthTokenFile.write JSON.parse(response.body)['token']
1570
1626
  puts "Success! #{ENV[URL_ENV_NAME] || "https://github.com/"}settings/applications"
1571
1627
  return
1572
1628
  elsif Net::HTTPUnauthorized === response
@@ -1747,14 +1803,6 @@ Could not find copy command, tried:
1747
1803
  ENV.key?(URL_ENV_NAME) ? URI(ENV[URL_ENV_NAME]) : GITHUB_API_URL
1748
1804
  end
1749
1805
 
1750
- def auth_token_file
1751
- if ENV.key?(URL_ENV_NAME)
1752
- File.expand_path "~/.gist.#{ENV[URL_ENV_NAME].gsub(/[^a-z.]/, '')}"
1753
- else
1754
- File.expand_path "~/.gist"
1755
- end
1756
- end
1757
-
1758
1806
  def legacy_private_gister?
1759
1807
  return unless which('git')
1760
1808
  `git config --global gist.private` =~ /\Ayes|1|true|on\z/i
@@ -1772,6 +1820,7 @@ end
1772
1820
 
1773
1821
  # Silence Ctrl-C's
1774
1822
  trap('INT'){ exit 1 }
1823
+ trap('PIPE', 'EXIT')
1775
1824
 
1776
1825
  require 'optparse'
1777
1826
 
@@ -1875,7 +1924,7 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
1875
1924
  options[:paste] = true
1876
1925
  end
1877
1926
 
1878
- opts.on("-R", "--raw", "Raw url of the new gist") do
1927
+ opts.on("-R", "--raw", "Display raw URL of the new gist") do
1879
1928
  options[:raw] = true
1880
1929
  end
1881
1930
 
@@ -1914,9 +1963,9 @@ begin
1914
1963
 
1915
1964
  if options.key? :list
1916
1965
  if options[:list]
1917
- Gist.list_gists(options[:list])
1966
+ Gist.list_all_gists(options[:list])
1918
1967
  else
1919
- Gist.list_gists
1968
+ Gist.list_all_gists
1920
1969
  end
1921
1970
  exit
1922
1971
  end
data/build/gist.1 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "GIST" "1" "August 2014" "" "Gist manual"
4
+ .TH "GIST" "1" "July 2015" "" "Gist manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBgist\fR \- upload code to https://gist\.github\.com
@@ -73,7 +73,7 @@ gist \-d "Random rbx bug" a\.rb
73
73
  You can update existing gists with \fB\-u\fR:
74
74
  .
75
75
  .IP
76
- gist lib/gist\.rb bin/gist \-u 42f2c239d2eb57299408
76
+ gist \-u GIST_ID FILE_NAME gist \-u 42f2c239d2eb57299408 test\.txt
77
77
  .
78
78
  .IP "\(bu" 4
79
79
  If you\'d like to copy the resulting URL to your clipboard, use \fB\-c\fR\.
@@ -123,7 +123,7 @@ Success! https://github\.com/settings/applications
123
123
  .IP "" 0
124
124
  .
125
125
  .P
126
- You can read the 2\-factor auth code from an sms or the authentification app, depending on how you set your account up \fIhttps://github\.com/settings/admin\fR\.
126
+ You can read the 2\-factor auth code from an sms or the authentication app, depending on how you set your account up \fIhttps://github\.com/settings/admin\fR\.
127
127
  .
128
128
  .P
129
129
  Note: 2\-factor authentication just appeared recently \fIhttps://github\.com/blog/1614\-two\-factor\-authentication\fR, so if you run into errors, update the gist gem\.
data/lib/gist.rb CHANGED
@@ -12,7 +12,7 @@ end
12
12
  module Gist
13
13
  extend self
14
14
 
15
- VERSION = '4.4.1'
15
+ VERSION = '4.4.2'
16
16
 
17
17
  # A list of clipboard commands with copy and paste support.
18
18
  CLIPBOARD_COMMANDS = {
@@ -188,7 +188,7 @@ module Gist
188
188
  if user == ""
189
189
  access_token = auth_token()
190
190
  if access_token.to_s != ''
191
- url << "/gists?per_page=100&taccess_token=" << CGI.escape(access_token)
191
+ url << "/gists?per_page=100&access_token=" << CGI.escape(access_token)
192
192
  get_gist_pages(url)
193
193
  else
194
194
  raise Error, "Not authenticated. Use 'gist --login' to login or 'gist -l username' to view public gists."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conrad Irwin