Class: SOF::MCM::Request
- Inherits:
-
Object
- Object
- SOF::MCM::Request
- Defined in:
- lib/sof/mcm/request.rb
Defined Under Namespace
Classes: NotImplementedError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(url, body, headers) ⇒ Request
constructor
A new instance of Request.
- #request ⇒ Object
- #verify_mode=(mode) ⇒ Object
Constructor Details
#initialize(url, body, headers) ⇒ Request
Returns a new instance of Request.
23 24 25 26 27 28 29 |
# File 'lib/sof/mcm/request.rb', line 23 def initialize(url, body, headers) @uri = URI(url) @body = body @headers = headers @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = uri.scheme == "https" end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
30 31 32 |
# File 'lib/sof/mcm/request.rb', line 30 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
30 31 32 |
# File 'lib/sof/mcm/request.rb', line 30 def headers @headers end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
30 31 32 |
# File 'lib/sof/mcm/request.rb', line 30 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
30 31 32 |
# File 'lib/sof/mcm/request.rb', line 30 def uri @uri end |
Class Method Details
.call(url, body = nil, headers = nil) ⇒ Object
19 20 21 |
# File 'lib/sof/mcm/request.rb', line 19 def self.call(url, body = nil, headers = nil) new(url, body, headers).call end |
.with_verify(verify) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sof/mcm/request.rb', line 6 def self.with_verify(verify) veification = if verify OpenSSL::SSL::VERIFY_PEER else OpenSSL::SSL::VERIFY_NONE end proc do |url, body = nil, headers = nil| new(url, body, headers).tap do |instance| instance.verify_mode = veification end.call end end |
Instance Method Details
#call ⇒ Object
44 45 46 |
# File 'lib/sof/mcm/request.rb', line 44 def call http.request(request) end |
#request ⇒ Object
38 39 40 41 42 |
# File 'lib/sof/mcm/request.rb', line 38 def request type.new(uri, headers).tap do |req| req.body = body if body end end |
#verify_mode=(mode) ⇒ Object
34 35 36 |
# File 'lib/sof/mcm/request.rb', line 34 def verify_mode=(mode) http.verify_mode = mode end |