Class: S3Search::Client
- Inherits:
-
Object
- Object
- S3Search::Client
- Includes:
- API::Documents, API::Searches, API::Stats
- Defined in:
- lib/s3search/client.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #_delete(path, params = {}) ⇒ Object
- #_get(path, params = {}) ⇒ Object
- #_post(path, params = {}) ⇒ Object
- #_put(path, params = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #request(method, path, params) ⇒ Object
Methods included from API::Stats
Methods included from API::Searches
Methods included from API::Documents
#create, #create_many, #delete, #get, #get_all, #update
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/s3search/client.rb', line 20 def initialize @url = ENV['S3SEARCH_URL'] || 'https://us-east-1.s3search.io' @http = Faraday.new(url: @url, ssl: {verify: false}) do |builder| builder.response :mashify builder.response :json, :content_type => /\bjson$/ builder.request :json builder.request :basic_auth, ENV['S3SEARCH_API_KEY'], ENV['S3SEARCH_API_SECRET'] builder.[:read_timeout] = 4 builder.[:open_timeout] = 2 builder.adapter :excon end @http.headers = { accept: 'application/json', user_agent: "S3Search Ruby Gem #{S3Search::VERSION}", "Content-Type" => "application/json" } @logger = Logger.new(STDOUT) # 0=DEBUG, 1=INFO, 2=WARN, 3=ERROR, 4=FATAL @logger.level = ENV['S3SEARCH_LOG_LEVEL'].try(:to_i) || 2 @logger.formatter = proc do |severity, datetime, progname, msg| "[S3Search][#{severity}]: #{msg}\n" end end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
18 19 20 |
# File 'lib/s3search/client.rb', line 18 def http @http end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
18 19 20 |
# File 'lib/s3search/client.rb', line 18 def logger @logger end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
18 19 20 |
# File 'lib/s3search/client.rb', line 18 def url @url end |
Instance Method Details
#_delete(path, params = {}) ⇒ Object
48 49 50 |
# File 'lib/s3search/client.rb', line 48 def _delete path, params={} request :delete, path, params end |
#_get(path, params = {}) ⇒ Object
52 53 54 |
# File 'lib/s3search/client.rb', line 52 def _get path, params={} request :get, path, params end |
#_post(path, params = {}) ⇒ Object
56 57 58 |
# File 'lib/s3search/client.rb', line 56 def _post path, params={} request :post, path, params end |
#_put(path, params = {}) ⇒ Object
60 61 62 |
# File 'lib/s3search/client.rb', line 60 def _put path, params={} request :put, path, params end |
#request(method, path, params) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/s3search/client.rb', line 64 def request method, path, params response = http.send(method, path, params) case response.status when 200..299 response.body when 404, 410 raise RequestError::NotFound.new(response) when 401 raise RequestError::Unauthorized.new(response) else raise RequestError.new(response) end end |