lib/gooddata/connection.rb in gooddata-0.5.4 vs lib/gooddata/connection.rb in gooddata-0.5.5

- old
+ new

@@ -69,11 +69,11 @@ # Connection.new(username, password).get '/gdc/projects' def get(path, options = {}) GoodData.logger.debug "GET #{path}" ensure_connection b = Proc.new { @server[path].get cookies } - response = (options[:process] == false) ? (b.call) : process_response(options, &b) + process_response(options, &b) end # Performs a HTTP POST request. # # Retuns the JSON response formatted as a Hash object. @@ -89,13 +89,33 @@ def post(path, data, options = {}) payload = data.is_a?(Hash) ? data.to_json : data GoodData.logger.debug "POST #{path}, payload: #{payload}" ensure_connection b = Proc.new { @server[path].post payload, cookies } - options[:process] == false ? b.call : process_response(options, &b) + process_response(options, &b) end + # Performs a HTTP PUT request. + # + # Retuns the JSON response formatted as a Hash object. + # + # === Parameters + # + # * +path+ - The HTTP path on the GoodData server (must be prefixed with a forward slash) + # * +data+ - The payload data in the format of a Hash object + # + # === Examples + # + # Connection.new(username, password).put '/gdc/projects', { ... } + def put(path, data, options = {}) + payload = data.is_a?(Hash) ? data.to_json : data + GoodData.logger.debug "PUT #{path}, payload: #{payload}" + ensure_connection + b = Proc.new { @server[path].put payload, cookies } + process_response(options, &b) + end + # Performs a HTTP DELETE request. # # Retuns the JSON response formatted as a Hash object. # # === Parameters @@ -107,11 +127,11 @@ # Connection.new(username, password).delete '/gdc/project/1' def delete(path, options = {}) GoodData.logger.debug "DELETE #{path}" ensure_connection b = Proc.new { @server[path].delete cookies } - options[:process] == false ? b.call : process_response(options, &b) + process_response(options, &b) end # Get the cookies associated with the current connection. def cookies @cookies ||= { :cookies => {} } @@ -254,9 +274,11 @@ refresh_token response = block.call end merge_cookies! response.cookies content_type = response.headers[:content_type] + return response if options[:process] == false + if content_type == "application/json" || content_type == "application/json;charset=UTF-8" then result = response.to_str == '""' ? {} : JSON.parse(response.to_str) GoodData.logger.debug "Response: #{result.inspect}" elsif content_type == "application/zip" then result = response