Module: Elastic::SiteSearch::Request
- Included in:
- Client
- Defined in:
- lib/elastic/site-search/request.rb
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#poll(options = {}) ⇒ Object
Poll a block with backoff until a timeout is reached.
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
-
#request(method, path, params = {}) ⇒ Object
Construct and send a request to the API.
Instance Method Details
#delete(path, params = {}) ⇒ Object
29 30 31 |
# File 'lib/elastic/site-search/request.rb', line 29 def delete(path, params={}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
17 18 19 |
# File 'lib/elastic/site-search/request.rb', line 17 def get(path, params={}) request(:get, path, params) end |
#poll(options = {}) ⇒ Object
Poll a block with backoff until a timeout is reached.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elastic/site-search/request.rb', line 44 def poll(={}) timeout = [:timeout] || 10 delay = 0.05 Timeout.timeout(timeout) do while true res = yield return res if res sleep delay *= 2 end end end |
#post(path, params = {}) ⇒ Object
21 22 23 |
# File 'lib/elastic/site-search/request.rb', line 21 def post(path, params={}) request(:post, path, params) end |
#put(path, params = {}) ⇒ Object
25 26 27 |
# File 'lib/elastic/site-search/request.rb', line 25 def put(path, params={}) request(:put, path, params) end |
#request(method, path, params = {}) ⇒ Object
Construct and send a request to the API.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/elastic/site-search/request.rb', line 59 def request(method, path, params={}) Timeout.timeout(overall_timeout) do uri = URI.parse("#{Elastic::SiteSearch.endpoint}#{path}") request = build_request(method, uri, params) if proxy proxy_parts = URI.parse(proxy) http = Net::HTTP.new(uri.host, uri.port, proxy_parts.host, proxy_parts.port, proxy_parts.user, proxy_parts.password) else http = Net::HTTP.new(uri.host, uri.port) end http.open_timeout = open_timeout http.read_timeout = overall_timeout if uri.scheme == 'https' http.use_ssl = true # st_ssl_verify_none provides a means to disable SSL verification for debugging purposes. An example # is Charles, which uses a self-signed certificate in order to inspect https traffic. This will # not be part of this client's public API, this is more of a development enablement option http.verify_mode = ENV['st_ssl_verify_none'] == 'true' ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER http.ca_file = File.join(File.dirname(__FILE__), '../..', 'data', 'ca-bundle.crt') http.ssl_timeout = open_timeout end response = http.request(request) handle_errors(response) JSON.parse(response.body) if response.body && response.body.strip != '' end end |