Module: SwiftypeEnterprise::Request
- Included in:
- Client
- Defined in:
- lib/swiftype-enterprise/request.rb
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #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
20 21 22 |
# File 'lib/swiftype-enterprise/request.rb', line 20 def delete(path, params={}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
8 9 10 |
# File 'lib/swiftype-enterprise/request.rb', line 8 def get(path, params={}) request(:get, path, params) end |
#post(path, params = {}) ⇒ Object
12 13 14 |
# File 'lib/swiftype-enterprise/request.rb', line 12 def post(path, params={}) request(:post, path, params) end |
#put(path, params = {}) ⇒ Object
16 17 18 |
# File 'lib/swiftype-enterprise/request.rb', line 16 def put(path, params={}) request(:put, path, params) end |
#request(method, path, params = {}) ⇒ Object
Construct and send a request to the API.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/swiftype-enterprise/request.rb', line 27 def request(method, path, params = {}) Timeout.timeout(overall_timeout) do uri = URI.parse("#{SwiftypeEnterprise.endpoint}#{path}") request = build_request(method, uri, params) http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = open_timeout http.read_timeout = overall_timeout if uri.scheme == 'https' http.use_ssl = true http.verify_mode = 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 |