Class: Ncio::HttpClient
- Inherits:
-
Object
- Object
- Ncio::HttpClient
- Defined in:
- lib/ncio/http_client.rb
Overview
HttpClient provides a Net::HTTP instance pre-configured to communicate with the Puppet Node Classification Service. The client will return Ruby native objects where possible, parsing JSON responses from the service.
This client implements v1 of the Node Classification API.
Defined Under Namespace
Classes: ApiError
Constant Summary collapse
- OPTION_DEFAULTS =
{ host: Socket.gethostname, port: 4433, use_ssl: true, cert: ssldir + '/certs/pe-internal-orchestrator.pem', key: ssldir + '/private_keys/pe-internal-orchestrator.pem', cacert: ssldir + '/certs/ca.pem' }.freeze
Instance Attribute Summary collapse
-
#cacert ⇒ Object
readonly
Returns the value of attribute cacert.
-
#cert ⇒ Object
readonly
Returns the value of attribute cert.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#use_ssl ⇒ Object
readonly
Returns the value of attribute use_ssl.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ HttpClient
constructor
initialize a new HttpClient instance.
-
#request(req, body = nil) ⇒ Net::HTTPResponse
make a request, pass through to Net::HTTP#request.
-
#uri ⇒ URI
Provide a URL to the endpoint this client connects to.
Constructor Details
#initialize(opts = {}) ⇒ HttpClient
initialize a new HttpClient instance
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ncio/http_client.rb', line 56 def initialize(opts = {}) opts = OPTION_DEFAULTS.merge(opts) @use_ssl = opts[:use_ssl] @host = opts[:host] @port = opts[:port] @cert = opts[:cert] @key = opts[:key] @cacert = opts[:cacert] @protocol = use_ssl ? 'https' : 'http' end |
Instance Attribute Details
#cacert ⇒ Object (readonly)
Returns the value of attribute cacert.
19 20 21 |
# File 'lib/ncio/http_client.rb', line 19 def cacert @cacert end |
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
17 18 19 |
# File 'lib/ncio/http_client.rb', line 17 def cert @cert end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
14 15 16 |
# File 'lib/ncio/http_client.rb', line 14 def host @host end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
18 19 20 |
# File 'lib/ncio/http_client.rb', line 18 def key @key end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/ncio/http_client.rb', line 15 def port @port end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
20 21 22 |
# File 'lib/ncio/http_client.rb', line 20 def protocol @protocol end |
#use_ssl ⇒ Object (readonly)
Returns the value of attribute use_ssl.
16 17 18 |
# File 'lib/ncio/http_client.rb', line 16 def use_ssl @use_ssl end |
Instance Method Details
#request(req, body = nil) ⇒ Net::HTTPResponse
make a request, pass through to Net::HTTP#request
76 77 78 |
# File 'lib/ncio/http_client.rb', line 76 def request(req, body = nil) http.request(req, body) end |
#uri ⇒ URI
Provide a URL to the endpoint this client connects to. This is intended to construct URL's and add query parameters easily.
85 86 87 88 |
# File 'lib/ncio/http_client.rb', line 85 def uri return @uri if @uri @uri = URI("#{protocol}://#{host}:#{port}") end |