Class: Candid::Events::V1::Client
- Inherits:
-
Object
- Object
- Candid::Events::V1::Client
- Defined in:
- lib/candid/events/v_1/client.rb
Instance Method Summary collapse
- #get(request_options: {}, **params) ⇒ Candid::Events::V1::Types::Event
- #initialize(client:, base_url: nil, environment: nil) ⇒ void constructor
-
#scan(request_options: {}, **params) ⇒ Candid::Events::V1::Types::EventScanPage
Scans the last 30 days of events.
Constructor Details
#initialize(client:, base_url: nil, environment: nil) ⇒ void
12 13 14 15 16 |
# File 'lib/candid/events/v_1/client.rb', line 12 def initialize(client:, base_url: nil, environment: nil) @client = client @base_url = base_url @environment = environment end |
Instance Method Details
#get(request_options: {}, **params) ⇒ Candid::Events::V1::Types::Event
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/candid/events/v_1/client.rb', line 76 def get(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "GET", path: "/api/events/v1/#{params[:event_id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::Events::V1::Types::Event.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#scan(request_options: {}, **params) ⇒ Candid::Events::V1::Types::EventScanPage
Scans the last 30 days of events. All results are sorted by created date, descending.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/candid/events/v_1/client.rb', line 34 def scan(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[page_token limit event_types created_before created_after] query_params = {} query_params["page_token"] = params[:page_token] if params.key?(:page_token) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["event_types"] = params[:event_types] if params.key?(:event_types) query_params["created_before"] = params[:created_before] if params.key?(:created_before) query_params["created_after"] = params[:created_after] if params.key?(:created_after) params.except(*query_param_names) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "GET", path: "/api/events/v1/", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::Events::V1::Types::EventScanPage.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |