Class: Datadog::CI::Transport::Adapters::Net
- Inherits:
-
Object
- Object
- Datadog::CI::Transport::Adapters::Net
- Defined in:
- lib/datadog/ci/transport/adapters/net.rb
Overview
Adapter for Net::HTTP
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #call(path:, payload:, headers:, verb:) ⇒ Object
-
#initialize(hostname:, port:, ssl:, timeout_seconds:) ⇒ Net
constructor
A new instance of Net.
- #open(&block) ⇒ Object
- #post(path:, payload:, headers:) ⇒ Object
Constructor Details
#initialize(hostname:, port:, ssl:, timeout_seconds:) ⇒ Net
Returns a new instance of Net.
21 22 23 24 25 26 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 21 def initialize(hostname:, port:, ssl:, timeout_seconds:) @hostname = hostname @port = port @timeout = timeout_seconds @ssl = ssl end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
15 16 17 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 15 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 15 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
15 16 17 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 15 def ssl @ssl end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
15 16 17 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 15 def timeout @timeout end |
Instance Method Details
#call(path:, payload:, headers:, verb:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 37 def call(path:, payload:, headers:, verb:) headers ||= {} # skip tracing for internal DD requests headers[Core::Transport::Ext::HTTP::HEADER_DD_INTERNAL_UNTRACED_REQUEST] = "1" if respond_to?(verb) send(verb, path: path, payload: payload, headers: headers) else raise "Unknown HTTP method [#{verb}]" end end |
#open(&block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 28 def open(&block) req = net_http_client.new(hostname, port) req.use_ssl = ssl req.open_timeout = req.read_timeout = timeout req.start(&block) end |
#post(path:, payload:, headers:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 49 def post(path:, payload:, headers:) post = ::Net::HTTP::Post.new(path, headers) post.body = payload # Connect and send the request http_response = open do |http| http.request(post) end # Build and return response Response.new(http_response) end |