jist 0.9.0 → 0.9.1

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 (3) hide show
  1. data/bin/jist +21 -18
  2. data/lib/jist.rb +17 -12
  3. metadata +4 -5
data/bin/jist CHANGED
@@ -13,29 +13,28 @@ opts = OptionParser.new do |opts|
13
13
  opts.banner = <<-EOS
14
14
  Jist (v#{Jist::VERSION}) lets you upload to https://gist.github.com/
15
15
 
16
- Usage: #{executable_name} [-p] [-d DESC] [-t TOKEN] [-u URL] [-f NAME]* [FILE]*
16
+ Usage: #{executable_name} [-p] [-d DESC] [-t TOKEN|-a] [-u URL] [-f NAME]* [FILE]*
17
17
  #{executable_name} --login
18
18
 
19
- When used with no arguments, jist creates an anonymous, private, gist, with
20
- no description. The FILENAME defaults to "a.rb" and we read the contents of
21
- STDIN.
19
+ The content to be uploaded can be passed as a list of files, if none are
20
+ specified STDIN will be read. The default filename for STDIN is "a.rb", and all
21
+ filenames can be overridden by repeating the "-f" flag. The most useful reason
22
+ to do this is to change the syntax highlighting.
22
23
 
23
- If you'd like your gists to be associated with your github account, so that
24
- you can edit them, and find them in future, first use `jist --login` to obtain
25
- an Oauth2 access token. This is stored and used for all future uses of jist.
24
+ If you'd like your gists to be associated with your GitHub account, so that you
25
+ can edit them and find them in future, first use `jist --login` to obtain an
26
+ Oauth2 access token. This is stored and used by jist in the future.
26
27
 
27
- If you're calling jist from another program that already has an access_token
28
- with the "gist" scope, then pass it using `jist -t`.
28
+ Public gists have guessable URLs and can be created with "-p", you can also set
29
+ the description at the top of the gist by passing "-d".
29
30
 
30
- If you specify FILEs on the command line, then jist will use the names of the
31
- files you specify as the filenames for the gist. If you'd rather override the
32
- name you can specify the -f parameter once per file. If you don't specify any
33
- files, then the -f parameter will be used to name the contents of STDIN. If you
34
- don't specify the -f parameter at all when using STDIN, "a.rb" will be used.
31
+ Anonymous gists are not associated with your GitHub account, they can be created
32
+ with "-a" even after you have used "jist --login". If you already have an access
33
+ token with the "gist" scope, you can pass that with "-t".
35
34
 
36
- Making a gist public causes it to have a prettier, guessable url. And adding
37
- a description can provide useful context to people who stumble across your
38
- gist.
35
+ Instead of creating a new jist, you can update an existing one by passing its ID
36
+ or URL with "-u". For this to work, you must be logged in, and have created the
37
+ original gist with the same GitHub account.
39
38
 
40
39
  EOS
41
40
 
@@ -89,7 +88,11 @@ begin
89
88
  else
90
89
  files = {}
91
90
  ARGV.zip(filenames).each do |(file, name)|
92
- files[name || file] = File.read(File.expand_path(file))
91
+ files[name || file] = begin
92
+ File.read(File.expand_path(file))
93
+ rescue => e
94
+ raise e.extend(Jist::Error)
95
+ end
93
96
  end
94
97
 
95
98
  puts Jist.multi_gist(files, options)['html_url']
@@ -5,7 +5,7 @@ require 'json'
5
5
  # It just gists.
6
6
  module Jist
7
7
 
8
- VERSION = '0.9.0'
8
+ VERSION = '0.9.1'
9
9
 
10
10
  # Exception tag for errors raised while gisting.
11
11
  module Error; end
@@ -73,13 +73,21 @@ module Jist
73
73
  request = Net::HTTP::Post.new(url)
74
74
  request.body = JSON.dump(json)
75
75
 
76
- response = http(request)
76
+ retried = false
77
77
 
78
- if Net::HTTPSuccess === response
79
- JSON.parse(response.body)
80
- else
81
- raise "Got #{response.class} from gist: #{response.body}"
78
+ begin
79
+ response = http(request)
80
+ if Net::HTTPSuccess === response
81
+ JSON.parse(response.body)
82
+ else
83
+ raise "Got #{response.class} from gist: #{response.body}"
84
+ end
85
+ rescue => e
86
+ raise if retried
87
+ retried = true
88
+ retry
82
89
  end
90
+
83
91
  rescue => e
84
92
  raise e.extend Error
85
93
  end
@@ -126,18 +134,15 @@ module Jist
126
134
  raise e.extend Error
127
135
  end
128
136
 
129
- private
130
-
131
- module_function
132
137
  # Run an HTTP operation against api.github.com
133
138
  #
134
- # @param [Net::HTTP::Request] request
135
- # @return [Net::HTTP::Response]
139
+ # @param [Net::HTTPRequest] request
140
+ # @return [Net::HTTPResponse]
136
141
  def http(request)
137
142
  connection = Net::HTTP.new("api.github.com", 443)
138
143
  connection.use_ssl = true
139
144
  connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
140
- connection.open_timeout = 5
145
+ connection.open_timeout = 10
141
146
  connection.read_timeout = 10
142
147
  connection.start do |http|
143
148
  http.request request
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: 0.9.0
4
+ version: 0.9.1
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-07-03 00:00:00.000000000 Z
12
+ date: 2012-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -35,8 +35,7 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - lib/jist.rb
38
- - !binary |-
39
- YmluL2ppc3Q=
38
+ - bin/jist
40
39
  homepage: https://github.com/ConradIrwin/jist
41
40
  licenses: []
42
41
  post_install_message:
@@ -57,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
56
  version: '0'
58
57
  requirements: []
59
58
  rubyforge_project:
60
- rubygems_version: 1.8.19
59
+ rubygems_version: 1.8.24
61
60
  signing_key:
62
61
  specification_version: 3
63
62
  summary: Just allows you to upload gists