Class: Pincers::Http::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/pincers/http/session.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Accept' => '*/*',
  'Cache-Control' => 'no-cache'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_other = nil) ⇒ Session

Returns a new instance of Session.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pincers/http/session.rb', line 17

def initialize(_other = nil)
  if _other
    @headers = _other.headers.clone
    @cookie_jar = _other.cookie_jar.copy
    @proxy_addr = _other.proxy_addr
    @proxy_port = _other.proxy_port
    @redirect_limit = _other.redirect_limit
    @ssl_cert = _other.ssl_cert
    @ssl_key = _other.ssl_key
  else
    @headers = DEFAULT_HEADERS
    @cookie_jar = CookieJar.new
    @redirect_limit = 10
  end
end

Instance Attribute Details

Returns the value of attribute cookie_jar.



13
14
15
# File 'lib/pincers/http/session.rb', line 13

def cookie_jar
  @cookie_jar
end

#headersObject (readonly)

Returns the value of attribute headers.



13
14
15
# File 'lib/pincers/http/session.rb', line 13

def headers
  @headers
end

#proxy_addrObject

Returns the value of attribute proxy_addr.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def proxy_addr
  @proxy_addr
end

#proxy_passwordObject

Returns the value of attribute proxy_password.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def proxy_password
  @proxy_password
end

#proxy_portObject

Returns the value of attribute proxy_port.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def proxy_port
  @proxy_port
end

#proxy_userObject

Returns the value of attribute proxy_user.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def proxy_user
  @proxy_user
end

#redirect_limitObject

Returns the value of attribute redirect_limit.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def redirect_limit
  @redirect_limit
end

#ssl_certObject

Returns the value of attribute ssl_cert.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def ssl_cert
  @ssl_cert
end

#ssl_keyObject

Returns the value of attribute ssl_key.



14
15
16
# File 'lib/pincers/http/session.rb', line 14

def ssl_key
  @ssl_key
end

Instance Method Details

#cloneObject



49
50
51
# File 'lib/pincers/http/session.rb', line 49

def clone
  self.class.new self
end

#perform(_request) ⇒ Object



58
59
60
# File 'lib/pincers/http/session.rb', line 58

def perform(_request)
  perform_recursive _request, @redirect_limit
end

#proxy=(_value) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pincers/http/session.rb', line 33

def proxy=(_value)
  if _value
    @proxy_addr, @proxy_port = _value.split ':'
  else
    @proxy_addr, @proxy_port = [nil, nil]
  end
end

#proxy_auth=(_value) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/pincers/http/session.rb', line 41

def proxy_auth=(_value)
  if _value
    @proxy_user, @proxy_password = _value.split ':'
  else
    @proxy_user, @proxy_password = [nil, nil]
  end
end

#sync(_other) ⇒ Object



53
54
55
56
# File 'lib/pincers/http/session.rb', line 53

def sync(_other)
  @headers.merge! _other.headers
  _other.cookie_jar.cookies.each { |c| cookie_jar.set c }
end