Class: MeiliSearch::HTTPRequest

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/meilisearch/http_request.rb

Direct Known Subclasses

Client, Index, Task

Constant Summary collapse

DEFAULT_OPTIONS =
{
  timeout: 1,
  max_retries: 0,
  convert_body?: true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @base_url = url
  @api_key = api_key
  @options = DEFAULT_OPTIONS.merge(options)
  @headers = build_default_options_headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/meilisearch/http_request.rb', line 10

def headers
  @headers
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/meilisearch/http_request.rb', line 10

def options
  @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, options = {})
  send_request(
    proc { |path, config| self.class.post(path, config) },
    relative_path,
    config: {
      query_params: query_params,
      body: body,
      headers: @headers.dup.merge(options[:headers] || {}),
      options: @options.merge(options)
    }
  )
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