Sha256: 29d1f32352df09cff43300d64e07431e6b00614231f7a3f2dafdac3cac6d1937

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

require "net/http"

module ApiClient::Dispatcher
  def _get(url, header)
    initialize_connection(url)
    @http.get(@uri.path, header)
  end

  def _post(url, args, header)
    initialize_connection(url)
    @http.post(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header))
  end

  def _put(url, args, header)
    initialize_connection(url)
    @http.put(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header))
  end

  def _patch(url, args, header)
    initialize_connection(url)
    @http.patch(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header))
  end

  def _delete(url, header)
    initialize_connection(url)
    @http.delete(@uri.path, header)
  end

  protected

  def initialize_connection(url = '')
    @uri = URI(url)
    @http = Net::HTTP.new(@uri.host, @uri.port)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api-client-1.2.0 lib/api-client/dispatcher.rb