lib/api-client/dispatcher.rb in api-client-1.1.1 vs lib/api-client/dispatcher.rb in api-client-1.2.0
- old
+ new
@@ -1,13 +1,35 @@
require "net/http"
module ApiClient::Dispatcher
- def _get(url = '')
- Net::HTTP.get_response(URI.parse(url))
+ def _get(url, header)
+ initialize_connection(url)
+ @http.get(@uri.path, header)
end
- def _post(url = '', args = {})
- uri = URI(url)
- http = Net::HTTP.new(uri.host, uri.port)
- http.post(uri.path, args.to_json, { 'Content-Type' => 'application/json' })
+ 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
\ No newline at end of file