Module: Wpxf::Net::TyphoeusHelper

Included in:
HttpClient
Defined in:
lib/wpxf/net/typhoeus_helper.rb

Overview

Provides helper functions for interfacing with Typhoeus in a module.

Instance Method Summary collapse

Instance Method Details

#advanced_typhoeus_optionsObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/wpxf/net/typhoeus_helper.rb', line 7

def advanced_typhoeus_options
  {
    userpwd: datastore['basic_auth_creds'],
    proxy: datastore['proxy'],
    proxyuserpwd: datastore['proxy_auth_creds'],
    ssl_verifyhost: normalized_option_value('verify_host') ? 2 : 0,
    ssl_verifypeer: normalized_option_value('verify_peer'),
    timeout: normalized_option_value('http_client_timeout')
  }
end

#create_typhoeus_request(opts) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wpxf/net/typhoeus_helper.rb', line 33

def create_typhoeus_request(opts)
  headers = opts[:headers] || {}
  headers['Cookie'] = opts[:cookie] if opts[:cookie]
  options = create_typhoeus_request_options(
    opts[:method],
    opts[:params],
    opts[:body],
    headers
  )
  Typhoeus::Request.new(normalize_relative_uri(opts[:url]), options)
end

#create_typhoeus_request_options(method, params, body, headers) ⇒ Object



28
29
30
31
# File 'lib/wpxf/net/typhoeus_helper.rb', line 28

def create_typhoeus_request_options(method, params, body, headers)
  standard_typhoeus_options(method, params, body, headers)
    .merge(advanced_typhoeus_options)
end

#standard_typhoeus_options(method, params, body, headers) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/wpxf/net/typhoeus_helper.rb', line 18

def standard_typhoeus_options(method, params, body, headers)
  {
    method: method,
    body: body,
    params: params,
    headers: base_http_headers.merge(headers),
    followlocation: normalized_option_value('follow_http_redirection')
  }
end