Class: Zephyrus::Request
- Inherits:
-
Object
- Object
- Zephyrus::Request
- Defined in:
- lib/zephyrus/request.rb
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 17 18 19 20 21 22 23 |
# File 'lib/zephyrus/request.rb', line 8 def initialize( default_parameters = {} ) # parse the API uri uri = URI.parse( Zephyrus.configuration.api_uri ) # construct http request @http = Net::HTTP.new( uri.host, uri.port ) # use ssl when https is the uri scheme @http.use_ssl = ( uri.scheme == 'https' ) @http.verify_mode = OpenSSL::SSL::VERIFY_NONE # retain the default parameters @default_parameters = default_parameters.stringify_keys end |
Instance Method Details
#destroy(path, parameters = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zephyrus/request.rb', line 25 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/zephyrus/request.rb', line 44 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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/zephyrus/request.rb', line 60 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 |