curl_wrapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ ## 0.0.0 Nothing
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2012 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ require 'curl_wrapper/version'
2
+ require 'curl_wrapper/config_options'
3
+ require 'open3'
4
+
5
+ class CurlWrapper
6
+ include CurlWrapper::ConfigOptions
7
+
8
+ class << self
9
+ def method_missing(method, *args, &block)
10
+ new.send(method, *args, &block)
11
+ end
12
+ end
13
+ def initialize(&block)
14
+ yield self if block_given?
15
+ end
16
+
17
+ def command
18
+ ['curl', options].join(' ')
19
+ end
20
+
21
+ def run
22
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(command)
23
+ end
24
+
25
+ def out
26
+ run if @stdout.nil?
27
+ @stdout.collect(&:to_s).join('')
28
+ end
29
+ alias :body :out
30
+ alias :to_s :out
31
+
32
+ def err
33
+ run if @stdout.nil?
34
+ @stderr.collect(&:to_s).join('')
35
+ end
36
+
37
+ def to_ary
38
+ [to_s]
39
+ end
40
+ end
41
+
@@ -0,0 +1,48 @@
1
+ require 'pp'
2
+ class CurlWrapper
3
+ module ConfigOptions
4
+ def method_missing(method, *args, &block)
5
+ method = method.to_s
6
+ if method.length == 1
7
+ option = "-#{method}"
8
+ else
9
+ option = "--#{method.gsub('_', '-')}"
10
+ end
11
+ append_option option, args.first
12
+ end
13
+
14
+ def options
15
+ @options
16
+ end
17
+
18
+ def append_option option, value = nil
19
+ option = "#{option} '#{value}'" unless value.nil?
20
+ if @options.nil?
21
+ @options = option
22
+ else
23
+ @options = "#{@options} #{option}"
24
+ end
25
+ self
26
+ end
27
+
28
+ def fail
29
+ append_option '--fail'
30
+ end
31
+
32
+ def http1_0
33
+ append_option '--http1.0'
34
+ end
35
+
36
+ def proxy1_0 value
37
+ append_option '--proxy1.0', value
38
+ end
39
+
40
+ def p
41
+ append_option '-p'
42
+ end
43
+
44
+ def verbose
45
+ append_option '--verbose'
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ class CurlWrapper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,115 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'curl_wrapper'
4
+
5
+ class CurlWrapperTest < MiniTest::Unit::TestCase
6
+
7
+ def test_curl_basic
8
+ curl = CurlWrapper.new
9
+ assert_equal 'curl ', curl.command
10
+ end
11
+
12
+ def test_curl_with_block
13
+ curl = CurlWrapper.new do |config|
14
+
15
+ end
16
+ assert_equal 'curl ', curl.command
17
+ end
18
+
19
+ def test_collin_curl
20
+ curl_result = `curl 2>/dev/null`
21
+ curl = CurlWrapper.new
22
+ curl.run
23
+ assert_equal curl_result, curl.out, ":out should return culr help message #{curl_result}"
24
+ end
25
+
26
+ def test_collin_curl
27
+ curl_result = `curl 2>&1`
28
+ curl = CurlWrapper.new
29
+ curl.run
30
+ assert_equal curl_result, curl.err, ":err should return culr help message #{curl_result}"
31
+ end
32
+
33
+ def test_command_after_help_option
34
+ expected_command = 'curl --help'
35
+ curl = CurlWrapper.new
36
+ curl.help
37
+
38
+ assert_equal expected_command, curl.command, ":command should be #{expected_command}"
39
+ end
40
+
41
+ def test_called_with_help_option
42
+ expected_out = `curl --help`
43
+ curl = CurlWrapper.new
44
+ curl.help
45
+ curl.run
46
+
47
+ assert_equal expected_out, curl.out, ":out should return the help screen"
48
+ end
49
+
50
+ def test_excepts_config_in_a_block
51
+ expected_out = `curl --help`
52
+ curl = CurlWrapper.new do |config|
53
+ config.help
54
+ end
55
+ curl.run
56
+
57
+ assert_equal expected_out, curl.out, ":out should return the help screen"
58
+ end
59
+
60
+ def test_autoruns_on_calling_out
61
+ expected_out = `curl --help`
62
+ curl = CurlWrapper.new do |config|
63
+ config.help
64
+ end
65
+
66
+ assert_equal expected_out, curl.out, ":out should return the help screen"
67
+ end
68
+
69
+ def test_autoruns_on_calling_err
70
+ expected_out = ''
71
+ curl = CurlWrapper.new do |config|
72
+ config.help
73
+ end
74
+
75
+ assert_equal expected_out, curl.err, ":out should return the help screen"
76
+ end
77
+
78
+ def test_options_should_return_self
79
+ expected_out = `curl --help`
80
+ curl = CurlWrapper.new
81
+ assert_equal curl, curl.help, "Should be returning it self"
82
+ end
83
+
84
+ def test_is_chanable
85
+ expected_out = `curl --help`
86
+ assert_equal expected_out, CurlWrapper.new.help.out, "Should be returning it self"
87
+ end
88
+
89
+ def test_get_new_out_of_the_way
90
+ expected_out = `curl --help`
91
+ assert_equal expected_out, CurlWrapper.help.out, "Should be returning it self"
92
+ end
93
+
94
+ def test_body_should_be_aliast_to_out
95
+ expected_out = `curl --help`
96
+ assert_equal expected_out, CurlWrapper.help.body, "Should be returning it self"
97
+ end
98
+
99
+ def test_to_s_should_be_aliast_to_out
100
+ expected_out = `curl --help`
101
+ assert_equal expected_out, CurlWrapper.help.to_s, "Should be returning it self"
102
+ end
103
+
104
+ def test_skiping_out_should_just_work
105
+ expected_out = `curl --help`
106
+ assert_equal expected_out, "#{CurlWrapper.help}", "Should be returning it self"
107
+ end
108
+
109
+ def test_should_convert_to_array_to_work_with_puts
110
+ expected_out = `curl --help`
111
+ assert_equal expected_out, CurlWrapper.help.to_ary.first, "Should be returning it self"
112
+ end
113
+
114
+
115
+ end
@@ -0,0 +1,306 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'curl_wrapper/config_options'
4
+
5
+ class CurlWrapperTest < MiniTest::Unit::TestCase
6
+ class ConfigOptionsTest < MiniTest::Unit::TestCase
7
+ KNOWN_LONG_CURL_OPTIONS = [
8
+ { :method => :anyauth, :option => '--anyauth', :description => %q[Pick "any" authentication method (H)] },
9
+ { :method => :append, :option => '--append', :description => %q[Append to target file when uploading (F/SFTP)] },
10
+ { :method => :basic, :option => '--basic', :description => %q[Use HTTP Basic Authentication (H)] },
11
+ { :method => :cacert, :option => '--cacert', :param => 'FILE', :description => %q[CA certificate to verify peer against (SSL)] },
12
+ { :method => :capath, :option => '--capath', :param => 'DIR', :description => %q[CA directory to verify peer against (SSL)] },
13
+ { :method => :cert, :option => '--cert', :param => 'CERT[:PASSWD]', :description => %q[Client certificate file and password (SSL)] },
14
+ { :method => :cert_type, :option => '--cert-type', :param => 'TYPE', :description => %q[Certificate file type (DER/PEM/ENG) (SSL)] },
15
+ { :method => :ciphers, :option => '--ciphers', :param => 'LIST', :description => %q[SSL ciphers to use (SSL)] },
16
+ { :method => :compressed, :option => '--compressed', :description => %q[Request compressed response (using deflate or gzip)] },
17
+ { :method => :config, :option => '--config', :param => 'FILE', :description => %q[Specify which config file to read] },
18
+ { :method => :connect_timeout, :option => '--connect-timeout', :param => 'SECONDS', :description => %q[Maximum time allowed for connection] },
19
+ { :method => :continue_at, :option => '--continue-at', :param => 'OFFSET', :description => %q[Resumed transfer offset] },
20
+ { :method => :cookie, :option => '--cookie', :param => 'STRING/FILE', :description => %q[String or file to read cookies from (H)] },
21
+ { :method => :cookie_jar, :option => '--cookie-jar', :param => 'FILE', :description => %q[Write cookies to this file after operation (H)] },
22
+ { :method => :create_dirs, :option => '--create-dirs', :description => %q[Create necessary local directory hierarchy] },
23
+ { :method => :crlf, :option => '--crlf', :description => %q[Convert LF to CRLF in upload] },
24
+ { :method => :crlfile, :option => '--crlfile', :param => 'FILE', :description => %q[Get a CRL list in PEM format from the given file] },
25
+ { :method => :data, :option => '--data', :param => 'DATA', :description => %q[HTTP POST data (H)] },
26
+ { :method => :data_ascii, :option => '--data-ascii', :param => 'DATA', :description => %q[HTTP POST ASCII data (H)] },
27
+ { :method => :data_binary, :option => '--data-binary', :param => 'DATA', :description => %q[HTTP POST binary data (H)] },
28
+ { :method => :data_urlencode, :option => '--data-urlencode', :param => 'DATA', :description => %q[HTTP POST data url encoded (H)] },
29
+ { :method => :delegation, :option => '--delegation', :param => 'STRING', :description => %q[GSS-API delegation permission] },
30
+ { :method => :digest, :option => '--digest', :description => %q[Use HTTP Digest Authentication (H)] },
31
+ { :method => :disable_eprt, :option => '--disable-eprt', :description => %q[Inhibit using EPRT or LPRT (F)] },
32
+ { :method => :disable_epsv, :option => '--disable-epsv', :description => %q[Inhibit using EPSV (F)] },
33
+ { :method => :dump_header, :option => '--dump-header', :param => 'FILE', :description => %q[Write the headers to this file] },
34
+ { :method => :egd_file, :option => '--egd-file', :param => 'FILE', :description => %q[EGD socket path for random data (SSL)] },
35
+ { :method => :engine, :option => '--engine', :param => 'ENGINGE', :description => %q[Crypto engine (SSL). "--engine list" for list] },
36
+ { :method => :fail, :option => '--fail', :description => %q[Fail silently (no output at all) on HTTP errors (H)] },
37
+ { :method => :form, :option => '--form', :param => 'CONTENT', :description => %q[Specify HTTP multipart POST data (H)] },
38
+ { :method => :form_string, :option => '--form-string', :param => 'STRING', :description => %q[Specify HTTP multipart POST data (H)] },
39
+ { :method => :ftp_account, :option => '--ftp-account', :param => 'DATA', :description => %q[Account data string (F)] },
40
+ { :method => :ftp_alternative_to_user, :option => '--ftp-alternative-to-user', :param => 'COMMAND', :description => %q[String to replace "USER [name]" (F)] },
41
+ { :method => :ftp_create_dirs, :option => '--ftp-create-dirs', :description => %q[Create the remote dirs if not present (F)] },
42
+ { :method => :ftp_method, :option => '--ftp-method', :param => '[MULTICWD/NOCWD/SINGLECWD]', :description => %q[Control CWD usage (F)] },
43
+ { :method => :ftp_pasv, :option => '--ftp-pasv', :description => %q[Use PASV/EPSV instead of PORT (F)] },
44
+ { :method => :ftp_port, :option => '--ftp-port', :param => 'ADR', :description => %q[Use PORT with given address instead of PASV (F)] },
45
+ { :method => :ftp_skip_pasv_ip, :option => '--ftp-skip-pasv-ip', :description => %q[Skip the IP address for PASV (F)] },
46
+ { :method => :ftp_pret, :option => '--ftp-pret', :description => %q[Send PRET before PASV (for drftpd) (F)] },
47
+ { :method => :ftp_ssl_ccc, :option => '--ftp-ssl-ccc', :description => %q[Send CCC after authenticating (F)] },
48
+ { :method => :ftp_ssl_ccc_mode, :option => '--ftp-ssl-ccc-mode', :param => 'ACTIVE/PASSIVE', :description => %q[Set CCC mode (F)] },
49
+ { :method => :ftp_ssl_control, :option => '--ftp-ssl-control', :description => %q[Require SSL/TLS for ftp login, clear for transfer (F)] },
50
+ { :method => :get, :option => '--get', :description => %q[Send the -d data with a HTTP GET (H)] },
51
+ { :method => :globoff, :option => '--globoff', :description => %q[Disable URL sequences and ranges using {} and []] },
52
+ { :method => :header, :option => '--header', :param => 'LINE', :description => %q[Custom header to pass to server (H)] },
53
+ { :method => :head, :option => '--head', :description => %q[Show document info only] },
54
+ { :method => :help, :option => '--help', :description => %q[This help text] },
55
+ { :method => :hostpubmd5, :option => '--hostpubmd5', :param => 'MD5', :description => %q[Hex encoded MD5 string of the host public key. (SSH)] },
56
+ { :method => :http1_0, :option => '--http1.0', :description => %q[Use HTTP 1.0 (H)] },
57
+ { :method => :ignore_content_length, :option => '--ignore-content-length', :description => %q[Ignore the HTTP Content-Length header] },
58
+ { :method => :include, :option => '--include', :description => %q[Include protocol headers in the output (H/F)] },
59
+ { :method => :insecure, :option => '--insecure', :description => %q[Allow connections to SSL sites without certs (H)] },
60
+ { :method => :interface, :option => '--interface', :param => 'INTERFACE', :description => %q[Specify network interface/address to use] },
61
+ { :method => :ipv4, :option => '--ipv4', :description => %q[Resolve name to IPv4 address] },
62
+ { :method => :ipv6, :option => '--ipv6', :description => %q[Resolve name to IPv6 address] },
63
+ { :method => :junk_session_cookies, :option => '--junk-session-cookies', :description => %q[Ignore session cookies read from file (H)] },
64
+ { :method => :keepalive_time, :option => '--keepalive-time', :param => 'SECONDS', :description => %q[Interval between keepalive probes] },
65
+ { :method => :key, :option => '--key', :param => 'KEY', :description => %q[Private key file name (SSL/SSH)] },
66
+ { :method => :key_type, :option => '--key-type', :param => 'TYPE', :description => %q[Private key file type (DER/PEM/ENG) (SSL)] },
67
+ { :method => :krb, :option => '--krb', :param => 'LEVEL', :description => %q[Enable Kerberos with specified security level (F)] },
68
+ { :method => :libcurl, :option => '--libcurl', :param => 'FILE', :description => %q[Dump libcurl equivalent code of this command line] },
69
+ { :method => :limit_rate, :option => '--limit-rate', :param => 'RATE', :description => %q[Limit transfer speed to this rate] },
70
+ { :method => :list_only, :option => '--list-only', :description => %q[List only names of an FTP directory (F)] },
71
+ { :method => :local_port, :option => '--local-port', :param => 'RANGE', :description => %q[Force use of these local port numbers] },
72
+ { :method => :location, :option => '--location', :description => %q[Follow redirects (H)] },
73
+ { :method => :location_trusted, :option => '--location-trusted', :description => %q[like --location and send auth to other hosts (H)] },
74
+ { :method => :manual, :option => '--manual', :description => %q[Display the full manual] },
75
+ { :method => :mail_from, :option => '--mail-from', :param => 'FROM', :description => %q[Mail from this address] },
76
+ { :method => :mail_rcpt, :option => '--mail-rcpt', :param => 'TO', :description => %q[Mail to this receiver(s)] },
77
+ { :method => :max_filesize, :option => '--max-filesize', :param => 'BYTES', :description => %q[Maximum file size to download (H/F)] },
78
+ { :method => :max_redirs, :option => '--max-redirs', :param => 'NUM', :description => %q[Maximum number of redirects allowed (H)] },
79
+ { :method => :max_time, :option => '--max-time', :param => 'SECONDS', :description => %q[Maximum time allowed for the transfer] },
80
+ { :method => :negotiate, :option => '--negotiate', :description => %q[Use HTTP Negotiate Authentication (H)] },
81
+ { :method => :netrc, :option => '--netrc', :description => %q[Must read .netrc for user name and password] },
82
+ { :method => :netrc_optional, :option => '--netrc-optional', :description => %q[Use either .netrc or URL; overrides -n] },
83
+ { :method => :netrc_file, :option => '--netrc-file', :param => 'FILE', :description => %q[Set up the netrc filename to use] },
84
+ { :method => :no_buffer, :option => '--no-buffer', :description => %q[Disable buffering of the output stream] },
85
+ { :method => :no_keepalive, :option => '--no-keepalive', :description => %q[Disable keepalive use on the connection] },
86
+ { :method => :no_sessionid, :option => '--no-sessionid', :description => %q[Disable SSL session-ID reusing (SSL)] },
87
+ { :method => :noproxy, :option => '--noproxy', :description => %q[List of hosts which do not use proxy] },
88
+ { :method => :ntlm, :option => '--ntlm', :description => %q[Use HTTP NTLM authentication (H)] },
89
+ { :method => :output, :option => '--output', :param => 'FILE', :description => %q[Write output to <file> instead of stdout] },
90
+ { :method => :pass, :option => '--pass', :param => 'PASS', :description => %q[Pass phrase for the private key (SSL/SSH)] },
91
+ { :method => :post301, :option => '--post301', :description => %q[Do not switch to GET after following a 301 redirect (H)] },
92
+ { :method => :post302, :option => '--post302', :description => %q[Do not switch to GET after following a 302 redirect (H)] },
93
+ { :method => :progress_bar, :option => '--progress-bar', :description => %q[Display transfer progress as a progress bar] },
94
+ { :method => :proto, :option => '--proto', :param => 'PROTOCOLS', :description => %q[Enable/disable specified protocols] },
95
+ { :method => :proto_redir, :option => '--proto-redir', :param => 'PROTOCOLS', :description => %q[Enable/disable specified protocols on redirect] },
96
+ { :method => :proxy, :option => '--proxy', :param => '[PROTOCOL://]HOST[:PORT]', :description => %q[Use proxy on given port] },
97
+ { :method => :proxy_anyauth, :option => '--proxy-anyauth', :description => %q[Pick "any" proxy authentication method (H)] },
98
+ { :method => :proxy_basic, :option => '--proxy-basic', :description => %q[Use Basic authentication on the proxy (H)] },
99
+ { :method => :proxy_digest, :option => '--proxy-digest', :description => %q[Use Digest authentication on the proxy (H)] },
100
+ { :method => :proxy_negotiate, :option => '--proxy-negotiate', :description => %q[Use Negotiate authentication on the proxy (H)] },
101
+ { :method => :proxy_ntlm, :option => '--proxy-ntlm', :description => %q[Use NTLM authentication on the proxy (H)] },
102
+ { :method => :proxy_user, :option => '--proxy-user', :param => 'USER[:PASSWORD]', :description => %q[Proxy user and password] },
103
+ { :method => :proxy1_0, :option => '--proxy1.0', :param => 'HOST[:PORT]', :description => %q[Use HTTP/1.0 proxy on given port] },
104
+ { :method => :proxytunnel, :option => '--proxytunnel', :description => %q[Operate through a HTTP proxy tunnel (using CONNECT)] },
105
+ { :method => :pubkey, :option => '--pubkey', :param => 'KEY', :description => %q[Public key file name (SSH)] },
106
+ { :method => :quote, :option => '--quote', :param => 'CMD', :description => %q[Send command(s) to server before transfer (F/SFTP)] },
107
+ { :method => :random_file, :option => '--random-file', :param => 'FILE', :description => %q[File for reading random data from (SSL)] },
108
+ { :method => :range, :option => '--range', :param => 'RANGE', :description => %q[Retrieve only the bytes within a range] },
109
+ { :method => :raw, :option => '--raw', :description => %q[Do HTTP "raw", without any transfer decoding (H)] },
110
+ { :method => :referer, :option => '--referer', :description => %q[Referer URL (H)] },
111
+ { :method => :remote_header_name, :option => '--remote-header-name', :description => %q[Use the header-provided filename (H)] },
112
+ { :method => :remote_name, :option => '--remote-name', :description => %q[Write output to a file named as the remote file] },
113
+ { :method => :remote_name_all, :option => '--remote-name-all', :description => %q[Use the remote file name for all URLs] },
114
+ { :method => :remote_time, :option => '--remote-time', :description => %q[Set the remote file's time on the local output] },
115
+ { :method => :request, :option => '--request', :param => 'COMMAND', :description => %q[Specify request command to use] },
116
+ { :method => :resolve, :option => '--resolve', :param => 'HOST:PORT:ADDRESS', :description => %q[Force resolve of HOST:PORT to ADDRESS] },
117
+ { :method => :retry, :option => '--retry', :param => 'NUM', :description => %q[Retry request NUM times if transient problems occur] },
118
+ { :method => :retry_delay, :option => '--retry-delay', :param => 'SECONDS', :description => %q[When retrying, wait this many seconds between each] },
119
+ { :method => :retry_max_time, :option => '--retry-max-time', :param => 'SECONDS', :description => %q[Retry only within this period] },
120
+ { :method => :show_error, :option => '--show-error', :description => %q[Show error. With -s, make curl show errors when they occur] },
121
+ { :method => :silent, :option => '--silent', :description => %q[Silent mode. Don't output anything] },
122
+ { :method => :socks4, :option => '--socks4', :param => 'HOST[:PORT]', :description => %q[SOCKS4 proxy on given host + port] },
123
+ { :method => :socks4a, :option => '--socks4a', :param => 'HOST[:PORT]', :description => %q[SOCKS4a proxy on given host + port] },
124
+ { :method => :socks5, :option => '--socks5', :param => 'HOST[:PORT]', :description => %q[SOCKS5 proxy on given host + port] },
125
+ { :method => :socks5_hostname, :option => '--socks5-hostname', :param => 'HOST[:PORT]', :description => %q[SOCKS5 proxy, pass host name to proxy] },
126
+ { :method => :speed_limit, :option => '--speed-limit', :param => 'RATE', :description => %q[Stop transfers below speed-limit for 'speed-time' secs] },
127
+ { :method => :speed_time, :option => '--speed-time', :param => 'SECONDS', :description => %q[Time for trig speed-limit abort. Defaults to 30] },
128
+ { :method => :ssl, :option => '--ssl', :description => %q[Try SSL/TLS (FTP, IMAP, POP3, SMTP)] },
129
+ { :method => :ssl_reqd, :option => '--ssl-reqd', :description => %q[Require SSL/TLS (FTP, IMAP, POP3, SMTP)] },
130
+ { :method => :sslv2, :option => '--sslv2', :description => %q[Use SSLv2 (SSL)] },
131
+ { :method => :sslv3, :option => '--sslv3', :description => %q[Use SSLv3 (SSL)] },
132
+ { :method => :stderr, :option => '--stderr', :param => 'FILE', :description => %q[Where to redirect stderr. - means stdout] },
133
+ { :method => :tcp_nodelay, :option => '--tcp-nodelay', :description => %q[Use the TCP_NODELAY option] },
134
+ { :method => :telnet_option, :option => '--telnet-option', :param => 'OPT=VAL', :description => %q[Set telnet option] },
135
+ { :method => :tftp_blksize, :option => '--tftp-blksize', :param => 'VALUE', :description => %q[Set TFTP BLKSIZE option (must be >512)] },
136
+ { :method => :time_cond, :option => '--time-cond', :param => 'TIME', :description => %q[Transfer based on a time condition] },
137
+ { :method => :tlsv1, :option => '--tlsv1', :description => %q[Use TLSv1 (SSL)] },
138
+ { :method => :trace, :option => '--trace', :param => 'FILE', :description => %q[Write a debug trace to the given file] },
139
+ { :method => :trace_ascii, :option => '--trace-ascii', :param => 'FILE', :description => %q[Like --trace but without the hex output] },
140
+ { :method => :trace_time, :option => '--trace-time', :description => %q[Add time stamps to trace/verbose output] },
141
+ { :method => :tr_encoding, :option => '--tr-encoding', :description => %q[Request compressed transfer encoding (H)] },
142
+ { :method => :upload_file, :option => '--upload-file', :param => 'FILE', :description => %q[Transfer FILE to destination] },
143
+ { :method => :url, :option => '--url', :param => 'URL', :description => %q[URL to work with] },
144
+ { :method => :use_ascii, :option => '--use-ascii', :description => %q[Use ASCII/text transfer] },
145
+ { :method => :user, :option => '--user', :param => 'USER[:PASSWORD]', :description => %q[Server user and password] },
146
+ { :method => :tlsuser, :option => '--tlsuser', :param => 'USER', :description => %q[TLS username] },
147
+ { :method => :tlspassword, :option => '--tlspassword', :param => 'STRING', :description => %q[TLS password] },
148
+ { :method => :tlsauthtype, :option => '--tlsauthtype', :param => 'STRING', :description => %q[TLS authentication type (default SRP)] },
149
+ { :method => :user_agent, :option => '--user-agent', :param => 'STRING', :description => %q[User-Agent to send to server (H)] },
150
+ { :method => :verbose, :option => '--verbose', :description => %q[Make the operation more talkative] },
151
+ { :method => :version, :option => '--version', :description => %q[Show version number and quit] },
152
+ { :method => :write_out, :option => '--write-out', :param => 'FORMAT', :description => %q[What to output after completion] },
153
+ { :method => :xattr, :option => '--xattr', :description => %q[Store metadata in extended file attributes] },
154
+ ]
155
+
156
+ KNOWN_SHORT_CURL_OPTIONS = [
157
+ { :method => :a, :option => '-a', :description => %q[Append to target file when uploading (F/SFTP)] },
158
+ { :method => :E, :option => '-E', :param => 'CERT[:PASSWD]', :description => %q[Client certificate file and password (SSL)] },
159
+ { :method => :K, :option => '-K', :param => 'FILE', :description => %q[Specify which config file to read] },
160
+ { :method => :C, :option => '-C', :param => 'OFFSET', :description => %q[Resumed transfer offset] },
161
+ { :method => :b, :option => '-b', :param => 'STRING/FILE', :description => %q[String or file to read cookies from (H)] },
162
+ { :method => :c, :option => '-c', :param => 'FILE', :description => %q[Write cookies to this file after operation (H)] },
163
+ { :method => :d, :option => '-d', :param => 'DATA', :description => %q[HTTP POST data (H)] },
164
+ { :method => :D, :option => '-D', :param => 'FILE', :description => %q[Write the headers to this file] },
165
+ { :method => :f, :option => '-f', :description => %q[Fail silently (no output at all) on HTTP errors (H)] },
166
+ { :method => :F, :option => '-F', :param => 'CONTENT', :description => %q[Specify HTTP multipart POST data (H)] },
167
+ { :method => :P, :option => '-P', :param => 'ADR', :description => %q[Use PORT with given address instead of PASV (F)] },
168
+ { :method => :G, :option => '-G', :description => %q[Send the -d data with a HTTP GET (H)] },
169
+ { :method => :g, :option => '-g', :description => %q[Disable URL sequences and ranges using {} and []] },
170
+ { :method => :H, :option => '-H', :param => 'LINE', :description => %q[Custom header to pass to server (H)] },
171
+ { :method => :I, :option => '-I', :description => %q[Show document info only] },
172
+ { :method => :h, :option => '-h', :description => %q[This help text] },
173
+ { :method => :'0', :option => '-0', :description => %q[Use HTTP 1.0 (H)] },
174
+ { :method => :i, :option => '-i', :description => %q[Include protocol headers in the output (H/F)] },
175
+ { :method => :k, :option => '-k', :description => %q[Allow connections to SSL sites without certs (H)] },
176
+ { :method => :'4', :option => '-4', :description => %q[Resolve name to IPv4 address] },
177
+ { :method => :'6', :option => '-6', :description => %q[Resolve name to IPv6 address] },
178
+ { :method => :j, :option => '-j', :description => %q[Ignore session cookies read from file (H)] },
179
+ { :method => :l, :option => '-l', :description => %q[List only names of an FTP directory (F)] },
180
+ { :method => :L, :option => '-L', :description => %q[Follow redirects (H)] },
181
+ { :method => :M, :option => '-M', :description => %q[Display the full manual] },
182
+ { :method => :m, :option => '-m', :param => 'SECONDS', :description => %q[Maximum time allowed for the transfer] },
183
+ { :method => :n, :option => '-n', :description => %q[Must read .netrc for user name and password] },
184
+ { :method => :N, :option => '-N', :description => %q[Disable buffering of the output stream] },
185
+ { :method => :o, :option => '-o', :param => 'FILE', :description => %q[Write output to <file> instead of stdout] },
186
+ { :method => :'#', :option => '-#', :description => %q[Display transfer progress as a progress bar] },
187
+ { :method => :x, :option => '-x', :param => '[PROTOCOL://]HOST[:PORT]', :description => %q[Use proxy on given port] },
188
+ { :method => :U, :option => '-U', :param => 'USER[:PASSWORD]', :description => %q[Proxy user and password] },
189
+ { :method => :p, :option => '-p', :description => %q[Operate through a HTTP proxy tunnel (using CONNECT)] },
190
+ { :method => :Q, :option => '-Q', :param => 'CMD', :description => %q[Send command(s) to server before transfer (F/SFTP)] },
191
+ { :method => :r, :option => '-r', :param => 'RANGE', :description => %q[Retrieve only the bytes within a range] },
192
+ { :method => :e, :option => '-e', :description => %q[Referer URL (H)] },
193
+ { :method => :J, :option => '-J', :description => %q[Use the header-provided filename (H)] },
194
+ { :method => :O, :option => '-O', :description => %q[Write output to a file named as the remote file] },
195
+ { :method => :R, :option => '-R', :description => %q[Set the remote file's time on the local output] },
196
+ { :method => :X, :option => '-X', :param => 'COMMAND', :description => %q[Specify request command to use] },
197
+ { :method => :S, :option => '-S', :description => %q[Show error. With -s, make curl show errors when they occur] },
198
+ { :method => :s, :option => '-s', :description => %q[Silent mode. Don't output anything] },
199
+ { :method => :Y, :option => '-Y', :param => 'RATE', :description => %q[Stop transfers below speed-limit for 'speed-time' secs] },
200
+ { :method => :y, :option => '-y', :param => 'SECONDS', :description => %q[Time for trig speed-limit abort. Defaults to 30] },
201
+ { :method => :'2', :option => '-2', :description => %q[Use SSLv2 (SSL)] },
202
+ { :method => :'3', :option => '-3', :description => %q[Use SSLv3 (SSL)] },
203
+ { :method => :t, :option => '-t', :param => 'OPT=VAL', :description => %q[Set telnet option] },
204
+ { :method => :z, :option => '-z', :param => 'TIME', :description => %q[Transfer based on a time condition] },
205
+ { :method => :'1', :option => '-1', :description => %q[Use TLSv1 (SSL)] },
206
+ { :method => :T, :option => '-T', :param => 'FILE', :description => %q[Transfer FILE to destination] },
207
+ { :method => :B, :option => '-B', :description => %q[Use ASCII/text transfer] },
208
+ { :method => :u, :option => '-u', :param => 'USER[:PASSWORD]', :description => %q[Server user and password] },
209
+ { :method => :A, :option => '-A', :param => 'STRING', :description => %q[User-Agent to send to server (H)] },
210
+ { :method => :v, :option => '-v', :description => %q[Make the operation more talkative] },
211
+ { :method => :V, :option => '-V', :description => %q[Show version number and quit] },
212
+ { :method => :w, :option => '-w', :param => 'FORMAT', :description => %q[What to output after completion] },
213
+ { :method => :q, :option => '-q', :description => %q[If used as the first parameter disables .curlrc] },
214
+ ]
215
+
216
+ class CurlWrapperFack
217
+ include CurlWrapper::ConfigOptions
218
+ end
219
+
220
+ def test_known_long_curl_options
221
+ KNOWN_LONG_CURL_OPTIONS.each do |long_option|
222
+ curl = CurlWrapperFack.new
223
+ if long_option[:param].nil?
224
+ curl.send long_option[:method]
225
+ expected = "#{long_option[:option]}"
226
+ assert_equal expected, curl.options, "Should have worked for #{expected} => '#{long_option[:description]}'"
227
+ else
228
+ curl.send long_option[:method], long_option[:param]
229
+ expected = "#{long_option[:option]} '#{long_option[:param]}'"
230
+ assert_equal expected, curl.options, "Should have worked for #{expected} => '#{long_option[:description]}'"
231
+ end
232
+ end
233
+ end
234
+
235
+ def test_known_short_curl_options
236
+ KNOWN_SHORT_CURL_OPTIONS.each do |short_option|
237
+ curl = CurlWrapperFack.new
238
+ if short_option[:param].nil?
239
+ curl.send short_option[:method]
240
+ expected = "#{short_option[:option]}"
241
+ assert_equal expected, curl.options, "Should have worked for #{expected} => '#{short_option[:description]}'"
242
+ else
243
+ curl.send short_option[:method], short_option[:param]
244
+ expected = "#{short_option[:option]} '#{short_option[:param]}'"
245
+ assert_equal expected, curl.options, "Should have worked for #{expected} => '#{short_option[:description]}'"
246
+ end
247
+ end
248
+ end
249
+
250
+ def test_combinde_options
251
+ long_option = KNOWN_LONG_CURL_OPTIONS[30]
252
+ short_option = KNOWN_SHORT_CURL_OPTIONS[9]
253
+
254
+ curl = CurlWrapperFack.new
255
+
256
+ if short_option[:param].nil?
257
+ curl.send short_option[:method]
258
+ expected_short = "#{short_option[:option]}"
259
+ else
260
+ curl.send short_option[:method], short_option[:param]
261
+ expected_short = "#{short_option[:option]} '#{short_option[:param]}'"
262
+ end
263
+
264
+ if long_option[:param].nil?
265
+ curl.send long_option[:method]
266
+ expected_long = "#{long_option[:option]}"
267
+ else
268
+ curl.send long_option[:method], long_option[:param]
269
+ expected_long = "#{long_option[:option]} '#{long_option[:param]}'"
270
+ end
271
+ expected = [expected_short, expected_long].join(' ')
272
+
273
+ assert_equal expected, curl.options, "Should have worked for #{expected} => '#{short_option[:description]}' and '#{long_option[:description]}'"
274
+ end
275
+
276
+
277
+ def test_known_long_curl_options_returns_self
278
+ KNOWN_LONG_CURL_OPTIONS.each do |long_option|
279
+ actual_return_value = nil
280
+ curl = CurlWrapperFack.new
281
+ if long_option[:param].nil?
282
+ actual_return_value = curl.send long_option[:method]
283
+ else
284
+ actual_return_value = curl.send long_option[:method], long_option[:param]
285
+ end
286
+
287
+ assert_equal curl, actual_return_value, "Should be returning self to enable changing."
288
+ end
289
+ end
290
+
291
+ def test_known_short_curl_options_returns_self
292
+ KNOWN_SHORT_CURL_OPTIONS.each do |short_option|
293
+ actual_return_value = nil
294
+ curl = CurlWrapperFack.new
295
+ if short_option[:param].nil?
296
+ actual_return_value = curl.send short_option[:method]
297
+ else
298
+ actual_return_value = curl.send short_option[:method], short_option[:param]
299
+ end
300
+
301
+ assert_equal curl, actual_return_value, "Should be returning self to enable changing."
302
+ end
303
+ end
304
+
305
+ end
306
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: curl_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ægir Örn Símonarson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &2156158340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2156158340
25
+ description: Makes it easy to take you curl hacking from bash to ruby
26
+ email:
27
+ - agirorn@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - CHANGELOG.md
33
+ - MIT-LICENSE
34
+ - lib/curl_wrapper/config_options.rb
35
+ - lib/curl_wrapper/version.rb
36
+ - lib/curl_wrapper.rb
37
+ - test/units/curl_wrapper_test.rb
38
+ - test/units/curl_wrapper_test/config_options_test.rb
39
+ homepage: ''
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project: curl_wrapper
59
+ rubygems_version: 1.8.15
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: DSL wraper for the curl command.
63
+ test_files:
64
+ - test/units/curl_wrapper_test.rb
65
+ - test/units/curl_wrapper_test/config_options_test.rb