curl_wrapper 0.0.2 → 0.0.3
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/MIT-LICENSE +6 -6
- data/lib/curl_wrapper.rb +8 -6
- data/lib/curl_wrapper/config_options.rb +8 -8
- data/lib/curl_wrapper/version.rb +1 -1
- data/test/units/curl_wrapper_test.rb +24 -25
- data/test/units/curl_wrapper_test/config_options_test.rb +17 -17
- metadata +10 -5
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2012 Ægir Örn Símonarson
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -13,8 +13,8 @@ included in all copies or substantial portions of the Software.
|
|
13
13
|
|
14
14
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/curl_wrapper.rb
CHANGED
@@ -4,36 +4,38 @@ require 'open3'
|
|
4
4
|
|
5
5
|
class CurlWrapper
|
6
6
|
include CurlWrapper::ConfigOptions
|
7
|
-
|
7
|
+
|
8
8
|
class << self
|
9
9
|
def method_missing(method, *args, &block)
|
10
10
|
new.send(method, *args, &block)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
13
14
|
def initialize(&block)
|
14
15
|
yield self if block_given?
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
def command
|
18
19
|
['curl', options].join(' ')
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
def run
|
22
23
|
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(command)
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def out
|
26
27
|
run if @stdout.nil?
|
27
28
|
@stdout.collect(&:to_s).join('')
|
28
29
|
end
|
30
|
+
|
29
31
|
alias :body :out
|
30
32
|
alias :to_s :out
|
31
|
-
|
33
|
+
|
32
34
|
def err
|
33
35
|
run if @stdout.nil?
|
34
36
|
@stderr.collect(&:to_s).join('')
|
35
37
|
end
|
36
|
-
|
38
|
+
|
37
39
|
def to_ary
|
38
40
|
[to_s]
|
39
41
|
end
|
@@ -10,11 +10,11 @@ class CurlWrapper
|
|
10
10
|
end
|
11
11
|
append_option option, args.first
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def options
|
15
15
|
@options
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def append_option option, value = nil
|
19
19
|
option = "#{option} '#{value}'" unless value.nil?
|
20
20
|
if @options.nil?
|
@@ -24,25 +24,25 @@ class CurlWrapper
|
|
24
24
|
end
|
25
25
|
self
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def fail
|
29
29
|
append_option '--fail'
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def http1_0
|
33
33
|
append_option '--http1.0'
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def proxy1_0 value
|
37
37
|
append_option '--proxy1.0', value
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def p
|
41
41
|
append_option '-p'
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def verbose
|
45
45
|
append_option '--verbose'
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
data/lib/curl_wrapper/version.rb
CHANGED
@@ -3,113 +3,112 @@ require 'minitest/pride'
|
|
3
3
|
require 'curl_wrapper'
|
4
4
|
|
5
5
|
class CurlWrapperTest < MiniTest::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
def test_curl_basic
|
8
8
|
curl = CurlWrapper.new
|
9
9
|
assert_equal 'curl ', curl.command
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test_curl_with_block
|
13
13
|
curl = CurlWrapper.new do |config|
|
14
|
-
|
14
|
+
|
15
15
|
end
|
16
16
|
assert_equal 'curl ', curl.command
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_collin_curl
|
20
20
|
curl_result = `curl 2>/dev/null`
|
21
21
|
curl = CurlWrapper.new
|
22
22
|
curl.run
|
23
23
|
assert_equal curl_result, curl.out, ":out should return culr help message #{curl_result}"
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_collin_curl
|
27
27
|
curl_result = `curl 2>&1`
|
28
28
|
curl = CurlWrapper.new
|
29
29
|
curl.run
|
30
30
|
assert_equal curl_result, curl.err, ":err should return culr help message #{curl_result}"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def test_command_after_help_option
|
34
34
|
expected_command = 'curl --help'
|
35
35
|
curl = CurlWrapper.new
|
36
36
|
curl.help
|
37
|
-
|
37
|
+
|
38
38
|
assert_equal expected_command, curl.command, ":command should be #{expected_command}"
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_called_with_help_option
|
42
42
|
expected_out = `curl --help`
|
43
43
|
curl = CurlWrapper.new
|
44
44
|
curl.help
|
45
45
|
curl.run
|
46
|
-
|
46
|
+
|
47
47
|
assert_equal expected_out, curl.out, ":out should return the help screen"
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_excepts_config_in_a_block
|
51
51
|
expected_out = `curl --help`
|
52
52
|
curl = CurlWrapper.new do |config|
|
53
53
|
config.help
|
54
54
|
end
|
55
55
|
curl.run
|
56
|
-
|
56
|
+
|
57
57
|
assert_equal expected_out, curl.out, ":out should return the help screen"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def test_autoruns_on_calling_out
|
61
61
|
expected_out = `curl --help`
|
62
62
|
curl = CurlWrapper.new do |config|
|
63
63
|
config.help
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
assert_equal expected_out, curl.out, ":out should return the help screen"
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_autoruns_on_calling_err
|
70
70
|
expected_out = ''
|
71
71
|
curl = CurlWrapper.new do |config|
|
72
72
|
config.help
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
assert_equal expected_out, curl.err, ":out should return the help screen"
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def test_options_should_return_self
|
79
79
|
expected_out = `curl --help`
|
80
80
|
curl = CurlWrapper.new
|
81
81
|
assert_equal curl, curl.help, "Should be returning it self"
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def test_is_chanable
|
85
85
|
expected_out = `curl --help`
|
86
86
|
assert_equal expected_out, CurlWrapper.new.help.out, "Should be returning it self"
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def test_get_new_out_of_the_way
|
90
90
|
expected_out = `curl --help`
|
91
91
|
assert_equal expected_out, CurlWrapper.help.out, "Should be returning it self"
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def test_body_should_be_aliast_to_out
|
95
95
|
expected_out = `curl --help`
|
96
96
|
assert_equal expected_out, CurlWrapper.help.body, "Should be returning it self"
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
def test_to_s_should_be_aliast_to_out
|
100
100
|
expected_out = `curl --help`
|
101
101
|
assert_equal expected_out, CurlWrapper.help.to_s, "Should be returning it self"
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
def test_skiping_out_should_just_work
|
105
105
|
expected_out = `curl --help`
|
106
106
|
assert_equal expected_out, "#{CurlWrapper.help}", "Should be returning it self"
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
def test_should_convert_to_array_to_work_with_puts
|
110
110
|
expected_out = `curl --help`
|
111
111
|
assert_equal expected_out, CurlWrapper.help.to_ary.first, "Should be returning it self"
|
112
112
|
end
|
113
|
-
|
114
|
-
|
115
|
-
end
|
113
|
+
|
114
|
+
end
|
@@ -152,8 +152,8 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
152
152
|
{ :method => :write_out, :option => '--write-out', :param => 'FORMAT', :description => %q[What to output after completion] },
|
153
153
|
{ :method => :xattr, :option => '--xattr', :description => %q[Store metadata in extended file attributes] },
|
154
154
|
]
|
155
|
-
|
156
|
-
KNOWN_SHORT_CURL_OPTIONS = [
|
155
|
+
|
156
|
+
KNOWN_SHORT_CURL_OPTIONS = [
|
157
157
|
{ :method => :a, :option => '-a', :description => %q[Append to target file when uploading (F/SFTP)] },
|
158
158
|
{ :method => :E, :option => '-E', :param => 'CERT[:PASSWD]', :description => %q[Client certificate file and password (SSL)] },
|
159
159
|
{ :method => :K, :option => '-K', :param => 'FILE', :description => %q[Specify which config file to read] },
|
@@ -212,11 +212,11 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
212
212
|
{ :method => :w, :option => '-w', :param => 'FORMAT', :description => %q[What to output after completion] },
|
213
213
|
{ :method => :q, :option => '-q', :description => %q[If used as the first parameter disables .curlrc] },
|
214
214
|
]
|
215
|
-
|
215
|
+
|
216
216
|
class CurlWrapperFack
|
217
217
|
include CurlWrapper::ConfigOptions
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def test_known_long_curl_options
|
221
221
|
KNOWN_LONG_CURL_OPTIONS.each do |long_option|
|
222
222
|
curl = CurlWrapperFack.new
|
@@ -231,7 +231,7 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
231
231
|
end
|
232
232
|
end
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
def test_known_short_curl_options
|
236
236
|
KNOWN_SHORT_CURL_OPTIONS.each do |short_option|
|
237
237
|
curl = CurlWrapperFack.new
|
@@ -246,13 +246,13 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
def test_combinde_options
|
251
251
|
long_option = KNOWN_LONG_CURL_OPTIONS[30]
|
252
252
|
short_option = KNOWN_SHORT_CURL_OPTIONS[9]
|
253
|
-
|
253
|
+
|
254
254
|
curl = CurlWrapperFack.new
|
255
|
-
|
255
|
+
|
256
256
|
if short_option[:param].nil?
|
257
257
|
curl.send short_option[:method]
|
258
258
|
expected_short = "#{short_option[:option]}"
|
@@ -260,7 +260,7 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
260
260
|
curl.send short_option[:method], short_option[:param]
|
261
261
|
expected_short = "#{short_option[:option]} '#{short_option[:param]}'"
|
262
262
|
end
|
263
|
-
|
263
|
+
|
264
264
|
if long_option[:param].nil?
|
265
265
|
curl.send long_option[:method]
|
266
266
|
expected_long = "#{long_option[:option]}"
|
@@ -269,11 +269,11 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
269
269
|
expected_long = "#{long_option[:option]} '#{long_option[:param]}'"
|
270
270
|
end
|
271
271
|
expected = [expected_short, expected_long].join(' ')
|
272
|
-
|
272
|
+
|
273
273
|
assert_equal expected, curl.options, "Should have worked for #{expected} => '#{short_option[:description]}' and '#{long_option[:description]}'"
|
274
274
|
end
|
275
|
-
|
276
|
-
|
275
|
+
|
276
|
+
|
277
277
|
def test_known_long_curl_options_returns_self
|
278
278
|
KNOWN_LONG_CURL_OPTIONS.each do |long_option|
|
279
279
|
actual_return_value = nil
|
@@ -283,11 +283,11 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
283
283
|
else
|
284
284
|
actual_return_value = curl.send long_option[:method], long_option[:param]
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
assert_equal curl, actual_return_value, "Should be returning self to enable changing."
|
288
288
|
end
|
289
289
|
end
|
290
|
-
|
290
|
+
|
291
291
|
def test_known_short_curl_options_returns_self
|
292
292
|
KNOWN_SHORT_CURL_OPTIONS.each do |short_option|
|
293
293
|
actual_return_value = nil
|
@@ -297,10 +297,10 @@ class CurlWrapperTest < MiniTest::Unit::TestCase
|
|
297
297
|
else
|
298
298
|
actual_return_value = curl.send short_option[:method], short_option[:param]
|
299
299
|
end
|
300
|
-
|
300
|
+
|
301
301
|
assert_equal curl, actual_return_value, "Should be returning self to enable changing."
|
302
302
|
end
|
303
303
|
end
|
304
|
-
|
304
|
+
|
305
305
|
end
|
306
|
-
end
|
306
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curl_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: Makes it easy to take you curl hacking from bash to ruby
|
26
31
|
email:
|
27
32
|
- agirorn@gmail.com
|
@@ -56,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
61
|
version: '0'
|
57
62
|
requirements: []
|
58
63
|
rubyforge_project: curl_wrapper
|
59
|
-
rubygems_version: 1.8.
|
64
|
+
rubygems_version: 1.8.24
|
60
65
|
signing_key:
|
61
66
|
specification_version: 3
|
62
67
|
summary: DSL wraper for the curl command.
|