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
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#offset_request(method, path, options = {}) ⇒ Object
The response format is different for v3 and v4.
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
Instance Method Details
#delete(path, options = {}) ⇒ Object
19 20 21 |
# File 'lib/wazuh/sawyer/request.rb', line 19 def delete(path, = {}) request(:delete, path, ).data end |
#get(path, options = {}) ⇒ Object
7 8 9 |
# File 'lib/wazuh/sawyer/request.rb', line 7 def get(path, = {}) request(:get, path, ).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, = {}) items = [] data = send(method, path, ) 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| [:offset] = offset d = send(method, path, ) _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, = {}) request(:post, path, ).data end |
#put(path, options = {}) ⇒ Object
15 16 17 |
# File 'lib/wazuh/sawyer/request.rb', line 15 def put(path, = {}) request(:put, path, ).data end |