module ApiClient::Dispatcher::NetHttp

ApiClient::Dispatcher::NetHttp provides methods to make requests using the native ruby library ‘net/http’

Public Class Methods

delete(url, header = {}) click to toggle source

Make a delete request and returns it.

@param [String] url of the api request. @param [Hash] header attributes of the request. @return [HTTP] the response object.

# File lib/api-client/dispatcher/net-http.rb, line 50
def self.delete(url, header = {})
  dispatch(:delete, url, { :header => header })
end
get(url, header = {}) click to toggle source

Make a get request and returns it.

@param [String] url of the api request. @param [Hash] header attributes of the request. @return [HTTP] the response object.

# File lib/api-client/dispatcher/net-http.rb, line 11
def self.get(url, header = {})
  dispatch(:get, url, { :header => header })
end
patch(url, args, header = {}) click to toggle source

Make a patch request and returns it.

@param [String] url of the api request. @param [Hash] args attributes of object. @param [Hash] header attributes of the request. @return [HTTP] the response object.

# File lib/api-client/dispatcher/net-http.rb, line 41
def self.patch(url, args, header = {})
  dispatch(:patch, url, { :args => args, :header => header })
end
post(url, args, header = {}) click to toggle source

Make a post request and returns it.

@param [String] url of the api request. @param [Hash] args attributes of object. @param [Hash] header attributes of the request. @return [HTTP] the response object.

# File lib/api-client/dispatcher/net-http.rb, line 21
def self.post(url, args, header = {})
  dispatch(:post, url, { :args => args, :header => header })
end
put(url, args, header = {}) click to toggle source

Make a put request and returns it.

@param [String] url of the api request. @param [Hash] args attributes of object. @param [Hash] header attributes of the request. @return [HTTP] the response object.

# File lib/api-client/dispatcher/net-http.rb, line 31
def self.put(url, args, header = {})
  dispatch(:put, url, { :args => args, :header => header })
end

Protected Class Methods

dispatch(method, url, options = {}) click to toggle source
# File lib/api-client/dispatcher/net-http.rb, line 56
def self.dispatch(method, url, options = {})
  args = options[:args].to_json if options[:args]
  header = ApiClient.config.header.merge(options[:header])
  uri = URI(url)
  http = Net::HTTP.start(uri.host, uri.port)
  begin
    if args
      http.send(method, uri.request_uri, args, header)
    else
      http.send(method, uri.request_uri, header)
    end
  rescue Errno::ECONNREFUSED
    raise ApiClient::Exceptions::ConnectionRefused
  end
end