Sha256: 962a26e61849812a1106eba977a0b1c62e6d4611d0ad6b46cf8ec283c4e32c34
Contents?: true
Size: 1.33 KB
Versions: 5
Compression:
Stored size: 1.33 KB
Contents
module Hull # Defines HTTP request methods module Request # Perform an HTTP DELETE request def delete(path, params={}, options={}) request(:delete, api_path(path), params, options) end # Perform an HTTP GET request def get(path, params={}, options={}) request(:get, api_path(path), params, options) end # Perform an HTTP POST request def post(path, params={}, options={}) request(:post, api_path(path), params, options) end # Perform an HTTP PUT request def put(path, params={}, options={}) request(:put, api_path(path), params, options) end private def api_path path if path =~ /^\// path.to_s else "/api/v1/#{path.to_s.gsub(/^\//, '')}" end end # Perform an HTTP request def request(method, path, params={}, options={}) Hull.log("#{method.upcase} #{path} - params: #{params.to_json}") response = connection(options).run_request(method, nil, nil, nil) do |request| request.options[:raw] = true if options[:raw] case method.to_sym when :delete, :get request.url(path, params) when :post, :put request.path = path request.body = params unless params.empty? end end options[:raw] ? response : response.body end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
hullio-0.3.1 | lib/hull/request.rb |
hullio-0.3.0 | lib/hull/request.rb |
hullio-0.2.1 | lib/hull/request.rb |
hullio-0.2.0 | lib/hull/request.rb |
hullio-0.1.0 | lib/hull/request.rb |