Module: TinyClient::CurbRequestor

Defined in:
lib/tiny_client/curb_requestor.rb

Overview

Allows to perform request with Curb and wrapped the response. Curb client are attached to a current thread Fiber. ( One curb per Fiber. )

Class Method Summary collapse

Class Method Details

.perform_delete(url, headers, connect_timeout, verbose) ⇒ TinyClient::Response

Perform a delete request with Curl

Parameters:

  • url (String)

    the full url

  • headers (Hash)

    the request headers

  • connect_timeout (Integer)

    timeout if the request connection go over (in second)

  • verbose (Boolean)

    set curl verbose mode

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



53
54
55
56
# File 'lib/tiny_client/curb_requestor.rb', line 53

def perform_delete(url, headers, connect_timeout, verbose)
  perform(:DELETE, url, nil, nil, headers: headers, connect_timeout: connect_timeout,
                                  verbose: verbose)
end

.perform_get(url, headers, connect_timeout, verbose) ⇒ TinyClient::Response

Perform a get request with Curl

Parameters:

  • url (String)

    the full url

  • headers (Hash)

    the request headers

  • connect_timeout (Integer)

    timeout if the request connection go over (in second)

  • verbose (Boolean)

    set curl verbose mode

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



15
16
17
18
# File 'lib/tiny_client/curb_requestor.rb', line 15

def perform_get(url, headers, connect_timeout, verbose)
  perform(:GET, url, nil, nil, headers: headers, connect_timeout: connect_timeout,
                               verbose: verbose)
end

.perform_head(url, headers, connect_timeout, verbose) ⇒ TinyClient::Response

Perform a head request with Curl

Parameters:

  • url (String)

    the full url

  • headers (Hash)

    the request headers

  • connect_timeout (Integer)

    timeout if the request connection go over (in second)

  • verbose (Boolean)

    set curl verbose mode

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



65
66
67
68
# File 'lib/tiny_client/curb_requestor.rb', line 65

def perform_head(url, headers, connect_timeout, verbose)
  perform(:HEAD, url, nil, nil, headers: headers, connect_timeout: connect_timeout,
                                verbose: verbose)
end

.perform_post(url, headers, content, connect_timeout, verbose) ⇒ TinyClient::Response

Perform a post request with Curl

Parameters:

  • url (String)

    the full url

  • headers (Hash)

    the request headers

  • content (String)

    the request body content

  • connect_timeout (Integer)

    timeout if the request connection go over (in second)

  • verbose (Boolean)

    set curl verbose mode

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



41
42
43
44
# File 'lib/tiny_client/curb_requestor.rb', line 41

def perform_post(url, headers, content, connect_timeout, verbose)
  perform(:POST, url, content, nil, headers: headers, connect_timeout: connect_timeout,
                                    verbose: verbose)
end

.perform_put(url, headers, content, connect_timeout, verbose) ⇒ TinyClient::Response

Perform a put request with Curl

Parameters:

  • url (String)

    the full url

  • headers (Hash)

    the request headers

  • content (String)

    the request body content

  • connect_timeout (Integer)

    timeout if the request connection go over (in second)

  • verbose (Boolean)

    set curl verbose mode

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



28
29
30
31
# File 'lib/tiny_client/curb_requestor.rb', line 28

def perform_put(url, headers, content, connect_timeout, verbose)
  perform(:PUT, url, nil, content, headers: headers, connect_timeout: connect_timeout,
                                   verbose: verbose)
end