Class: Unimatrix::Request
- Inherits:
-
Object
- Object
- Unimatrix::Request
- Defined in:
- lib/unimatrix/request.rb
Direct Known Subclasses
Instance Method Summary collapse
- #destroy(path, parameters = {}) ⇒ Object
- #get(path, parameters = {}) ⇒ Object
-
#initialize(default_parameters = {}) ⇒ Request
constructor
A new instance of Request.
- #post(path, parameters = {}, body = {}) ⇒ Object
Constructor Details
#initialize(default_parameters = {}) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 16 |
# File 'lib/unimatrix/request.rb', line 8 def initialize( default_parameters = {} ) uri = URI( Unimatrix.configuration.url ) @http = Net::HTTP.new( uri.host, uri.port ) @http.use_ssl = ( uri.scheme == 'https' ) @http.verify_mode = OpenSSL::SSL::VERIFY_NONE @default_parameters = default_parameters.stringify_keys end |
Instance Method Details
#destroy(path, parameters = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/unimatrix/request.rb', line 18 def destroy( path, parameters = {} ) begin request = Net::HTTP::Delete.new( compose_request_path( path, parameters ), { 'Content-Type' =>'application/json' } ) response = Response.new( @http.request( request ) ) rescue Timeout::Error response = nil end response end |
#get(path, parameters = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/unimatrix/request.rb', line 33 def get( path, parameters = {} ) response = nil begin response = Response.new( @http.get( compose_request_path( path, parameters ) ) ) rescue Timeout::Error response = nil end response end |
#post(path, parameters = {}, body = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/unimatrix/request.rb', line 47 def post( path, parameters = {}, body = {} ) response = nil begin request = Net::HTTP::Post.new( compose_request_path( path, parameters ), { 'Content-Type' =>'application/json' } ) request.body = body.to_json response = Response.new( @http.request( request ) ) rescue Timeout::Error response = nil end response end |