Class: Thoom::RestUp

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_up.rb

Overview

Makes the request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ RestUp

Returns a new instance of RestUp.



24
25
26
27
28
29
30
31
32
# File 'lib/rest_up.rb', line 24

def initialize(config = nil)
  @config = config.nil? ? HashConfig.new : config
  @log = Logger.new STDOUT

  @uri = nil
  @xmethods = nil
  @headers = @config.get(:headers, {})
  @standard_methods = %w(delete get head options patch post put)
end

Instance Attribute Details

#certObject

Returns the value of attribute cert.



21
22
23
# File 'lib/rest_up.rb', line 21

def cert
  @cert
end

#dataObject

Returns the value of attribute data.



21
22
23
# File 'lib/rest_up.rb', line 21

def data
  @data
end

#endpointObject

Returns the value of attribute endpoint.



21
22
23
# File 'lib/rest_up.rb', line 21

def endpoint
  @endpoint
end

#headersObject

Returns the value of attribute headers.



22
23
24
# File 'lib/rest_up.rb', line 22

def headers
  @headers
end

#logObject (readonly)

Returns the value of attribute log.



22
23
24
# File 'lib/rest_up.rb', line 22

def log
  @log
end

#methodObject

Returns the value of attribute method.



22
23
24
# File 'lib/rest_up.rb', line 22

def method
  @method
end

Instance Method Details

#httpObject



64
65
66
67
68
69
70
71
72
# File 'lib/rest_up.rb', line 64

def http
  http = Net::HTTP.new(uri.host, uri.port)
  http.read_timeout = @config.get(:timeout, 300)

  configure_tls http
  configure_client_cert http

  http
end

#requestObject

Raises:



53
54
55
56
57
58
59
60
61
62
# File 'lib/rest_up.rb', line 53

def request
  raise RestUpError, 'Invalid URL' unless uri.respond_to?(:request_uri)

  request = create_request(uri.request_uri)

  add_request_headers(request)
  add_request_body(request)

  request
end

#submit(request) ⇒ Object



74
75
76
# File 'lib/rest_up.rb', line 74

def submit(request)
  http.request request
end

#uriObject



78
79
80
81
# File 'lib/rest_up.rb', line 78

def uri
  return @uri if @uri
  @uri = URI.parse url
end

#urlObject



83
84
85
86
87
# File 'lib/rest_up.rb', line 83

def url
  return endpoint if endpoint.start_with?('http')

  @config.get(:url, '') + endpoint
end