Class: StudioApi::GenericRequest
- Inherits:
-
Object
- Object
- StudioApi::GenericRequest
- Defined in:
- lib/studio_api/generic_request.rb
Overview
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.
Instance Method Summary collapse
-
#delete(path) ⇒ String
sends delete request.
-
#get(path) ⇒ String
sends get request.
-
#get_file(path, &block) ⇒ nil
sends get request to suse studio.
-
#initialize(connection) ⇒ GenericRequest
constructor
Creates new instance of request for given connection.
-
#post(path, data = {}) ⇒ String
sends post request.
-
#put(path, data = {}) ⇒ String
sends post request.
Constructor Details
#initialize(connection) ⇒ GenericRequest
Creates new instance of request for given connection
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |
Instance Method Details
#delete(path) ⇒ String
sends delete request
82 83 84 85 |
# 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 |
#get(path) ⇒ String
sends get request
65 66 67 |
# 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 |
#get_file(path, &block) ⇒ nil
sends get request to suse studio
72 73 74 75 76 |
# 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 |
#post(path, data = {}) ⇒ String
sends post request
92 93 94 95 96 |
# 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 |
#put(path, data = {}) ⇒ String
sends post request
103 104 105 106 107 |
# 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 |