Class: SOF::MCM::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/sof/mcm/request.rb

Direct Known Subclasses

Get, Put

Defined Under Namespace

Classes: NotImplementedError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



30
31
32
# File 'lib/sof/mcm/request.rb', line 30

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



30
31
32
# File 'lib/sof/mcm/request.rb', line 30

def headers
  @headers
end

#httpObject (readonly)

Returns the value of attribute http.



30
31
32
# File 'lib/sof/mcm/request.rb', line 30

def http
  @http
end

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

#callObject



44
45
46
# File 'lib/sof/mcm/request.rb', line 44

def call
  http.request(request)
end

#requestObject



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