Class: MeiliSearch::HTTPRequest
- Inherits:
-
Object
- Object
- MeiliSearch::HTTPRequest
- Includes:
- HTTParty
- Defined in:
- lib/meilisearch/http_request.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ timeout: 1, max_retries: 0, 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) ⇒ Object
- #http_get(relative_path = '', query_params = {}) ⇒ Object
- #http_patch(relative_path = '', body = nil, query_params = nil) ⇒ Object
- #http_post(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
- #http_put(relative_path = '', body = nil, query_params = nil) ⇒ 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.
18 19 20 21 22 23 |
# File 'lib/meilisearch/http_request.rb', line 18 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) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/meilisearch/http_request.rb', line 76 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, 'Content-Type'), options: @options } ) end |
#http_get(relative_path = '', query_params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/meilisearch/http_request.rb', line 25 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, 'Content-Type'), options: @options } ) end |
#http_patch(relative_path = '', body = nil, query_params = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/meilisearch/http_request.rb', line 63 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, options: @options } ) end |
#http_post(relative_path = '', body = nil, query_params = nil, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/meilisearch/http_request.rb', line 37 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() } ) end |
#http_put(relative_path = '', body = nil, query_params = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/meilisearch/http_request.rb', line 50 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, options: @options } ) end |