Sha256: ac79fc0ade8ee6083242672ba5667c7f1855caf1d51b24e498e6f822c77de00f

Contents?: true

Size: 1.92 KB

Versions: 22

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true
# typed: true

module WorkOS
  # The Connection class provides a lightweight wrapper around
  # a WorkOS Connection resource. This class is not meant to be instantiated
  # in user space, and is instantiated internally but exposed.
  # Note: status is deprecated - use state instead
  class Connection
    include HashProvider
    extend T::Sig

    attr_accessor :id, :name, :connection_type, :domains, :organization_id,
                  :state, :status, :created_at, :updated_at

    # rubocop:disable Metrics/AbcSize
    sig { params(json: String).void }
    def initialize(json)
      raw = parse_json(json)

      @id = T.let(raw.id, String)
      @name = T.let(raw.name, String)
      @connection_type = T.let(raw.connection_type, String)
      @domains = T.let(raw.domains, Array)
      @organization_id = raw.organization_id
      @state = T.let(raw.state, String)
      @status = T.let(raw.status, String)
      @created_at = T.let(raw.created_at, String)
      @updated_at = T.let(raw.updated_at, String)
    end
    # rubocop:enable Metrics/AbcSize

    def to_json(*)
      {
        id: id,
        name: name,
        connection_type: connection_type,
        domains: domains,
        organization_id: organization_id,
        state: state,
        status: status,
        created_at: created_at,
        updated_at: updated_at,
      }
    end

    private

    sig { params(json_string: String).returns(WorkOS::Types::ConnectionStruct) }
    def parse_json(json_string)
      hash = JSON.parse(json_string, symbolize_names: true)

      WorkOS::Types::ConnectionStruct.new(
        id: hash[:id],
        name: hash[:name],
        connection_type: hash[:connection_type],
        domains: hash[:domains],
        organization_id: hash[:organization_id],
        state: hash[:state],
        status: hash[:status],
        created_at: hash[:created_at],
        updated_at: hash[:updated_at],
      )
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
workos-4.1.0 lib/workos/connection.rb
workos-4.0.0 lib/workos/connection.rb
workos-3.1.0 lib/workos/connection.rb
workos-3.0.0 lib/workos/connection.rb
workos-2.17.0 lib/workos/connection.rb
workos-2.16.0 lib/workos/connection.rb
workos-2.15.0 lib/workos/connection.rb
workos-2.14.0 lib/workos/connection.rb
workos-2.13.0 lib/workos/connection.rb
workos-2.12.1 lib/workos/connection.rb
workos-2.12.0 lib/workos/connection.rb
workos-2.11.0 lib/workos/connection.rb
workos-2.10.0 lib/workos/connection.rb
workos-2.9.0 lib/workos/connection.rb
workos-2.8.0 lib/workos/connection.rb
workos-2.7.0 lib/workos/connection.rb
workos-2.6.0 lib/workos/connection.rb
workos-2.5.1 lib/workos/connection.rb
workos-2.5.0 lib/workos/connection.rb
workos-2.4.0 lib/workos/connection.rb