Class: Orias::Request
Overview
Dedicated to request handling to ORIAS API
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
#body ⇒ Object
Returns the value of attribute body.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#post ⇒ Object
readonly
Returns the value of attribute post.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#build! ⇒ Object
Build the request to be sent.
-
#initialize(attributes = {}) ⇒ Request
constructor
Initialize an Orias::Request instance.
-
#response ⇒ Object
Return or set #response if not already set.
-
#send! ⇒ Object
Send the built request.
Constructor Details
#initialize(attributes = {}) ⇒ Request
Initialize an Orias::Request instance
11 12 13 14 |
# File 'lib/orias/request.rb', line 11 def initialize(attributes = {}) super @api_endpoint ||= Orias.configuration.api_endpoint end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
8 9 10 |
# File 'lib/orias/request.rb', line 8 def api_endpoint @api_endpoint end |
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/orias/request.rb', line 8 def body @body end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
7 8 9 |
# File 'lib/orias/request.rb', line 7 def http @http end |
#post ⇒ Object (readonly)
Returns the value of attribute post.
7 8 9 |
# File 'lib/orias/request.rb', line 7 def post @post end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/orias/request.rb', line 7 def uri @uri end |
Instance Method Details
#build! ⇒ Object
Build the request to be sent
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/orias/request.rb', line 17 def build! @uri = URI(@api_endpoint) @post = Net::HTTP::Post.new(uri) @post.body = @body @post['Content-Type'] = 'application/xml' @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true self end |
#response ⇒ Object
Return or set #response if not already set
38 39 40 |
# File 'lib/orias/request.rb', line 38 def response @response || send! end |
#send! ⇒ Object
Send the built request
31 32 33 34 35 |
# File 'lib/orias/request.rb', line 31 def send! build! unless @post && @http @response = @http.request(@post) @response end |