Class: Thoom::RestUp
- Inherits:
-
Object
- Object
- Thoom::RestUp
- Defined in:
- lib/rest_up.rb
Overview
Makes the request
Instance Attribute Summary collapse
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#data ⇒ Object
Returns the value of attribute data.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#method ⇒ Object
Returns the value of attribute method.
Instance Method Summary collapse
- #http ⇒ Object
-
#initialize(config = nil) ⇒ RestUp
constructor
A new instance of RestUp.
- #request ⇒ Object
- #submit(request) ⇒ Object
- #uri ⇒ Object
- #url ⇒ Object
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
#cert ⇒ Object
Returns the value of attribute cert.
21 22 23 |
# File 'lib/rest_up.rb', line 21 def cert @cert end |
#data ⇒ Object
Returns the value of attribute data.
21 22 23 |
# File 'lib/rest_up.rb', line 21 def data @data end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
21 22 23 |
# File 'lib/rest_up.rb', line 21 def endpoint @endpoint end |
#headers ⇒ Object
Returns the value of attribute headers.
22 23 24 |
# File 'lib/rest_up.rb', line 22 def headers @headers end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
22 23 24 |
# File 'lib/rest_up.rb', line 22 def log @log end |
#method ⇒ Object
Returns the value of attribute method.
22 23 24 |
# File 'lib/rest_up.rb', line 22 def method @method end |
Instance Method Details
#http ⇒ Object
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 |
#request ⇒ Object
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 |
#uri ⇒ Object
78 79 80 81 |
# File 'lib/rest_up.rb', line 78 def uri return @uri if @uri @uri = URI.parse url end |
#url ⇒ Object
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 |