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.
23 24 25 26 27 28 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 23 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.
17 18 19 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 17 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
17 18 19 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 17 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
17 18 19 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 17 def ssl @ssl end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 17 def timeout @timeout end |
Instance Method Details
#call(path:, payload:, headers:, verb:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 39 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
30 31 32 33 34 35 36 37 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 30 def open(&block) req = NetHttpClient.original_net_http.new(hostname, port) req.use_ssl = ssl req.open_timeout = req.read_timeout = timeout req.start(&block) end |
#post(path:, payload:, headers:) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 51 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 |