Class: Tweakphoeus::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tweakphoeus.rb

Overview

Http client class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ua_systems: %i[linux mac],, ssl_verifypeer: true, redirect: false) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
# File 'lib/tweakphoeus.rb', line 15

def initialize(ua_systems: i[linux mac], ssl_verifypeer: true, redirect: false)
  @cookie_jar = Tweakphoeus::CookieJar.new
  @referer_list = Tweakphoeus::RefererList.new
  @redirect = redirect
  @base_headers = build_base_headers(ua_systems)
  @proxy = nil
  @proxyuserpwd = nil
  @ssl_verifypeer = ssl_verifypeer
end

Instance Attribute Details

#base_headersObject

Returns the value of attribute base_headers.



12
13
14
# File 'lib/tweakphoeus.rb', line 12

def base_headers
  @base_headers
end

Returns the value of attribute cookie_jar.



12
13
14
# File 'lib/tweakphoeus.rb', line 12

def cookie_jar
  @cookie_jar
end

#redirectObject

Returns the value of attribute redirect.



12
13
14
# File 'lib/tweakphoeus.rb', line 12

def redirect
  @redirect
end

#referer_listObject

Returns the value of attribute referer_list.



12
13
14
# File 'lib/tweakphoeus.rb', line 12

def referer_list
  @referer_list
end

#ssl_verifypeerObject (readonly)

Returns the value of attribute ssl_verifypeer.



13
14
15
# File 'lib/tweakphoeus.rb', line 13

def ssl_verifypeer
  @ssl_verifypeer
end

Instance Method Details

#delete(url, body: nil, headers: nil) ⇒ Object



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

def delete(url, body: nil, headers: nil)
  referer_list.referer_from_headers(headers)
  http_request(url, body: body, headers: headers, method: :delete)
end

#get(url, body: nil, params: nil, headers: nil) ⇒ Object



25
26
27
28
# File 'lib/tweakphoeus.rb', line 25

def get(url, body: nil, params: nil, headers: nil)
  referer_list.referer_from_headers(headers)
  http_request(url, body: body, params: params, headers: headers, method: :get)
end

#post(url, body: nil, headers: nil) ⇒ Object



35
36
37
38
# File 'lib/tweakphoeus.rb', line 35

def post(url, body: nil, headers: nil)
  referer_list.referer_from_headers(headers)
  http_request(url, body: body, headers: headers, method: :post)
end

#set_proxy(url, auth) ⇒ Object



40
41
42
43
44
45
# File 'lib/tweakphoeus.rb', line 40

def set_proxy(url, auth)
  return unless auth

  @proxyuserpwd = "#{auth[:user]}:#{auth[:password]}"
  @proxy = url
end

#unset_proxyObject



47
48
49
50
# File 'lib/tweakphoeus.rb', line 47

def unset_proxy
  @proxyuserpwd = nil
  @proxy = nil
end