gist 4.3.0 → 4.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7a304fb9f742996cc0bca4b5a3d62c8ca52abba
4
- data.tar.gz: 24bcae03f00c4e4241f4dea50aae4bf64850a140
3
+ metadata.gz: a00795d0cd699dec7993e7b371e70dc3387c7a91
4
+ data.tar.gz: f8dd93ec358f2193f5764f4bb567b3189d76cfdd
5
5
  SHA512:
6
- metadata.gz: bb0f2608a1bb78e0cc359d9d4f2793ebfbf33e846fca649f91ffa48125c44ce59114b8adb84d886f6d8cf94b87a2622f8a234695b6ca04b3be4fd42d96737bbc
7
- data.tar.gz: 5bbbe8d45b08eb54ec5f659d9e23b83313ff3abf9b2475f408d44c117e62d7eb9604d0c8d26bbfe11fe313d71671e12ba696c09fc8d1d92a692909fca5fa7de6
6
+ metadata.gz: 814b45808c5aea3d9d5d35117c706f38d956f96f20c394bcb28b68fd331fed0d8ba709bafc5c47aad90362e198abb14d96f7ebf36fa2ad0a12496ba838f0bf93
7
+ data.tar.gz: 14b0f241463232cfc679fac45a6e932031b21d4fdc94c56dc72228eb56d4c4a280fd2558e2b09f90ec28d8666d0361581840a26edf3cbe899928466943f43768
data/README.md CHANGED
@@ -50,7 +50,8 @@ upload content to https://gist.github.com/.
50
50
 
51
51
  ‌You can update existing gists with `-u`:
52
52
 
53
- gist lib/gist.rb bin/gist -u 42f2c239d2eb57299408
53
+ gist -u GIST_ID FILE_NAME
54
+ gist -u 42f2c239d2eb57299408 test.txt
54
55
 
55
56
  ‌If you'd like to copy the resulting URL to your clipboard, use `-c`.
56
57
 
@@ -84,7 +85,7 @@ an OAuth2 token (with the "gist" permission).
84
85
  2-factor auth code:
85
86
  Success! https://github.com/settings/applications
86
87
 
87
- You can read the 2-factor auth code from an sms or the authentification app,
88
+ You can read the 2-factor auth code from an sms or the authentication app,
88
89
  depending on how you [set your account up](https://github.com/settings/admin).
89
90
 
90
91
  Note: 2-factor authentication
data/bin/gist CHANGED
@@ -106,7 +106,7 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
106
106
  options[:paste] = true
107
107
  end
108
108
 
109
- opts.on("-R", "--raw", "Raw url of the new gist") do
109
+ opts.on("-R", "--raw", "Display raw URL of the new gist") do
110
110
  options[:raw] = true
111
111
  end
112
112
 
@@ -145,9 +145,9 @@ begin
145
145
 
146
146
  if options.key? :list
147
147
  if options[:list]
148
- Gist.list_gists(options[:list])
148
+ Gist.list_all_gists(options[:list])
149
149
  else
150
- Gist.list_gists
150
+ Gist.list_all_gists
151
151
  end
152
152
  exit
153
153
  end
data/gist.gemspec CHANGED
@@ -14,7 +14,8 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.executables << 'gist'
16
16
 
17
- %w(rake rspec webmock ronn).each do |gem|
18
- s.add_development_dependency gem
19
- end
17
+ s.add_development_dependency 'rake'
18
+ s.add_development_dependency 'ronn'
19
+ s.add_development_dependency 'webmock'
20
+ s.add_development_dependency 'rspec', '>3'
20
21
  end
data/lib/gist.rb CHANGED
@@ -12,12 +12,12 @@ end
12
12
  module Gist
13
13
  extend self
14
14
 
15
- VERSION = '4.3.0'
15
+ VERSION = '4.4.0'
16
16
 
17
17
  # A list of clipboard commands with copy and paste support.
18
18
  CLIPBOARD_COMMANDS = {
19
19
  'xclip' => 'xclip -o',
20
- 'xsel -i' => 'xsel -o',
20
+ 'xsel -i' => 'xsel -o',
21
21
  'pbcopy' => 'pbpaste',
22
22
  'putclip' => 'getclip'
23
23
  }
@@ -40,11 +40,32 @@ module Gist
40
40
  end
41
41
  class ClipboardError < RuntimeError; include Error end
42
42
 
43
+ # helper module for authentication token actions
44
+ module AuthTokenFile
45
+ def self.filename
46
+ if ENV.key?(URL_ENV_NAME)
47
+ File.expand_path "~/.gist.#{ENV[URL_ENV_NAME].gsub(/[^a-z.]/, '')}"
48
+ else
49
+ File.expand_path "~/.gist"
50
+ end
51
+ end
52
+
53
+ def self.read
54
+ File.read(filename).chomp
55
+ end
56
+
57
+ def self.write(token)
58
+ File.open(filename, 'w', 0600) do |f|
59
+ f.write token
60
+ end
61
+ end
62
+ end
63
+
43
64
  # auth token for authentication
44
65
  #
45
66
  # @return [String] string value of access token or `nil`, if not found
46
67
  def auth_token
47
- @token ||= File.read(auth_token_file) rescue nil
68
+ @token ||= AuthTokenFile.read rescue nil
48
69
  end
49
70
 
50
71
  # Upload a gist to https://gist.github.com
@@ -160,6 +181,40 @@ module Gist
160
181
  end
161
182
  end
162
183
 
184
+ def list_all_gists(user = "")
185
+ url = "#{base_path}"
186
+
187
+ if user == ""
188
+ access_token = auth_token()
189
+ if access_token.to_s != ''
190
+ url << "/gists?access_token=" << CGI.escape(access_token)
191
+ get_gist_pages(url)
192
+ else
193
+ raise Error, "Not authenticated. Use 'gist --login' to login or 'gist -l username' to view public gists."
194
+ end
195
+
196
+ else
197
+ url << "/users/#{user}/gists"
198
+ get_gist_pages(url)
199
+ end
200
+
201
+ end
202
+
203
+ def get_gist_pages(url)
204
+
205
+ request = Net::HTTP::Get.new(url)
206
+ response = http(api_url, request)
207
+ pretty_gist(response)
208
+
209
+ link_header = response.header['link']
210
+
211
+ if link_header
212
+ links = Hash[ link_header.gsub(/(<|>|")/, "").split(',').map { |link| link.split('; rel=') } ].invert
213
+ get_gist_pages(links['next']) if links['next']
214
+ end
215
+
216
+ end
217
+
163
218
  # return prettified string result of response body for all gists
164
219
  #
165
220
  # @params [Net::HTTPResponse] response
@@ -258,9 +313,7 @@ module Gist
258
313
  end
259
314
 
260
315
  if Net::HTTPCreated === response
261
- File.open(auth_token_file, 'w', 0600) do |f|
262
- f.write JSON.parse(response.body)['token']
263
- end
316
+ AuthTokenFile.write JSON.parse(response.body)['token']
264
317
  puts "Success! #{ENV[URL_ENV_NAME] || "https://github.com/"}settings/applications"
265
318
  return
266
319
  elsif Net::HTTPUnauthorized === response
@@ -441,14 +494,6 @@ Could not find copy command, tried:
441
494
  ENV.key?(URL_ENV_NAME) ? URI(ENV[URL_ENV_NAME]) : GITHUB_API_URL
442
495
  end
443
496
 
444
- def auth_token_file
445
- if ENV.key?(URL_ENV_NAME)
446
- File.expand_path "~/.gist.#{ENV[URL_ENV_NAME].gsub(/[^a-z.]/, '')}"
447
- else
448
- File.expand_path "~/.gist"
449
- end
450
- end
451
-
452
497
  def legacy_private_gister?
453
498
  return unless which('git')
454
499
  `git config --global gist.private` =~ /\Ayes|1|true|on\z/i
@@ -0,0 +1,61 @@
1
+ describe Gist::AuthTokenFile do
2
+ subject { Gist::AuthTokenFile }
3
+
4
+ before(:each) do
5
+ stub_const("Gist::URL_ENV_NAME", "STUBBED_GITHUB_URL")
6
+ end
7
+
8
+ describe "::filename" do
9
+ let(:filename) { double() }
10
+
11
+ context "with default GITHUB_URL" do
12
+ it "is ~/.gist" do
13
+ File.should_receive(:expand_path).with("~/.gist").and_return(filename)
14
+ subject.filename.should be filename
15
+ end
16
+ end
17
+
18
+ context "with custom GITHUB_URL" do
19
+ before do
20
+ ENV[Gist::URL_ENV_NAME] = github_url
21
+ end
22
+ let(:github_url) { "gh.custom.org" }
23
+
24
+ it "is ~/.gist.{custom_github_url}" do
25
+ File.should_receive(:expand_path).with("~/.gist.#{github_url}").and_return(filename)
26
+ subject.filename.should be filename
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ describe "::read" do
33
+ let(:token) { "auth_token" }
34
+
35
+ it "reads file contents" do
36
+ File.should_receive(:read).and_return(token)
37
+ subject.read.should eq token
38
+ end
39
+
40
+ it "chomps file contents" do
41
+ File.should_receive(:read).and_return(token + "\n")
42
+ subject.read.should eq token
43
+ end
44
+ end
45
+
46
+ describe "::write" do
47
+ let(:token) { double() }
48
+ let(:filename) { double() }
49
+ let(:token_file) { double() }
50
+
51
+ before do
52
+ subject.stub(:filename) { filename }
53
+ end
54
+
55
+ it "writes token to file" do
56
+ File.should_receive(:open).with(filename, 'w', 0600).and_yield(token_file)
57
+ token_file.should_receive(:write).with(token)
58
+ subject.write(token)
59
+ end
60
+ end
61
+ end
data/spec/ghe_spec.rb CHANGED
@@ -63,7 +63,7 @@ describe '...' do
63
63
 
64
64
  it "uses them" do
65
65
  $stdin = StringIO.new "#{MOCK_USER}_wrong\n#{MOCK_PASSWORD}_wrong\n"
66
- Gist.login! username: MOCK_USER, password: MOCK_PASSWORD
66
+ Gist.login! :username => MOCK_USER, :password => MOCK_PASSWORD
67
67
 
68
68
  assert_requested(:post, /#{MOCK_AUTHZ_GITHUB_URL}authorizations/)
69
69
  end
data/spec/gist_spec.rb CHANGED
@@ -2,21 +2,21 @@ describe Gist do
2
2
 
3
3
  describe "should_be_public?" do
4
4
  it "should return false if -p is specified" do
5
- Gist.should_be_public?(private: true).should be_false
5
+ Gist.should_be_public?(:private => true).should be_falsy
6
6
  end
7
7
 
8
8
  it "should return false if legacy_private_gister?" do
9
9
  Gist.should_receive(:legacy_private_gister?).and_return(true)
10
- Gist.should_be_public?.should be_false
10
+ Gist.should_be_public?.should be_falsy
11
11
  end
12
12
 
13
13
  it "should return true if --no-private is specified" do
14
14
  Gist.stub(:legacy_private_gister?).and_return(true)
15
- Gist.should_be_public?(private: false).should be_true
15
+ Gist.should_be_public?(:private => false).should be_truthy
16
16
  end
17
17
 
18
18
  it "should return true by default" do
19
- Gist.should_be_public?.should be_true
19
+ Gist.should_be_public?.should be_truthy
20
20
  end
21
21
  end
22
22
 
data/spec/spec_helper.rb CHANGED
@@ -5,11 +5,15 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
10
9
  config.filter_run :focus
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.syntax = :should
12
+ end
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.syntax = :should
15
+ end
11
16
  end
12
17
 
13
18
  require 'webmock/rspec'
14
- require_relative '../lib/gist'
15
-
19
+ require 'gist'
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.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conrad Irwin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-06 00:00:00.000000000 Z
12
+ date: 2015-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rspec
29
+ name: ronn
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -54,19 +54,19 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: ronn
57
+ name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - ">"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: '3'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - ">"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '3'
70
70
  description: Provides a single function (Gist.gist) that uploads a gist.
71
71
  email:
72
72
  - conrad.irwin@gmail.com
@@ -87,6 +87,7 @@ files:
87
87
  - build/gist.1
88
88
  - gist.gemspec
89
89
  - lib/gist.rb
90
+ - spec/auth_token_file_spec.rb
90
91
  - spec/clipboard_spec.rb
91
92
  - spec/ghe_spec.rb
92
93
  - spec/gist_spec.rb
@@ -115,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  version: '0'
116
117
  requirements: []
117
118
  rubyforge_project:
118
- rubygems_version: 2.2.2
119
+ rubygems_version: 2.4.5
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: Just allows you to upload gists
122
123
  test_files: []
123
- has_rdoc: