Class: FastlyNsq::Http
- Inherits:
-
Object
- Object
- FastlyNsq::Http
- Defined in:
- lib/fastly_nsq/http.rb,
lib/fastly_nsq/http/nsqd.rb,
lib/fastly_nsq/http/nsqlookupd.rb
Overview
Adapter class for HTTP requests to NSQD
Defined Under Namespace
Classes: Nsqd, Nsqlookupd
Instance Method Summary collapse
- #get(data = nil) ⇒ Object
-
#initialize(uri:, cert_filename: ENV["NSQ_SSL_CERTIFICATE"], key_filename: ENV["NSQ_SSL_KEY"]) ⇒ Http
constructor
A new instance of Http.
- #post(data, body = nil) ⇒ Object
- #use_ssl ⇒ Object
Constructor Details
#initialize(uri:, cert_filename: ENV["NSQ_SSL_CERTIFICATE"], key_filename: ENV["NSQ_SSL_KEY"]) ⇒ Http
Returns a new instance of Http.
18 19 20 21 22 |
# File 'lib/fastly_nsq/http.rb', line 18 def initialize(uri:, cert_filename: ENV["NSQ_SSL_CERTIFICATE"], key_filename: ENV["NSQ_SSL_KEY"]) @uri = uri.is_a?(URI) ? uri : URI.parse(uri) @cert_filename = cert_filename @key_filename = key_filename end |
Instance Method Details
#get(data = nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/fastly_nsq/http.rb', line 24 def get(data = nil) if data params = URI.encode_www_form(data) uri.query = params end req = Net::HTTP::Get.new(uri.request_uri) http.request(req) end |
#post(data, body = nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/fastly_nsq/http.rb', line 33 def post(data, body = nil) params = URI.encode_www_form(data) uri.query = params req = Net::HTTP::Post.new(uri.request_uri) http.request(req, body) end |
#use_ssl ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fastly_nsq/http.rb', line 40 def use_ssl return unless can_use_ssl? http.use_ssl = true http.cert = cert http.key = key http.verify_mode = OpenSSL::SSL::VERIFY_NONE end |