jist 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/jist +3 -0
  2. data/lib/jist.rb +19 -5
  3. metadata +33 -50
data/bin/jist CHANGED
@@ -90,6 +90,9 @@ begin
90
90
 
91
91
  puts Jist.multi_gist(files, options)['html_url']
92
92
  end
93
+ rescue Jist::Error => e
94
+ puts "Error: #{e.message}"
95
+ exit 1
93
96
  rescue Interrupt
94
97
  # bye!
95
98
  end
data/lib/jist.rb CHANGED
@@ -5,7 +5,10 @@ require 'json'
5
5
  # It just gists.
6
6
  module Jist
7
7
 
8
- VERSION = '0.7.1'
8
+ VERSION = '0.8.0'
9
+
10
+ # Exception tag for errors raised while gisting.
11
+ module Error; end
9
12
 
10
13
  module_function
11
14
  # Upload a gist to https://gist.github.com
@@ -20,7 +23,7 @@ module Jist
20
23
  # @option options [String] :update the URL or id of a gist to update
21
24
  #
22
25
  # @return [Hash] the decoded JSON response from the server
23
- # @raise [Exception] if something went wrong
26
+ # @raise [Jist::Error] if something went wrong
24
27
  #
25
28
  # @see http://developer.github.com/v3/gists/
26
29
  def gist(content, options = {})
@@ -39,7 +42,7 @@ module Jist
39
42
  # @option options [String] :update the URL or id of a gist to update
40
43
  #
41
44
  # @return [Hash] the decoded JSON response from the server
42
- # @raise [Exception] if something went wrong
45
+ # @raise [Jist::Error] if something went wrong
43
46
  #
44
47
  # @see http://developer.github.com/v3/gists/
45
48
  def multi_gist(files, options={})
@@ -50,6 +53,7 @@ module Jist
50
53
  json[:files] = {}
51
54
 
52
55
  files.each_pair do |(name, content)|
56
+ raise "Cannot gist empty files" if content.to_s.strip == ""
53
57
  json[:files][File.basename(name)] = {:content => content}
54
58
  end
55
59
 
@@ -68,14 +72,19 @@ module Jist
68
72
  if Net::HTTPSuccess === response
69
73
  JSON.parse(response.body)
70
74
  else
71
- raise RuntimeError.new "Got #{response.class} from gist: #{response.body}"
75
+ raise "Got #{response.class} from gist: #{response.body}"
72
76
  end
77
+ rescue => e
78
+ raise e.extend Error
73
79
  end
74
80
 
75
81
  # Log the user into jist.
76
82
  #
77
83
  # This method asks the user for a username and password, and tries to obtain
78
84
  # and OAuth2 access token, which is then stored in ~/.jist
85
+ #
86
+ # @raise [Jist::Error] if something went wrong
87
+ # @see http://developer.github.com/v3/oauth/
79
88
  def login!
80
89
  puts "Obtaining OAuth2 access_token from github."
81
90
  print "Github username: "
@@ -105,8 +114,10 @@ module Jist
105
114
  end
106
115
  puts "Success! https://github.com/settings/applications"
107
116
  else
108
- raise RuntimeError.new "Got #{response.class} from gist: #{response.body}"
117
+ raise "Got #{response.class} from gist: #{response.body}"
109
118
  end
119
+ rescue => e
120
+ raise e.extend Error
110
121
  end
111
122
 
112
123
  private
@@ -120,9 +131,12 @@ module Jist
120
131
  connection = Net::HTTP.new("api.github.com", 443)
121
132
  connection.use_ssl = true
122
133
  connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
134
+ connection.open_timeout = 5
123
135
  connection.read_timeout = 10
124
136
  connection.start do |http|
125
137
  http.request request
126
138
  end
139
+ rescue Timeout::Error
140
+ raise "Could not connect to https://api.github.com/"
127
141
  end
128
142
  end
metadata CHANGED
@@ -1,80 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jist
3
- version: !ruby/object:Gem::Version
4
- hash: 1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 7
9
- - 1
10
- version: 0.7.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Conrad Irwin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-06-26 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
34
30
  description: Provides a single function (Jist.gist) that uploads a gist.
35
31
  email: conrad.irwin@gmail.com
36
- executables:
32
+ executables:
37
33
  - jist
38
34
  extensions: []
39
-
40
35
  extra_rdoc_files: []
41
-
42
- files:
36
+ files:
43
37
  - lib/jist.rb
44
38
  - bin/jist
45
39
  homepage: https://github.com/ConradIrwin/jist
46
40
  licenses: []
47
-
48
41
  post_install_message:
49
42
  rdoc_options: []
50
-
51
- require_paths:
43
+ require_paths:
52
44
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
45
+ required_ruby_version: !ruby/object:Gem::Requirement
54
46
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
52
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
71
57
  requirements: []
72
-
73
58
  rubyforge_project:
74
- rubygems_version: 1.8.21
59
+ rubygems_version: 1.8.24
75
60
  signing_key:
76
61
  specification_version: 3
77
62
  summary: Just allows you to upload gists
78
63
  test_files: []
79
-
80
- has_rdoc: