Sha256: a92fd17d2310b03d9c2973544550cd2e57b117f9316972585ab6e55a0e023d81

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true
# typed: true

module WorkOS
  # The Webhook class provides a lightweight wrapper around
  # a WorkOS Webhook resource. This class is not meant to be instantiated
  # in user space, and is instantiated internally but exposed.
  class Webhook
    include HashProvider
    extend T::Sig

    attr_accessor :id, :event, :data, :created_at

    sig { params(json: String).void }
    def initialize(json)
      raw = parse_json(json)

      @id = T.let(raw.id, String)
      @event = T.let(raw.event, String)
      @data = raw.data
      @created_at = T.let(raw.created_at, String)
    end

    def to_json(*)
      {
        id: id,
        event: event,
        data: data,
        created_at: created_at,
      }
    end

    private

    sig do
      params(
        json_string: String,
      ).returns(WorkOS::Types::WebhookStruct)
    end
    def parse_json(json_string)
      hash = JSON.parse(json_string, symbolize_names: true)

      WorkOS::Types::WebhookStruct.new(
        id: hash[:id],
        event: hash[:event],
        data: hash[:data],
        created_at: hash[:created_at],
      )
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
workos-4.1.0 lib/workos/webhook.rb
workos-4.0.0 lib/workos/webhook.rb
workos-3.1.0 lib/workos/webhook.rb
workos-3.0.0 lib/workos/webhook.rb
workos-2.17.0 lib/workos/webhook.rb
workos-2.16.0 lib/workos/webhook.rb
workos-2.15.0 lib/workos/webhook.rb
workos-2.14.0 lib/workos/webhook.rb
workos-2.13.0 lib/workos/webhook.rb