Class: FrOData::Service::Request
- Inherits:
-
Object
- Object
- FrOData::Service::Request
- Defined in:
- lib/frodata/service/request.rb
Overview
Encapsulates a single request to an OData service.
Instance Attribute Summary collapse
-
#format ⇒ Object
The request format (‘:atom`, `:json`, or `:auto`).
-
#method ⇒ Object
The HTTP method for this request.
-
#query ⇒ Object
readonly
The FrOData::Query that generated this request (optional).
-
#service ⇒ Object
readonly
The OData service against which the request is performed.
Instance Method Summary collapse
-
#content_type ⇒ String
The content type for this request.
-
#execute(request_options = {}) ⇒ FrOData::Service::Response
Execute the request.
-
#initialize(service, url_chunk, options = {}) ⇒ Request
constructor
Create a new request.
-
#url ⇒ String
Return the full request URL (including service base).
Constructor Details
#initialize(service, url_chunk, options = {}) ⇒ Request
Create a new request
18 19 20 21 22 23 24 25 |
# File 'lib/frodata/service/request.rb', line 18 def initialize(service, url_chunk, = {}) @service = service @url_chunk = url_chunk @method = .delete(:method) || :get @format = .delete(:format) || :auto @query = .delete(:query) @options = end |
Instance Attribute Details
#format ⇒ Object
The request format (‘:atom`, `:json`, or `:auto`)
12 13 14 |
# File 'lib/frodata/service/request.rb', line 12 def format @format end |
#method ⇒ Object
The HTTP method for this request
10 11 12 |
# File 'lib/frodata/service/request.rb', line 10 def method @method end |
#query ⇒ Object (readonly)
The FrOData::Query that generated this request (optional)
8 9 10 |
# File 'lib/frodata/service/request.rb', line 8 def query @query end |
#service ⇒ Object (readonly)
The OData service against which the request is performed
6 7 8 |
# File 'lib/frodata/service/request.rb', line 6 def service @service end |
Instance Method Details
#content_type ⇒ String
The content type for this request. Depends on format.
35 36 37 38 39 40 41 42 43 |
# File 'lib/frodata/service/request.rb', line 35 def content_type if format == :auto MIME_TYPES.values.join(',') elsif MIME_TYPES.has_key? format MIME_TYPES[format] else raise ArgumentError, "Unknown format '#{format}'" end end |
#execute(request_options = {}) ⇒ FrOData::Service::Response
Execute the request
49 50 51 52 53 54 55 |
# File 'lib/frodata/service/request.rb', line 49 def execute( = {}) Response.new(service, query) do connection.run_request(method, url_chunk, nil, headers) do |conn| conn..merge! end end end |
#url ⇒ String
Return the full request URL (including service base)
29 30 31 |
# File 'lib/frodata/service/request.rb', line 29 def url ::URI.join("#{service.service_url}/", ::URI.escape(url_chunk)).to_s end |