Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM
activesupport (>= 6.1.0)
ffi (1.17.2)
ffi (1.17.2-arm64-darwin)
ffi (1.17.2-x86_64-linux-gnu)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
Expand Down Expand Up @@ -101,6 +102,8 @@ GEM
minitest (5.26.1)
nokogiri (1.18.10-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.10-x86_64-linux-gnu)
racc (~> 1.4)
parallel (1.27.0)
parser (3.3.10.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -216,6 +219,7 @@ GEM
PLATFORMS
arm64-darwin-23
arm64-darwin-24
x86_64-linux

DEPENDENCIES
dotenv-rails
Expand Down
10 changes: 8 additions & 2 deletions lib/chatkit/conversation/response/thread/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Response
class Thread
# Represents an item in a thread.
class Item
REQUIRED_ATTRIBUTES = %w[id thread_id created_at].freeze

# @!attribute [rw] id
# @return [String]
attr_accessor :id
Expand Down Expand Up @@ -76,6 +78,10 @@ class << self
# @param data [Hash] The item data from the event
# @return [Item]
def from_event(data)
missing_attrs = REQUIRED_ATTRIBUTES.reject { |attr| data.key?(attr) }
raise ArgumentError, "Missing required attributes: #{missing_attrs.join(', ')}" unless missing_attrs.empty?


new(
id: data["id"],
thread_id: data["thread_id"],
Expand Down Expand Up @@ -118,7 +124,7 @@ def update_from_event!(data)
if @workflow
@workflow.update!(data["workflow"])
else
@workflow = parse_workflow_data(data)
@workflow = self.class.parse_workflow_data(data)
end
end

Expand All @@ -143,7 +149,7 @@ def process_update!(update_data)
# Parse workflow data from event
# @param data [Hash] The event data
# @return [Workflow, nil]
def parse_workflow_data(data)
def self.parse_workflow_data(data)
return nil unless data["workflow"]

Workflow.from_event(data["workflow"])
Expand Down
8 changes: 4 additions & 4 deletions lib/chatkit/files/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class Response
attr_accessor :upload_url

# @param id [String] - The file ID.
# @param mime_typee [String] - The MIME type of the file.
# @param mime_type [String] - The MIME type of the file.
# @param name [String] - The name of the file.
# @param preview_url [String] - The preview URL of the file.
# @param type [String] - The type of the file.
# @param upload_url [String] - The upload URL of the file.
def initialize(id:, mime_typee:, name:, preview_url:, type:, upload_url:)
def initialize(id:, mime_type:, name:, preview_url:, type:, upload_url:)
@id = id
@mime_type = mime_typee
@mime_type = mime_type
@name = name
@preview_url = preview_url
@type = type
Expand All @@ -47,7 +47,7 @@ class << self
def deserialize(data)
new(
id: data["id"],
mime_typee: data["mime_type"],
mime_type: data["mime_type"],
name: data["name"],
preview_url: data["preview_url"],
type: data["type"],
Expand Down
4 changes: 4 additions & 0 deletions lib/chatkit/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module Defaults
ENABLED = true
end

# @!attribute [r] client
# @return [Ruby::ChatKit::Client] The ChatKit client instance.
attr_reader :client

# @!attribute [rw] user_id
# @return [String] The ID of the user.
attr_accessor :user_id
Expand Down
18 changes: 9 additions & 9 deletions spec/chatkit/files/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def sample_response_data
it "initializes with all provided values" do
response = described_class.new(
id: "file_test123",
mime_typee: "application/pdf",
mime_type: "application/pdf",
name: "document.pdf",
preview_url: "https://example.com/preview/file_test123",
type: "document",
Expand All @@ -40,7 +40,7 @@ def sample_response_data
it "raises an ArgumentError when id is missing" do
expect do
described_class.new(
mime_typee: "application/pdf",
mime_type: "application/pdf",
name: "document.pdf",
preview_url: "https://example.com/preview",
type: "document",
Expand All @@ -49,7 +49,7 @@ def sample_response_data
end.to raise_error(ArgumentError, /missing keyword.*id/)
end

it "raises an ArgumentError when mime_typee is missing" do
it "raises an ArgumentError when mime_type is missing" do
expect do
described_class.new(
id: "file_test123",
Expand All @@ -58,14 +58,14 @@ def sample_response_data
type: "document",
upload_url: "https://example.com/upload"
)
end.to raise_error(ArgumentError, /missing keyword.*mime_typee/)
end.to raise_error(ArgumentError, /missing keyword.*mime_type/)
end

it "raises an ArgumentError when name is missing" do
expect do
described_class.new(
id: "file_test123",
mime_typee: "application/pdf",
mime_type: "application/pdf",
preview_url: "https://example.com/preview",
type: "document",
upload_url: "https://example.com/upload"
Expand All @@ -77,7 +77,7 @@ def sample_response_data
expect do
described_class.new(
id: "file_test123",
mime_typee: "application/pdf",
mime_type: "application/pdf",
name: "document.pdf",
type: "document",
upload_url: "https://example.com/upload"
Expand All @@ -89,7 +89,7 @@ def sample_response_data
expect do
described_class.new(
id: "file_test123",
mime_typee: "application/pdf",
mime_type: "application/pdf",
name: "document.pdf",
preview_url: "https://example.com/preview",
upload_url: "https://example.com/upload"
Expand All @@ -101,7 +101,7 @@ def sample_response_data
expect do
described_class.new(
id: "file_test123",
mime_typee: "application/pdf",
mime_type: "application/pdf",
name: "document.pdf",
preview_url: "https://example.com/preview",
type: "document"
Expand Down Expand Up @@ -216,7 +216,7 @@ def sample_response_data
let(:response) do
described_class.new(
id: "file_test123",
mime_typee: "image/jpeg",
mime_type: "image/jpeg",
name: "photo.jpg",
preview_url: "https://example.com/preview/file_test123",
type: "image",
Expand Down