Module: SwiftypeAppSearch::Request
- Included in:
- Client
- Defined in:
- lib/swiftype-app-search/request.rb
Instance Attribute Summary collapse
-
#last_request ⇒ Object
Returns the value of attribute last_request.
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #patch(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 Attribute Details
#last_request ⇒ Object
Returns the value of attribute last_request.
13 14 15 |
# File 'lib/swiftype-app-search/request.rb', line 13 def last_request @last_request end |
Instance Method Details
#delete(path, params = {}) ⇒ Object
31 32 33 |
# File 'lib/swiftype-app-search/request.rb', line 31 def delete(path, params={}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
15 16 17 |
# File 'lib/swiftype-app-search/request.rb', line 15 def get(path, params={}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
27 28 29 |
# File 'lib/swiftype-app-search/request.rb', line 27 def patch(path, params={}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
19 20 21 |
# File 'lib/swiftype-app-search/request.rb', line 19 def post(path, params={}) request(:post, path, params) end |
#put(path, params = {}) ⇒ Object
23 24 25 |
# File 'lib/swiftype-app-search/request.rb', line 23 def put(path, params={}) request(:put, path, params) end |
#request(method, path, params = {}) ⇒ Object
Construct and send a request to the API.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/swiftype-app-search/request.rb', line 38 def request(method, path, params = {}) Timeout.timeout(overall_timeout) do uri = URI.parse("#{api_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 http.set_debug_output(STDERR) if debug? 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 @last_request = request response = http.request(request) response_json = parse_response(response) case response when Net::HTTPSuccess return response_json when Net::HTTPBadRequest raise SwiftypeAppSearch::BadRequest, response_json when Net::HTTPUnauthorized raise SwiftypeAppSearch::InvalidCredentials, response_json when Net::HTTPNotFound raise SwiftypeAppSearch::NonExistentRecord, response_json when Net::HTTPForbidden raise SwiftypeAppSearch::Forbidden, response_json when Net::HTTPRequestEntityTooLarge raise SwiftypeAppSearch::RequestEntityTooLarge, response_json else raise SwiftypeAppSearch::UnexpectedHTTPException.new(response, response_json) end end end |