Class: Unimatrix::Activist::Request
- Inherits:
-
Object
- Object
- Unimatrix::Activist::Request
- Defined in:
- lib/unimatrix/activist/request.rb
Instance Method Summary collapse
- #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/activist/request.rb', line 8 def initialize( default_parameters = {} ) uri = URI( Unimatrix::Activist.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
#get(path, parameters = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/unimatrix/activist/request.rb', line 18 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/unimatrix/activist/request.rb', line 32 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 |