Class: Boxspring::Request
- Inherits:
-
Object
- Object
- Boxspring::Request
- Defined in:
- lib/boxspring/request.rb
Instance Method Summary collapse
- #get(path, parameters = {}) ⇒ Object
-
#initialize(default_parameters = {}) ⇒ Request
constructor
A new instance of Request.
- #post(path, parameters = {}) ⇒ 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/boxspring/request.rb', line 8 def initialize( default_parameters = {} ) # parse the API uri uri = URI.parse( Boxspring.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
#get(path, parameters = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/boxspring/request.rb', line 25 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 = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/boxspring/request.rb', line 42 def post( path, parameters = {} ) response = nil begin data = [] parameters.each_pair do | key, value | data << "#{key.to_s}=#{value.to_s}" end response = Response.new( @http.post( compose_request_path( path ), data.join( '&' ) ) ) rescue Timeout::Error response = nil end response end |