Class: Increase::Resources::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/increase/resources/events.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Events

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Events.

Parameters:



82
83
84
# File 'lib/increase/resources/events.rb', line 82

def initialize(client:)
  @client = client
end

Instance Method Details

#list(associated_object_id: nil, category: nil, created_at: nil, cursor: nil, limit: nil, request_options: {}) ⇒ Increase::Internal::Page<Increase::Models::Event>

Some parameter documentations has been truncated, see Models::EventListParams for more details.

List Events

Parameters:

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/increase/resources/events.rb', line 48

def list(params = {})
  parsed, options = Increase::EventListParams.dump_request(params)
  query = Increase::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "events",
    query: query,
    page: Increase::Internal::Page,
    model: Increase::Event,
    options: options
  )
end

#retrieve(event_id, request_options: {}) ⇒ Increase::Models::Event

Retrieve an Event

Parameters:

  • event_id (String)

    The identifier of the Event.

  • request_options (Increase::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



17
18
19
20
21
22
23
24
# File 'lib/increase/resources/events.rb', line 17

def retrieve(event_id, params = {})
  @client.request(
    method: :get,
    path: ["events/%1$s", event_id],
    model: Increase::Event,
    options: params[:request_options]
  )
end

#unwrap(payload, headers:, key: @client.webhook_secret) ⇒ Increase::Models::UnwrapWebhookEvent

Parameters:

  • payload (String)

    The raw webhook payload as a string

  • headers (Hash{String=>String})

    The raw HTTP headers that came with the payload

  • key (String, nil) (defaults to: @client.webhook_secret)

    The webhook signing key

Returns:



68
69
70
71
72
73
74
75
76
77
# File 'lib/increase/resources/events.rb', line 68

def unwrap(payload, headers:, key: @client.webhook_secret)
  if key.nil?
    raise ArgumentError.new("Cannot verify a webhook without a key on either the client's webhook_secret or passed in as an argument")
  end

  ::StandardWebhooks::Webhook.new(Base64.strict_encode64(key)).verify(payload, headers)

  parsed = JSON.parse(payload, symbolize_names: true)
  Increase::Internal::Type::Converter.coerce(Increase::Models::UnwrapWebhookEvent, parsed)
end