Module: Wazuh::Sawyer::Request

Included in:
Client
Defined in:
lib/wazuh/sawyer/request.rb

Constant Summary collapse

MAX_ITEM_NUM =
500

Instance Method Summary collapse

Instance Method Details

#delete(path, options = {}) ⇒ Object



19
20
21
# File 'lib/wazuh/sawyer/request.rb', line 19

def delete(path, options = {})
  request(:delete, path, options).data
end

#get(path, options = {}) ⇒ Object



7
8
9
# File 'lib/wazuh/sawyer/request.rb', line 7

def get(path, options = {})
  request(:get, path, options).data
end

#offset_request(method, path, options = {}) ⇒ Object

The response format is different for v3 and v4. In v3, it is a camel case like ‘totalItems` and `items`, but in v4, it is snake case like total_affected_items. offset_request will fill this gap. This function is used if there are `affected_items` or `items` in the response.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wazuh/sawyer/request.rb', line 28

def offset_request(method, path, options = {})
  items = []
  data = send(method, path, options)
  total_items = api_version == 3 ? data.totalItems : data.total_affected_items

  return data.items if (api_version == 3 && data.items.size == data.totalItems)
  return data.affected_items if (api_version == 4 && data.affected_items.size == data.total_affected_items)

  0.step(total_items, MAX_ITEM_NUM) do |offset|
    options[:offset] = offset
    d = send(method, path, options)
    _items = api_version == 3 ? d.items : d.affected_items
    items.concat(_items)
  end

  items
end

#post(path, options = {}) ⇒ Object



11
12
13
# File 'lib/wazuh/sawyer/request.rb', line 11

def post(path, options = {})
  request(:post, path, options).data
end

#put(path, options = {}) ⇒ Object



15
16
17
# File 'lib/wazuh/sawyer/request.rb', line 15

def put(path, options = {})
  request(:put, path, options).data
end