Class: Orias::Request

Inherits:
Base
  • Object
show all
Defined in:
lib/orias/request.rb

Overview

Dedicated to request handling to ORIAS API

Instance Attribute Summary collapse

Instance Method Summary collapse

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_endpointObject

Returns the value of attribute api_endpoint.



8
9
10
# File 'lib/orias/request.rb', line 8

def api_endpoint
  @api_endpoint
end

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/orias/request.rb', line 8

def body
  @body
end

#httpObject (readonly)

Returns the value of attribute http.



7
8
9
# File 'lib/orias/request.rb', line 7

def http
  @http
end

#postObject (readonly)

Returns the value of attribute post.



7
8
9
# File 'lib/orias/request.rb', line 7

def post
  @post
end

#uriObject (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

#responseObject

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