hoick 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,11 +18,19 @@ Hoick has subcommands modelled on HTTP verbs.
18
18
 
19
19
  To fetch a resource, use GET. The response body will be printed to STDOUT.
20
20
 
21
+ $ hoick GET http://api.example.com/widgets/123
22
+
21
23
  If you're interested in response headers too, add the "`-h`" flag. Add the "`--follow`" flag if you wish to follow redirects.
22
24
 
23
25
  ### PUT and POST
24
26
 
25
- The "PUT" subcommand uploads data to a specified URL. By default, the payload is read from STDIN, but you can specify the "`-F`" option to read it from a file, instead.
27
+ The "PUT" subcommand uploads data to a specified URL.
28
+
29
+ $ hoick PUT -T json http://api.example.com/widgets/123 < widget-123.json
30
+
31
+ By default, the payload is read from STDIN, but you can specify the "`-F`" option to read it from a file, instead.
32
+
33
+ $ hoick PUT -F widget-123.json http://api.example.com/widgets/123
26
34
 
27
35
  Hoick guesses a "Content-Type" from the file-name. If a type cannot be guessed, or if the payload is sourced from STDIN, binary data ("application/octet-stream") is assumed. Either way, the default can be overridden with "`-T`" (which can be either a file extension, or a full MIME-type string).
28
36
 
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "clamp", "~> 0.5.1"
21
22
  spec.add_runtime_dependency "mime-types", "~> 1.22"
22
23
 
23
24
  end
@@ -29,6 +29,8 @@ module Hoick
29
29
  option ["-b", "--[no-]body"], :flag, "display response body", :default => true
30
30
  option ["-h", "--[no-]headers"], :flag, "display response status and headers"
31
31
 
32
+ option ["--timeout"], "SECONDS", "HTTP connection/read timeout", &method(:Float)
33
+
32
34
  option ["--debug"], :flag, "debug"
33
35
 
34
36
  def follow_redirects?
@@ -72,6 +74,16 @@ module Hoick
72
74
 
73
75
  end
74
76
 
77
+ subcommand ["head", "HEAD"], "HTTP HEAD" do
78
+
79
+ declare_url_parameter
80
+
81
+ def execute
82
+ http_request("HEAD", full_url, nil, nil, &method(:display_response))
83
+ end
84
+
85
+ end
86
+
75
87
  module PayloadOptions
76
88
 
77
89
  extend Clamp::Option::Declaration
@@ -153,6 +165,9 @@ module Hoick
153
165
  rescue Redirected => e
154
166
  uri = URI(e.location)
155
167
  retry
168
+ rescue SocketError, TimedOut => e
169
+ $stderr.puts "ERROR: #{e}"
170
+ exit(1)
156
171
  end
157
172
 
158
173
  def build_request(method, uri, content, content_type)
@@ -169,9 +184,19 @@ module Hoick
169
184
  http = Net::HTTP.new(uri.host, uri.port)
170
185
  http.use_ssl = (uri.scheme == "https")
171
186
  http.set_debug_output($stderr) if debug?
187
+ if timeout
188
+ http.open_timeout = timeout
189
+ http.read_timeout = timeout
190
+ end
172
191
  http.start do
173
- yield http
192
+ begin
193
+ yield http
194
+ rescue Timeout::Error
195
+ raise TimedOut, "request timed out"
196
+ end
174
197
  end
198
+ rescue Timeout::Error
199
+ raise TimedOut, "connection timed out"
175
200
  end
176
201
 
177
202
  def display_response(response)
@@ -192,6 +217,8 @@ module Hoick
192
217
  end
193
218
  end
194
219
 
220
+ class TimedOut < StandardError; end
221
+
195
222
  end
196
223
 
197
224
  end
@@ -1,3 +1,3 @@
1
1
  module Hoick
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,18 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Mike Williams
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-08-14 00:00:00.000000000 Z
12
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: clamp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.1
13
30
  - !ruby/object:Gem::Dependency
14
31
  name: mime-types
15
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
16
34
  requirements:
17
35
  - - ~>
18
36
  - !ruby/object:Gem::Version
@@ -20,6 +38,7 @@ dependencies:
20
38
  type: :runtime
21
39
  prerelease: false
22
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
23
42
  requirements:
24
43
  - - ~>
25
44
  - !ruby/object:Gem::Version
@@ -46,25 +65,32 @@ files:
46
65
  homepage: https://github.com/mdub/hoick
47
66
  licenses:
48
67
  - MIT
49
- metadata: {}
50
68
  post_install_message:
51
69
  rdoc_options: []
52
70
  require_paths:
53
71
  - lib
54
72
  required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
55
74
  requirements:
56
- - - '>='
75
+ - - ! '>='
57
76
  - !ruby/object:Gem::Version
58
77
  version: '0'
78
+ segments:
79
+ - 0
80
+ hash: -3857892055023656216
59
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
60
83
  requirements:
61
- - - '>='
84
+ - - ! '>='
62
85
  - !ruby/object:Gem::Version
63
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -3857892055023656216
64
90
  requirements: []
65
91
  rubyforge_project:
66
- rubygems_version: 2.0.0
92
+ rubygems_version: 1.8.23
67
93
  signing_key:
68
- specification_version: 4
94
+ specification_version: 3
69
95
  summary: A command-line HTTP client
70
96
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 0003e566cb04c2c3704564ddfbbbf643f4574322
4
- data.tar.gz: efbd89eb6c6b7fbe3a2fd12bd6d8f32faf0340b9
5
- SHA512:
6
- metadata.gz: d58fdcddc91db51bc7d06be0407af0df00f376bf4daa695a72c2db36fd81b5e42b9cddb19dc516f6326052a83d21a84fde7461b1b4de1b458c2611eed9a731d5
7
- data.tar.gz: 222734633bae1b63c7e9e1ffe9079d4d76b43a2612e7c480c52691755b449e752b324383d566c8efac2154ce22dbade0d71a6b538ec36ec2ac054ceb3fc41749