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.
-
#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
73 74 75 76 |
# File 'lib/studio_api/generic_request.rb', line 73 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 |
#post(path, data = {}) ⇒ String
sends post request
83 84 85 86 87 |
# File 'lib/studio_api/generic_request.rb', line 83 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
94 95 96 97 98 |
# File 'lib/studio_api/generic_request.rb', line 94 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 |