Class: WebTranslateIt::Connection
- Inherits:
-
Object
- Object
- WebTranslateIt::Connection
- Defined in:
- lib/web_translate_it/connection.rb
Constant Summary collapse
- @@api_key =
nil
- @@http_connection =
nil
- @@debug =
false
- @@silent =
false
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Connection
constructor
Initialize and yield a HTTPS Keep-Alive connection to WebTranslateIt.com.
Constructor Details
#initialize(api_key) ⇒ Connection
Initialize and yield a HTTPS Keep-Alive connection to WebTranslateIt.com
Usage:
WebTranslateIt::Connection.new(api_key) do
# do something with Connection.api_key and Connection.http_connection
end
Or:
WebTranslateIt::Connection.new(api_key) do |http_connection|
http_connection.request(request)
end
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/web_translate_it/connection.rb', line 30 def initialize(api_key) @@api_key = api_key proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new('webtranslateit.com', 443) http.use_ssl = true http.open_timeout = http.read_timeout = 60 http.set_debug_output($stderr) if @@debug begin http.verify_mode = OpenSSL::SSL::VERIFY_PEER @@http_connection = http.start yield @@http_connection if block_given? rescue OpenSSL::SSL::SSLError puts "Unable to verify SSL certificate." unless @@silent http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new('webtranslateit.com', 443) http.set_debug_output($stderr) if @@debug http.use_ssl = true http.open_timeout = http.read_timeout = 60 http.verify_mode = OpenSSL::SSL::VERIFY_NONE @@http_connection = http.start yield @@http_connection if block_given? rescue puts $! end end |
Class Method Details
.api_key ⇒ Object
67 68 69 |
# File 'lib/web_translate_it/connection.rb', line 67 def self.api_key @@api_key end |
.http_connection ⇒ Object
55 56 57 |
# File 'lib/web_translate_it/connection.rb', line 55 def self.http_connection @@http_connection end |
.turn_debug_on ⇒ Object
59 60 61 |
# File 'lib/web_translate_it/connection.rb', line 59 def self.turn_debug_on @@debug = true end |
.turn_silent_on ⇒ Object
63 64 65 |
# File 'lib/web_translate_it/connection.rb', line 63 def self.turn_silent_on @@silent = true end |