Class: Meilisearch::HTTPRequest
- Inherits:
-
Object
- Object
- Meilisearch::HTTPRequest
- Includes:
- HTTParty
- Defined in:
- lib/meilisearch/http_request.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ timeout: 10, max_retries: 2, retry_multiplier: 1.2, convert_body?: true }.freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #http_delete(relative_path = '', query_params = nil, options = {}) ⇒ Object
- #http_get(relative_path = '', query_params = {}, options = {}) ⇒ Object
- #http_patch(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
- #http_post(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
- #http_put(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
-
#initialize(url, api_key = nil, options = {}) ⇒ HTTPRequest
constructor
A new instance of HTTPRequest.
Constructor Details
#initialize(url, api_key = nil, options = {}) ⇒ HTTPRequest
Returns a new instance of HTTPRequest.
19 20 21 22 23 24 |
# File 'lib/meilisearch/http_request.rb', line 19 def initialize(url, api_key = nil, = {}) @base_url = url @api_key = api_key @options = DEFAULT_OPTIONS.merge() @headers = end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/meilisearch/http_request.rb', line 10 def headers @headers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/meilisearch/http_request.rb', line 10 def @options end |
Instance Method Details
#http_delete(relative_path = '', query_params = nil, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/meilisearch/http_request.rb', line 81 def http_delete(relative_path = '', query_params = nil, = {}) send_request( proc { |path, config| self.class.delete(path, config) }, relative_path, config: { query_params: query_params, headers: remove_headers(@headers.dup.merge([:headers] || {}), 'Content-Type'), options: @options.merge(), method_type: :delete } ) end |
#http_get(relative_path = '', query_params = {}, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/meilisearch/http_request.rb', line 26 def http_get(relative_path = '', query_params = {}, = {}) send_request( proc { |path, config| self.class.get(path, config) }, relative_path, config: { query_params: query_params, headers: remove_headers(@headers.dup.merge([:headers] || {}), 'Content-Type'), options: @options.merge(), method_type: :get } ) end |
#http_patch(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/meilisearch/http_request.rb', line 67 def http_patch(relative_path = '', body = nil, query_params = nil, = {}) send_request( proc { |path, config| self.class.patch(path, config) }, relative_path, config: { query_params: query_params, body: body, headers: @headers.dup.merge([:headers] || {}), options: @options.merge(), method_type: :patch } ) end |
#http_post(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/meilisearch/http_request.rb', line 39 def http_post(relative_path = '', body = nil, query_params = nil, = {}) send_request( proc { |path, config| self.class.post(path, config) }, relative_path, config: { query_params: query_params, body: body, headers: @headers.dup.merge([:headers] || {}), options: @options.merge(), method_type: :post } ) end |
#http_put(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/meilisearch/http_request.rb', line 53 def http_put(relative_path = '', body = nil, query_params = nil, = {}) send_request( proc { |path, config| self.class.put(path, config) }, relative_path, config: { query_params: query_params, body: body, headers: @headers.dup.merge([:headers] || {}), options: @options.merge(), method_type: :put } ) end |