Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove anonymous support due to deprecation. #280

Merged
merged 4 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions bin/gist
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ specified STDIN will be read. The default filename for STDIN is "a.rb", and all
filenames can be overridden by repeating the "-f" flag. The most useful reason
to do this is to change the syntax highlighting.

If you'd like your gists to be associated with your GitHub account, so that you
can edit them and find them in future, first use `gist --login` to obtain an
Oauth2 access token. This is stored and used by gist in the future.
All gists must to be associated with a GitHub account, so you will need to login with
`gist --login` to obtain an Oauth2 access token. This is stored and used by gist in the future.

Private gists do not have guessable URLs and can be created with "-p", you can
also set the description at the top of the gist by passing "-d".

Anonymous gists are not associated with your GitHub account, they can be created
with "-a" even after you have used "gist --login".

If you would like to shorten the resulting gist URL, use the -s flag. This will
use GitHub's URL shortener, git.io. You can also use -R to get the link to the
raw gist.
Expand All @@ -50,7 +46,7 @@ original gist with the same GitHub account.
If you want to skip empty files, use the --skip-empty flag. If all files are
empty no gist will be created.

Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-u URL]
[--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
#{executable_name} --login
#{executable_name} [-l|-r]
Expand Down Expand Up @@ -92,10 +88,6 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
options[:update] = update
end

opts.on("-a", "--anonymous", "Create an anonymous gist.") do
options[:anonymous] = true
end

opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
options[:copy] = true
end
Expand Down Expand Up @@ -148,6 +140,12 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
end.parse!

begin
if Gist.auth_token.nil?
puts 'Please log in with `gist --login`. ' \
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
exit(1)
end

options[:output] = if options[:embed] && options[:shorten]
raise Gist::Error, "--embed does not make sense with --shorten"
elsif options[:embed]
Expand Down
12 changes: 7 additions & 5 deletions lib/gist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def default_filename
#
# @see http://developer.github.com/v3/gists/
def multi_gist(files, options={})
if options[:anonymous]
raise 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
else
access_token = (options[:access_token] || auth_token())
end

json = {}

json[:description] = options[:description] if options[:description]
Expand All @@ -126,11 +133,6 @@ def multi_gist(files, options={})
return if json[:files].empty? && options[:skip_empty]

existing_gist = options[:update].to_s.split("/").last
if options[:anonymous]
access_token = nil
else
access_token = (options[:access_token] || auth_token())
end

url = "#{base_path}/gists"
url << "/" << CGI.escape(existing_gist) if existing_gist.to_s != ''
Expand Down
11 changes: 10 additions & 1 deletion spec/rawify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
end

it "should return the raw file url" do
Gist.gist("Test gist", :output => :raw_url, :anonymous => true).should == "https://gist.github.com/anonymous/XXXXXX/raw"
Gist.gist("Test gist", :output => :raw_url, :anonymous => false).should == "https://gist.github.com/anonymous/XXXXXX/raw"
end

it 'should raise an error when trying to do operations without being logged in' do
error_msg = 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'

expect do
Gist.gist("Test gist", output: :raw_url, anonymous: true)
end.to raise_error(StandardError, error_msg)
end
end

13 changes: 11 additions & 2 deletions spec/shorten_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@

it "should return a shortened version of the URL when response is 200" do
stub_request(:post, "https://git.io/create").to_return(:status => 200, :body => 'XXXXXX')
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
Gist.gist("Test gist", :output => :short_url, anonymous: false).should == "https://git.io/XXXXXX"
end

it "should return a shortened version of the URL when response is 201" do
stub_request(:post, "https://git.io/create").to_return(:status => 201, :headers => { 'Location' => 'https://git.io/XXXXXX' })
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
Gist.gist("Test gist", :output => :short_url, anonymous: false).should == "https://git.io/XXXXXX"
end

it 'should raise an error when trying to get short urls without being logged in' do
error_msg = 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'

expect do
Gist.gist("Test gist", output: :short_url, anonymous: true)
end.to raise_error(StandardError, error_msg)
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mocks.syntax = :should
end
config.expect_with :rspec do |expectations|
expectations.syntax = :should
expectations.syntax = [:should, :expect]
end
end

Expand Down