Class which use itself direct connection to studio for tasks where ActiveResource is not enough. For consistent api is all network exceptions mapped to ones used in ActiveResource.
@example
rq = StudioApi::GenericRequest.new @connection rq.get "/appliances" rq.post "/file", :file => "/etc/config"
Creates new instance of request for given connection @param (StudioApi::Connection) connection information about connection
# File lib/studio_api/generic_request.rb, line 43 def initialize(connection) @connection = connection if connection.proxy proxy = connection.proxy @http = Net::HTTP.new(connection.uri.host, connection.uri.port, proxy.host, proxy.port, proxy.user, proxy.password) else @http = Net::HTTP.new(connection.uri.host, connection.uri.port) end @http.read_timeout = connection.timeout if connection.uri.scheme == "https" @http.use_ssl = true Connection::SSL_ATTRIBUTES.each do |attr| @http.send :"#{attr}=", connection.ssl[attr.to_sym] if connection.ssl[attr.to_sym] end end end
sends delete request @param (String) path relative path from api root @return (String) response body from studio @raise [ActiveResource::ConnectionError] when problem occur during connection
# File lib/studio_api/generic_request.rb, line 82 def delete(path) #Even it is not dry I want to avoid meta programming with dynamic code evaluation so code is clear do_request(Net::HTTP::Delete.new(Util.join_relative_url(@connection.uri.request_uri,path))) end
sends get request @param (String) path relative path from api root @return (String) response body from studio @raise [ActiveResource::ConnectionError] when problem occur during connection
# File lib/studio_api/generic_request.rb, line 65 def get(path) do_request(Net::HTTP::Get.new(Util.join_relative_url(@connection.uri.request_uri,path))) end
sends get request to suse studio @return (nil) as response @raise [ActiveResource::ConnectionError] when problem occur during connection
# File lib/studio_api/generic_request.rb, line 72 def get_file(path, &block) do_file_request(Net::HTTP::Get.new( Util.join_relative_url(@connection.uri.request_uri,path)), &block) end
sends post request @param (String) path relative path from api root @param (Hash<to_s,to_s>,Hash<to_s,path>) data hash containing data to attach to body @return (String) response body from studio @raise [ActiveResource::ConnectionError] when problem occur during connection
# File lib/studio_api/generic_request.rb, line 92 def post(path,data={}) request = Net::HTTP::Post.new(Util.join_relative_url(@connection.uri.request_uri,path)) set_data(request,data) unless data.empty? do_request request end
sends post request @param (String) path relative path from api root @param (Hash<to_s,to_s>,Hash<to_s,path>) data hash containing data to attach to body @return (String) response body from studio @raise [ActiveResource::ConnectionError] when problem occur during connection
# File lib/studio_api/generic_request.rb, line 103 def put(path,data={}) request = Net::HTTP::Put.new(Util.join_relative_url(@connection.uri.request_uri,path)) set_data(request,data) unless data.empty? do_request request end