Class: GData::Connection
- Inherits:
-
Object
- Object
- GData::Connection
- Defined in:
- lib/gdata.rb
Instance Attribute Summary collapse
-
#http_connection ⇒ Object
readonly
Returns the value of attribute http_connection.
Instance Method Summary collapse
-
#initialize(host, port, proxy = nil, proxy_port = nil, proxy_user = nil, proxy_passwd = nil) ⇒ Connection
constructor
Establishes SSL connection to Google host.
-
#perform(method, path = '', body = nil, header = nil) ⇒ Object
Performs the http request and returns the http response.
Constructor Details
#initialize(host, port, proxy = nil, proxy_port = nil, proxy_user = nil, proxy_passwd = nil) ⇒ Connection
Establishes SSL connection to Google host
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gdata.rb', line 12 def initialize(host, port, proxy=nil, proxy_port=nil, proxy_user=nil, proxy_passwd=nil) conn = Net::HTTP.new(host, port, proxy, proxy_port, proxy_user, proxy_passwd) conn.use_ssl = true conn.verify_mode = OpenSSL::SSL::VERIFY_PEER conn.verify_mode = OpenSSL::SSL::VERIFY_NONE store = OpenSSL::X509::Store.new store.set_default_paths conn.cert_store = store conn.start @http_connection = conn end |
Instance Attribute Details
#http_connection ⇒ Object (readonly)
Returns the value of attribute http_connection.
9 10 11 |
# File 'lib/gdata.rb', line 9 def http_connection @http_connection end |
Instance Method Details
#perform(method, path = '', body = nil, header = nil) ⇒ Object
Performs the http request and returns the http response
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gdata.rb', line 25 def perform(method, path='', body=nil, header=nil) backoff_factor = 2 resp = nil while resp.nil? begin req = Net::HTTPGenericRequest.new(method, ! body.nil?, true, path) req['Content-Type'] = header['Content-Type'] if header['Content-Type'] req['Authorization'] = header['Authorization'] if header['Authorization'] req['Content-length'] = body.length.to_s if body resp = @http_connection.request(req, body) rescue Timeout::Error retry rescue GData::GDataError => e if e.code == "503" resp = nil sleep(backoff_factor) backoff_factor *= backoff_factor else return e end rescue Errno::EPIPE retry rescue EOFError end end return resp end |