Sha256: fda01251035f48f1dd128f3fb168311721e2607e7c28357bee66d0d12293ef71
Contents?: true
Size: 1.96 KB
Versions: 4
Compression:
Stored size: 1.96 KB
Contents
require "net/http" # ApiClient::Dispatcher provides methods to make requests using the native ruby library 'net/http' module ApiClient::Dispatcher # 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. def _get(url, header) initialize_connection(url) @http.get(@uri.path, header) end # 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. def _post(url, args, header) initialize_connection(url) @http.post(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) end # 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. def _put(url, args, header) initialize_connection(url) @http.put(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) end # 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. def _patch(url, args, header) initialize_connection(url) @http.patch(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) end # 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. 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
api-client-1.5.0 | lib/api-client/dispatcher.rb |
api-client-1.4.1 | lib/api-client/dispatcher.rb |
api-client-1.4.0 | lib/api-client/dispatcher.rb |
api-client-1.3.0 | lib/api-client/dispatcher.rb |