Method: Orchestrate::Client#send_request
- Defined in:
- lib/orchestrate/client.rb
permalink #send_request(method, path, options = {}) ⇒ Object
Performs an HTTP request against the Orchestrate API
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/orchestrate/client.rb', line 434 def send_request(method, path, ={}) path = ['/v0'].concat(path.map{|s| URI.escape(s.to_s).gsub('/','%2F') }).join('/') query_string = .fetch(:query, {}) body = .fetch(:body, '') headers = .fetch(:headers, {}) headers['User-Agent'] = "ruby/orchestrate/#{Orchestrate::VERSION}" headers['Accept'] = 'application/json' if method == :get headers['Connection'] = 'close' if method == :head http_response = http.send(method) do |request| request.url path, query_string if [:put, :post].include?(method) headers['Content-Type'] = 'application/json' request.body = body.to_json elsif [:patch].include?(method) request.body = body.to_json end headers.each {|header, value| request[header] = value } end response_class = .fetch(:response, API::Response) response_class.new(http_response, self) end |