Sha256: f361431adc154884507e914ad748628025cab2c9680914d96e8191805c6ff51b
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true module Wazuh module Sawyer module Request def get(path, options = {}) request(:get, path, options) end def post(path, options = {}) request(:post, path, options) end def put(path, options = {}) request(:put, path, options) end def delete(path, options = {}) request(:delete, path, options) end def offset_request(method, path, options = {}) items = [] data = send(method, path, options) 0.step(data.totalItems, 500) { |offset| options[:offset] = offset d = send(method, path, options) items.concat(d.items) } items end private def request(method, path, options) response = case method when :get, :delete connection.call(method, URI::Parser.new.escape(path), nil, {query: options}) when :post, :put data = options unless options.empty? connection.call(method, URI::Parser.new.escape(path), data) end return response.data.data if response.status == 200 error_message = "" if response.data.nil? # Error from a not wazuh api error_message = response.body else error_message = response.data.message end raise Wazuh::Api::Errors::WazuhError.new(error_message, response) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wazuh-ruby-client-0.2.7 | lib/wazuh/sawyer/request.rb |