Class: Typekit::Connection::Adaptor::Standard

Inherits:
Object
  • Object
show all
Defined in:
lib/typekit/connection/adaptor/standard.rb

Instance Method Summary collapse

Instance Method Details

#process(method, address, parameters = {}, headers = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/typekit/connection/adaptor/standard.rb', line 8

def process(method, address, parameters = {}, headers = {})
  klass = Net::HTTP.const_get(method.to_s.capitalize)
  request = klass.new(build_uri(address, parameters))
  headers.each { |k, v| request[k] = v }
  http = Net::HTTP.new(request.uri.host, request.uri.port)
  http.use_ssl = true if address =~ /^https:/
  response = http.request(request)
  [ response.code, response.to_hash, response.body ]
rescue NameError
  raise Error, 'Invalid method'
rescue SocketError
  raise Error, 'Connection failed'
end