Class: OData::Request
- Inherits:
-
Object
- Object
- OData::Request
- Defined in:
- lib/odata/request.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(method = :get, uri = '', data = nil) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(method = :get, uri = '', data = nil) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 |
# File 'lib/odata/request.rb', line 8 def initialize(method = :get, uri = '', data = nil) @method = method.to_s.downcase.to_sym @uri = URI(uri) @data = data @headers = { 'Content-Type' => 'application/json' } end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/odata/request.rb', line 6 def data @data end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/odata/request.rb', line 3 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
5 6 7 |
# File 'lib/odata/request.rb', line 5 def method @method end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/odata/request.rb', line 4 def uri @uri end |
Instance Method Details
#perform ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/odata/request.rb', line 17 def perform response = Net::HTTP .new(uri.hostname, uri.port) .tap { |h| h.use_ssl = true } .send(*send_params) raise ServerError.new(response) unless response.code.to_i < 500 raise AuthenticationError.new(response) if response.code.to_i == 401 raise AuthorizationError.new(response) if response.code.to_i == 403 raise ClientError.new(response) unless response.code.to_i < 400 if response.body begin OData.convert_keys_to_snake_case(JSON.parse(response.body)) rescue JSON::ParserError => e {} end else {} end end |