Module: Typhoeus::EasyFu::Options

Included in:
Typhoeus::Easy
Defined in:
lib/typhoeus/easy/options.rb

Instance Method Summary collapse

Instance Method Details

#connect_timeout=(milliseconds) ⇒ Object



38
39
40
41
42
# File 'lib/typhoeus/easy/options.rb', line 38

def connect_timeout=(milliseconds)
  @connect_timeout = milliseconds
  set_option(:nosignal, 1)
  set_option(:connecttimeout_ms, milliseconds)
end

#encoding=(encoding) ⇒ Object



12
13
14
15
# File 'lib/typhoeus/easy/options.rb', line 12

def encoding=(encoding)
  # Enable encoding/compression support
  set_option(:encoding, encoding)
end

#follow_location=(boolean) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/typhoeus/easy/options.rb', line 26

def follow_location=(boolean)
  if boolean
    set_option(:followlocation, 1)
  else
    set_option(:followlocation, 0)
  end
end

#header_function=(callback) ⇒ Object



8
9
10
# File 'lib/typhoeus/easy/options.rb', line 8

def header_function=(callback)
  set_option(:headerfunction, header_write_callback)
end

#interface=(interface) ⇒ Object



17
18
19
20
# File 'lib/typhoeus/easy/options.rb', line 17

def interface=(interface)
  @interface = interface
  set_option(:interface, interface)
end

#max_redirects=(redirects) ⇒ Object



34
35
36
# File 'lib/typhoeus/easy/options.rb', line 34

def max_redirects=(redirects)
  set_option(:maxredirs, redirects)
end

#method=(method) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/typhoeus/easy/options.rb', line 70

def method=(method)
  @method = method
  if method == :get
    set_option(:httpget, 1)
  elsif method == :post
    set_option(:httppost, 1)
    self.post_data = ""
  elsif method == :put
    set_option(:upload, 1)
    self.request_body = @request_body.to_s
  elsif method == :head
    set_option(:nobody, 1)
  else
    set_option(:customrequest, method.to_s.upcase)
  end
end

#post_data=(data) ⇒ Object



87
88
89
90
91
# File 'lib/typhoeus/easy/options.rb', line 87

def post_data=(data)
  @post_data_set = true
  set_option(:postfieldsize, Utils.bytesize(data))
  set_option(:copypostfields, data)
end

#request_body=(request_body) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/typhoeus/easy/options.rb', line 50

def request_body=(request_body)
  @request_body = request_body
  if method == :put
    @request_body_read = 0
    set_option(:infilesize, Utils.bytesize(@request_body))
    set_option(:readfunction, read_callback)
  else
    self.post_data = request_body
  end
end

#set_headersObject



108
109
110
111
112
# File 'lib/typhoeus/easy/options.rb', line 108

def set_headers
  @header_list = nil
  headers.each {|key, value| @header_list = Curl.slist_append(@header_list, "#{key}: #{value}") }
  set_option(:httpheader, @header_list) unless headers.empty?
end

#set_option(option, value) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/typhoeus/easy/options.rb', line 93

def set_option(option, value)
  case value
  when String
    Curl.easy_setopt_string(handle, option, value.to_s)
  when Integer
    Curl.easy_setopt_long(handle, option, value)
  when Proc, ::FFI::Function
    Curl.easy_setopt_callback(handle, option, value)
  when Typhoeus::Form
    Curl.easy_setopt(handle, option, value.first.read_pointer)
  else
    Curl.easy_setopt(handle, option, value) if value
  end
end

#timeout=(milliseconds) ⇒ Object



44
45
46
47
48
# File 'lib/typhoeus/easy/options.rb', line 44

def timeout=(milliseconds)
  @timeout = milliseconds
  set_option(:nosignal, 1)
  set_option(:timeout_ms, milliseconds)
end

#url=(url) ⇒ Object



65
66
67
68
# File 'lib/typhoeus/easy/options.rb', line 65

def url=(url)
  @url = url
  set_option(:url, url)
end

#user_agent=(user_agent) ⇒ Object



61
62
63
# File 'lib/typhoeus/easy/options.rb', line 61

def user_agent=(user_agent)
  set_option(:useragent, user_agent)
end

#verbose=(boolean) ⇒ Object



22
23
24
# File 'lib/typhoeus/easy/options.rb', line 22

def verbose=(boolean)
  set_option(:verbose, !!boolean ? 1 : 0)
end

#write_function=(callback) ⇒ Object



4
5
6
# File 'lib/typhoeus/easy/options.rb', line 4

def write_function=(callback)
  set_option(:writefunction, body_write_callback)
end