Class: Skylight::Util::HTTP Private
- Includes:
- Logging
- Defined in:
- lib/skylight/util/http.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ErrorResponse, ReadResponseError, Response, StartError
Constant Summary collapse
- CONTENT_ENCODING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'content-encoding'.freeze
- CONTENT_LENGTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'content-length'.freeze
- CONTENT_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'content-type'.freeze
- ACCEPT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'Accept'.freeze
- X_VERSION_HDR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'x-skylight-agent-version'.freeze
- APPLICATION_JSON =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'application/json'.freeze
- AUTHORIZATION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'authorization'.freeze
- DEFLATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'deflate'.freeze
- GZIP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'gzip'.freeze
- READ_EXCEPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[Timeout::Error, EOFError]
Instance Attribute Summary collapse
- #authentication ⇒ Object private
- #host ⇒ Object readonly private
- #port ⇒ Object readonly private
Instance Method Summary collapse
- #get(endpoint, hdrs = {}) ⇒ Object private
-
#initialize(config, service = :auth, opts = {}) ⇒ HTTP
constructor
private
A new instance of HTTP.
- #post(endpoint, body, hdrs = {}) ⇒ Object private
Methods included from Logging
#debug, #error, #info, #log, #t, #trace, trace?, #warn
Constructor Details
#initialize(config, service = :auth, opts = {}) ⇒ HTTP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HTTP.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/skylight/util/http.rb', line 35 def initialize(config, service = :auth, opts = {}) @config = config unless url = config["#{service}_url"] raise ArgumentError, "no URL specified" end url = URI.parse(url) @ssl = url.scheme == 'https' @host = url.host @port = url.port if proxy_url = config[:proxy_url] proxy_url = URI.parse(proxy_url) @proxy_addr, @proxy_port = proxy_url.host, proxy_url.port @proxy_user, @proxy_pass = (proxy_url.userinfo || '').split(/:/) end @open_timeout = get_timeout(:connect, config, service, opts) @read_timeout = get_timeout(:read, config, service, opts) @deflate = config["#{service}_http_deflate"] @authentication = config[:'authentication'] end |
Instance Attribute Details
#authentication ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/skylight/util/http.rb', line 24 def authentication @authentication end |
#host ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/skylight/util/http.rb', line 25 def host @host end |
#port ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/skylight/util/http.rb', line 25 def port @port end |
Instance Method Details
#get(endpoint, hdrs = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 64 |
# File 'lib/skylight/util/http.rb', line 61 def get(endpoint, hdrs = {}) request = build_request(Net::HTTP::Get, endpoint, hdrs) execute(request) end |
#post(endpoint, body, hdrs = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 69 70 71 72 73 74 |
# File 'lib/skylight/util/http.rb', line 66 def post(endpoint, body, hdrs = {}) unless body.respond_to?(:to_str) hdrs[CONTENT_TYPE] = APPLICATION_JSON body = body.to_json end request = build_request(Net::HTTP::Post, endpoint, hdrs, body.bytesize) execute(request, body) end |