Module: Curl

Defined in:
lib/curl.rb,
lib/curl/easy.rb,
lib/curl/multi.rb,
ext/curb.c

Overview

expose shortcut methods

Defined Under Namespace

Modules: Err Classes: Easy, Multi, PostField, Upload

Constant Summary collapse

CURB_VERSION =
rb_str_new2(CURB_VERSION)
VERSION =
curlver
CURL_VERSION =
curlver
VERNUM =
curlvernum
CURL_VERNUM =
curlvernum
LONG_VERSION =
curllongver
CURL_LONG_VERSION =
curllongver
CURLINFO_TEXT =

Passed to on_debug handler to indicate that the data is informational text.

LONG2NUM(CURLINFO_TEXT)
CURLINFO_HEADER_IN =

Passed to on_debug handler to indicate that the data is header (or header-like) data received from the peer.

LONG2NUM(CURLINFO_HEADER_IN)
CURLINFO_HEADER_OUT =

Passed to on_debug handler to indicate that the data is header (or header-like) data sent to the peer.

LONG2NUM(CURLINFO_HEADER_OUT)
CURLINFO_DATA_IN =

Passed to on_debug handler to indicate that the data is protocol data received from the peer.

LONG2NUM(CURLINFO_DATA_IN)
CURLINFO_DATA_OUT =

Passed to on_debug handler to indicate that the data is protocol data sent to the peer.

LONG2NUM(CURLINFO_DATA_OUT)
CURL_MULTICWD =
LONG2NUM(CURLFTPMETHOD_MULTICWD)
CURL_NOCWD =
LONG2NUM(CURLFTPMETHOD_NOCWD)
CURL_SINGLECWD =
LONG2NUM(CURLFTPMETHOD_SINGLECWD)
CURLPROXY_HTTP =
LONG2NUM(-1)
CURL_SSLVERSION_DEFAULT =
LONG2NUM(-1)
CURL_SSLVERSION_MAX_DEFAULT =
LONG2NUM(CURL_SSLVERSION_MAX_DEFAULT)
CURL_SSLVERSION_TLSv1 =
LONG2NUM(-1)
CURL_SSLVERSION_SSLv2 =
LONG2NUM(-1)
CURL_SSLVERSION_SSLv3 =
LONG2NUM(-1)
CURL_SSLVERSION_TLSv1_0 =
LONG2NUM(-1)
CURL_SSLVERSION_MAX_TLSv1_0 =
LONG2NUM(-1)
CURL_SSLVERSION_TLSv1_1 =
LONG2NUM(-1)
CURL_SSLVERSION_MAX_TLSv1_1 =
LONG2NUM(-1)
CURL_SSLVERSION_TLSv1_2 =
LONG2NUM(-1)
CURL_SSLVERSION_MAX_TLSv1_2 =
LONG2NUM(-1)
CURL_SSLVERSION_TLSv1_3 =
LONG2NUM(-1)
CURL_SSLVERSION_MAX_TLSv1_3 =
LONG2NUM(-1)
CURL_USESSL_CONTROL =
LONG2NUM(-1)
CURL_USESSL_NONE =
LONG2NUM(-1)
CURL_USESSL_TRY =
LONG2NUM(-1)
CURL_USESSL_ALL =
LONG2NUM(-1)
CURLPROXY_SOCKS4 =
LONG2NUM(-2)
CURLPROXY_SOCKS4A =
LONG2NUM(-2)
CURLPROXY_SOCKS5 =
LONG2NUM(-2)
CURLPROXY_SOCKS5_HOSTNAME =
LONG2NUM(-2)
CURLAUTH_BASIC =
LONG2NUM(0)
CURLAUTH_DIGEST =
LONG2NUM(0)
CURLAUTH_GSSNEGOTIATE =
LONG2NUM(0)
CURLAUTH_NTLM =
LONG2NUM(0)
CURLAUTH_ANYSAFE =
LONG2NUM(0)
CURLAUTH_ANY =
LONG2NUM(0)
PIPE_NOTHING =
LONG2NUM(CURLPIPE_NOTHING)
PIPE_HTTP1 =
LONG2NUM(CURLPIPE_HTTP1)
PIPE_MULTIPLEX =
LONG2NUM(CURLPIPE_MULTIPLEX)
HTTP_2_0 =
LONG2NUM(CURL_HTTP_VERSION_2_0)
HTTP_1_1 =
LONG2NUM(CURL_HTTP_VERSION_1_1)
HTTP_1_0 =
LONG2NUM(CURL_HTTP_VERSION_1_0)
HTTP_NONE =
LONG2NUM(CURL_HTTP_VERSION_NONE)

Class Method Summary collapse

Class Method Details

.asyncdns?Boolean

Returns true if the installed libcurl was built with support for asynchronous name lookups, which allows more exact timeouts (even on Windows) and less blocking when using the multi interface. For libcurl versions < 7.10.7, always returns false.

Returns:

  • (Boolean)


128
129
130
131
132
133
134
135
# File 'ext/curb.c', line 128

static VALUE ruby_curl_asyncdns_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_ASYNCHDNS
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_ASYNCHDNS) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.conv?Boolean

Returns true if the installed libcurl was built with support for character conversions. For libcurl versions < 7.15.4, always returns false.

Returns:

  • (Boolean)


213
214
215
216
217
218
219
220
# File 'ext/curb.c', line 213

static VALUE ruby_curl_conv_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_CONV
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_CONV) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.debug?Boolean

Returns true if the installed libcurl was built with extra debug capabilities built-in. For libcurl versions < 7.10.6, always returns false.

Returns:

  • (Boolean)


110
111
112
113
114
115
116
117
# File 'ext/curb.c', line 110

static VALUE ruby_curl_debug_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_DEBUG
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_DEBUG) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.delete(url, params = {}, &block) ⇒ Object



42
43
44
# File 'lib/curl.rb', line 42

def self.delete(url, params={}, &block)
  http :DELETE, url, postalize(params), nil, &block
end

.get(url, params = {}, &block) ⇒ Object



30
31
32
# File 'lib/curl.rb', line 30

def self.get(url, params={}, &block)
  http :GET, urlalize(url, params), nil, nil, &block
end

.gssnegotiate?Boolean

Returns true if the installed libcurl supports HTTP GSS-Negotiate. For libcurl versions < 7.10.6, always returns false.

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
# File 'ext/curb.c', line 93

static VALUE ruby_curl_gssnegotiate_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_GSSNEGOTIATE
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_GSSNEGOTIATE) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.head(url, params = {}, &block) ⇒ Object



50
51
52
# File 'lib/curl.rb', line 50

def self.head(url, params={}, &block)
  http :HEAD, urlalize(url, params), nil, nil, &block
end

.http(verb, url, post_body = nil, put_data = nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/curl.rb', line 11

def self.http(verb, url, post_body=nil, put_data=nil, &block)
  if Thread.current[:curb_curl_yielding]
    handle = Curl::Easy.new # we can't reuse this
  else
    handle = Thread.current[:curb_curl] ||= Curl::Easy.new
    handle.reset
  end
  handle.url = url
  handle.post_body = post_body if post_body
  handle.put_data = put_data if put_data
  if block_given?
    Thread.current[:curb_curl_yielding] = true
    yield handle
    Thread.current[:curb_curl_yielding] = false
  end
  handle.http(verb)
  handle
end

.http2?Boolean

Returns true if the installed libcurl was built with support for HTTP2. For libcurl versions < 7.33.0, always returns false.

Returns:

  • (Boolean)


229
230
231
232
233
234
235
236
# File 'ext/curb.c', line 229

static VALUE ruby_curl_http2_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_HTTP2
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_HTTP2) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.idn?Boolean

Returns true if the installed libcurl was built with support for IDNA, domain names with international letters. For libcurl versions < 7.12.0, always returns false.

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
# File 'ext/curb.c', line 178

static VALUE ruby_curl_idn_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_IDN
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_IDN) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.ipv6?Boolean

Returns true if the installed libcurl supports IPv6.

Returns:

  • (Boolean)


21
22
23
24
# File 'ext/curb.c', line 21

static VALUE ruby_curl_ipv6_q(VALUE mod) {
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_IPV6) ? Qtrue : Qfalse);
}

.kerberos4?Boolean

Returns true if the installed libcurl supports Kerberos4 authentication with FTP connections.

Returns:

  • (Boolean)


33
34
35
36
# File 'ext/curb.c', line 33

static VALUE ruby_curl_kerberos4_q(VALUE mod) {
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_KERBEROS4) ? Qtrue : Qfalse);
}

.largefile?Boolean

Returns true if the installed libcurl was built with support for large files. For libcurl versions < 7.11.1, always returns false.

Returns:

  • (Boolean)


161
162
163
164
165
166
167
168
# File 'ext/curb.c', line 161

static VALUE ruby_curl_largefile_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_LARGEFILE
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_LARGEFILE) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.libz?Boolean

Returns true if the installed libcurl supports HTTP deflate using libz. For libcurl versions < 7.10, always returns false.

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
# File 'ext/curb.c', line 61

static VALUE ruby_curl_libz_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_LIBZ
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_LIBZ) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.ntlm?Boolean

Returns true if the installed libcurl supports HTTP NTLM. For libcurl versions < 7.10.6, always returns false.

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
# File 'ext/curb.c', line 77

static VALUE ruby_curl_ntlm_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_NTLM
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_NTLM) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.options(url, params = {}, &block) ⇒ Object



54
55
56
# File 'lib/curl.rb', line 54

def self.options(url, params={}, &block)
  http :OPTIONS, urlalize(url, params), nil, nil, &block
end

.patch(url, params = {}, &block) ⇒ Object



46
47
48
# File 'lib/curl.rb', line 46

def self.patch(url, params={}, &block)
  http :PATCH, url, postalize(params), nil, &block
end

.post(url, params = {}, &block) ⇒ Object



34
35
36
# File 'lib/curl.rb', line 34

def self.post(url, params={}, &block)
  http :POST, url, postalize(params), nil, &block
end

.postalize(params = {}) ⇒ Object



68
69
70
# File 'lib/curl.rb', line 68

def self.postalize(params={})
  params.respond_to?(:map) ? URI.encode_www_form(params) : (params.respond_to?(:to_s) ? params.to_s : params)
end

.put(url, params = {}, &block) ⇒ Object



38
39
40
# File 'lib/curl.rb', line 38

def self.put(url, params={}, &block)
  http :PUT, url, nil, postalize(params), &block
end

.resetObject



72
73
74
# File 'lib/curl.rb', line 72

def self.reset
  Thread.current[:curb_curl] = Curl::Easy.new
end

.spnego?Boolean

Returns true if the installed libcurl was built with support for SPNEGO authentication (Simple and Protected GSS-API Negotiation Mechanism, defined in RFC 2478). For libcurl versions < 7.10.8, always returns false.

Returns:

  • (Boolean)


145
146
147
148
149
150
151
152
# File 'ext/curb.c', line 145

static VALUE ruby_curl_spnego_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_SPNEGO
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_SPNEGO) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.ssl?Boolean

Returns true if the installed libcurl supports SSL connections. For libcurl versions < 7.10, always returns false.

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'ext/curb.c', line 45

static VALUE ruby_curl_ssl_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_SSL
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_SSL) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.sspi?Boolean

Returns true if the installed libcurl was built with support for SSPI. This is only available on Windows and makes libcurl use Windows-provided functions for NTLM authentication. It also allows libcurl to use the current user and the current user’s password without the app having to pass them on. For libcurl versions < 7.13.2, always returns false.

Returns:

  • (Boolean)


197
198
199
200
201
202
203
204
# File 'ext/curb.c', line 197

static VALUE ruby_curl_sspi_q(VALUE mod) {
#ifdef HAVE_CURL_VERSION_SSPI
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
  return((ver->features & CURL_VERSION_SSPI) ? Qtrue : Qfalse);
#else
  return Qfalse;
#endif
}

.urlalize(url, params = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/curl.rb', line 58

def self.urlalize(url, params={})
  uri = URI(url)
  # early return if we didn't specify any extra params
  return uri.to_s if (params || {}).empty?

  params_query = URI.encode_www_form(params || {})
  uri.query = [uri.query.to_s, params_query].reject(&:empty?).join('&')
  uri.to_s
end