Class: Apis::Adapter::NetHTTP

Inherits:
Abstract
  • Object
show all
Defined in:
lib/apis/adapter/net_http.rb

Instance Attribute Summary

Attributes inherited from Abstract

#uri

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Apis::Adapter::Abstract

Instance Method Details

#connectionObject



6
7
8
# File 'lib/apis/adapter/net_http.rb', line 6

def connection
  Net::HTTP.start(uri.host, uri.port)
end

#run(method, path, params = {}, headers = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/apis/adapter/net_http.rb', line 10

def run(method, path, params = {}, headers = {})
  _module = Net::HTTP.const_get(method.to_s.capitalize)
  request = _module.new(path)
  response = connection.request(
    request,
    params.empty? ? nil : Addressable::URI.new.tap { |uri| uri.query_values = params }.query
  )
  [response.code.to_i] + response
end