Class: Rubytter::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubytter/connection.rb', line 6

def initialize(options = {})
  @proxy_host = options[:proxy_host]
  @proxy_port = options[:proxy_port]
  @proxy_user = options[:proxy_user_name]
  @proxy_password = options[:proxy_password]
  @proxy_uri = nil
  @enable_ssl = options[:enable_ssl]

  if @enable_ssl
    @protocol = "https"
    @port = 443
  else
    @protocol = "http"
    @port = 80
  end

  if @proxy_host
    @http_class = Net::HTTP::Proxy(@proxy_host, @proxy_port,
                                   @proxy_user, @proxy_password)
    @proxy_uri =  "#{@protocol}://" + @proxy_host + ":" + @proxy_port.to_s + "/"
  else
    @http_class = Net::HTTP
  end
end

Instance Attribute Details

#enable_sslObject (readonly)

Returns the value of attribute enable_ssl.



4
5
6
# File 'lib/rubytter/connection.rb', line 4

def enable_ssl
  @enable_ssl
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/rubytter/connection.rb', line 4

def port
  @port
end

#protocolObject (readonly)

Returns the value of attribute protocol.



4
5
6
# File 'lib/rubytter/connection.rb', line 4

def protocol
  @protocol
end

#proxy_uriObject (readonly)

Returns the value of attribute proxy_uri.



4
5
6
# File 'lib/rubytter/connection.rb', line 4

def proxy_uri
  @proxy_uri
end

Instance Method Details

#start(host, port = nil, &block) ⇒ Object



31
32
33
34
35
36
# File 'lib/rubytter/connection.rb', line 31

def start(host, port = nil, &block)
  http = @http_class.new(host, port || @port)
  http.use_ssl = @enable_ssl
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
  http.start(&block)
end