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: 10,
  max_retries: 2,
  retry_multiplier: 1.2,
  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.



19
20
21
22
23
24
# File 'lib/meilisearch/http_request.rb', line 19

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, 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, options = {})
  send_request(
    proc { |path, config| self.class.delete(path, config) },
    relative_path,
    config: {
      query_params: query_params,
      headers: remove_headers(@headers.dup.merge(options[:headers] || {}), 'Content-Type'),
      options: @options.merge(options),
      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 = {}, options = {})
  send_request(
    proc { |path, config| self.class.get(path, config) },
    relative_path,
    config: {
      query_params: query_params,
      headers: remove_headers(@headers.dup.merge(options[:headers] || {}), 'Content-Type'),
      options: @options.merge(options),
      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, options = {})
  send_request(
    proc { |path, config| self.class.patch(path, config) },
    relative_path,
    config: {
      query_params: query_params,
      body: body,
      headers: @headers.dup.merge(options[:headers] || {}),
      options: @options.merge(options),
      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, 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),
      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, options = {})
  send_request(
    proc { |path, config| self.class.put(path, config) },
    relative_path,
    config: {
      query_params: query_params,
      body: body,
      headers: @headers.dup.merge(options[:headers] || {}),
      options: @options.merge(options),
      method_type: :put
    }
  )
end