jist 1.1.0 → 1.2.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.
- data/Gemfile +1 -1
- data/bin/jist +8 -1
- data/jist.gemspec +1 -1
- data/lib/jist.rb +36 -2
- data/spec/shorten_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +19 -2
data/Gemfile
CHANGED
data/bin/jist
CHANGED
|
@@ -29,6 +29,9 @@ Anonymous gists are not associated with your GitHub account, they can be created
|
|
|
29
29
|
with "-a" even after you have used "jist --login". If you already have an access
|
|
30
30
|
token with the "gist" scope, you can pass that with "-t".
|
|
31
31
|
|
|
32
|
+
If you would like to shorten the resulting gist URL, use the -s flag. This will
|
|
33
|
+
use GitHub's URL shortener, git.io.
|
|
34
|
+
|
|
32
35
|
To copy the resulting URL to your clipboard you can use the -c option, or to just
|
|
33
36
|
open it directly in your browser, use -o. You can add `alias jist='jist -c'` to
|
|
34
37
|
your shell's rc file to configure this behaviour by default.
|
|
@@ -37,7 +40,7 @@ Instead of creating a new jist, you can update an existing one by passing its ID
|
|
|
37
40
|
or URL with "-u". For this to work, you must be logged in, and have created the
|
|
38
41
|
original gist with the same GitHub account.
|
|
39
42
|
|
|
40
|
-
Usage: #{executable_name} [-o|-c] [-p] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
|
|
43
|
+
Usage: #{executable_name} [-o|-c] [-p] [-s] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
|
|
41
44
|
#{executable_name} --login
|
|
42
45
|
|
|
43
46
|
EOS
|
|
@@ -60,6 +63,10 @@ Usage: #{executable_name} [-o|-c] [-p] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f
|
|
|
60
63
|
options[:description] = description
|
|
61
64
|
end
|
|
62
65
|
|
|
66
|
+
opts.on("-s", "--shorten", "Shorten the gist URL using git.io.") do |shorten|
|
|
67
|
+
options[:shorten] = shorten
|
|
68
|
+
end
|
|
69
|
+
|
|
63
70
|
opts.on("-u", "--update [ URL | ID ]", "Update an existing gist.") do |update|
|
|
64
71
|
options[:update] = update
|
|
65
72
|
end
|
data/jist.gemspec
CHANGED
data/lib/jist.rb
CHANGED
|
@@ -6,7 +6,7 @@ require 'json'
|
|
|
6
6
|
module Jist
|
|
7
7
|
extend self
|
|
8
8
|
|
|
9
|
-
VERSION = '1.
|
|
9
|
+
VERSION = '1.2.0'
|
|
10
10
|
|
|
11
11
|
# A list of clipboard commands with copy and paste support.
|
|
12
12
|
CLIPBOARD_COMMANDS = {
|
|
@@ -28,6 +28,7 @@ module Jist
|
|
|
28
28
|
# @option options [String] :filename ('a.rb') the filename
|
|
29
29
|
# @option options [Boolean] :public (false) is this gist public
|
|
30
30
|
# @option options [Boolean] :anonymous (false) is this gist anonymous
|
|
31
|
+
# @option options [Boolean] :shorten (false) Shorten the resulting URL using git.io.
|
|
31
32
|
# @option options [String] :access_token (`File.read("~/.jist")`) The OAuth2 access token.
|
|
32
33
|
# @option options [String] :update the URL or id of a gist to update
|
|
33
34
|
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
|
|
@@ -50,6 +51,7 @@ module Jist
|
|
|
50
51
|
# @option options [String] :description the description
|
|
51
52
|
# @option options [Boolean] :public (false) is this gist public
|
|
52
53
|
# @option options [Boolean] :anonymous (false) is this gist anonymous
|
|
54
|
+
# @option options [Boolean] :shorten (false) Shorten the resulting URL using git.io.
|
|
53
55
|
# @option options [String] :access_token (`File.read("~/.jist")`) The OAuth2 access token.
|
|
54
56
|
# @option options [String] :update the URL or id of a gist to update
|
|
55
57
|
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
|
|
@@ -105,6 +107,20 @@ module Jist
|
|
|
105
107
|
raise e.extend Error
|
|
106
108
|
end
|
|
107
109
|
|
|
110
|
+
# Convert long github urls into shotr git.io ones
|
|
111
|
+
#
|
|
112
|
+
# @param [String] url
|
|
113
|
+
# @return [String] shortened url, or long url if shortening fails
|
|
114
|
+
def shorten(url)
|
|
115
|
+
response = Net::HTTP.post_form(URI("http://git.io/"), :url => url)
|
|
116
|
+
case response.code
|
|
117
|
+
when "201"
|
|
118
|
+
response['Location']
|
|
119
|
+
else
|
|
120
|
+
url
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
108
124
|
# Log the user into jist.
|
|
109
125
|
#
|
|
110
126
|
# This method asks the user for a username and password, and tries to obtain
|
|
@@ -188,6 +204,7 @@ module Jist
|
|
|
188
204
|
def on_success(body, options={})
|
|
189
205
|
json = JSON.parse(body)
|
|
190
206
|
|
|
207
|
+
json['html_url'] = shorten(json['html_url']) if options[:shorten]
|
|
191
208
|
Jist.copy(json['html_url']) if options[:copy]
|
|
192
209
|
Jist.open(json['html_url']) if options[:open]
|
|
193
210
|
|
|
@@ -214,6 +231,23 @@ module Jist
|
|
|
214
231
|
`#{clipboard_command(:paste)}`
|
|
215
232
|
end
|
|
216
233
|
|
|
234
|
+
# Find command from PATH environment.
|
|
235
|
+
#
|
|
236
|
+
# @param [String] cmd command name to find
|
|
237
|
+
# @param [String] options PATH environment variable
|
|
238
|
+
# @return [String] the command found
|
|
239
|
+
def which(cmd, path=ENV['PATH'])
|
|
240
|
+
if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin|cygwin/
|
|
241
|
+
path.split(File::PATH_SEPARATOR).each {|dir|
|
|
242
|
+
f = File.join(dir, cmd+".exe")
|
|
243
|
+
return f if File.executable?(f) && !File.directory?(f)
|
|
244
|
+
}
|
|
245
|
+
nil
|
|
246
|
+
else
|
|
247
|
+
return system("which #{cmd} > /dev/null 2>&1")
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
217
251
|
# Get the command to use for the clipboard action.
|
|
218
252
|
#
|
|
219
253
|
# @param [Symbol] action either :copy or :paste
|
|
@@ -221,7 +255,7 @@ module Jist
|
|
|
221
255
|
# @raise [RuntimeError] if no clipboard integration could be found
|
|
222
256
|
def clipboard_command(action)
|
|
223
257
|
command = CLIPBOARD_COMMANDS.keys.detect do |cmd|
|
|
224
|
-
|
|
258
|
+
which cmd
|
|
225
259
|
end
|
|
226
260
|
raise "Could not find copy command, tried: #{CLIPBOARD_COMMANDS}" unless command
|
|
227
261
|
action == :copy ? command : CLIPBOARD_COMMANDS[command]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
describe '...' do
|
|
2
|
+
before do
|
|
3
|
+
stub_request(:post, /api\.github.com\/gists\?access_token=.*/).to_return(:body => '{"html_url": "http://github.com/"}')
|
|
4
|
+
stub_request(:post, "http://git.io/").to_return(:status => 201, :headers => { 'Location' => 'http://git.io/XXXXXX' })
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "should return a shortened version of the URL" do
|
|
8
|
+
Jist.gist("Test gist", :shorten => true).should == {"html_url" => "http://git.io/XXXXXX"}
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: json
|
|
@@ -59,6 +59,22 @@ dependencies:
|
|
|
59
59
|
- - ! '>='
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: webmock
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
62
78
|
description: Provides a single function (Jist.gist) that uploads a gist.
|
|
63
79
|
email: conrad.irwin@gmail.com
|
|
64
80
|
executables:
|
|
@@ -77,6 +93,7 @@ files:
|
|
|
77
93
|
- lib/jist.rb
|
|
78
94
|
- spec/clipboard_spec.rb
|
|
79
95
|
- spec/proxy_spec.rb
|
|
96
|
+
- spec/shorten_spec.rb
|
|
80
97
|
- spec/spec_helper.rb
|
|
81
98
|
homepage: https://github.com/ConradIrwin/jist
|
|
82
99
|
licenses:
|