Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #33 from pusher/user-supplied-room-ids
Browse files Browse the repository at this point in the history
User supplied room ids
  • Loading branch information
vivangkumar authored Jul 4, 2019
2 parents d3eacc5 + 6d5c984 commit acaa6e7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/pusher/chatkit-server-ruby/compare/1.4.0...HEAD)
## [Unreleased](https://github.com/pusher/chatkit-server-ruby/compare/1.5.0...HEAD)

[1.5.0](https://github.com/pusher/chatkit-server-ruby/compare/1.4.0...1.5.0) - 2019-07-03

### Additions

- Support for user specified room IDs. Provide an `id` parameter to the
`create_room` method.

### Changes

- The `delete_message` method now *requires* a room ID parameter, `room_id`, and
the `id` parameter has been renamed to `message_id` to avoid ambiguity.

[1.4.0](https://github.com/pusher/chatkit-server-ruby/compare/1.3.0...1.4.0) - 2019-06-24

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pusher-chatkit-server (1.3.0)
pusher-chatkit-server (1.5.0)
pusher-platform (~> 0.11.2)

GEM
Expand Down Expand Up @@ -37,4 +37,4 @@ DEPENDENCIES
rspec

BUNDLED WITH
1.16.6
2.0.1
2 changes: 1 addition & 1 deletion chatkit.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'pusher-chatkit-server'
s.version = '1.4.0'
s.version = '1.5.0'
s.licenses = ['MIT']
s.summary = 'Pusher Chatkit Ruby SDK'
s.authors = ['Pusher']
Expand Down
11 changes: 8 additions & 3 deletions lib/chatkit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(options)
@api_instance = PusherPlatform::Instance.new(
base_options.merge({
service_name: 'chatkit',
service_version: 'v4'
service_version: 'v6'
})
)

Expand Down Expand Up @@ -238,6 +238,7 @@ def create_room(options)
private: options[:private] || false
}

body[:id] = options[:id] unless options[:id].nil?
body[:custom_data] = options[:custom_data] unless options[:custom_data].nil?

unless options[:user_ids].nil?
Expand Down Expand Up @@ -499,13 +500,17 @@ def send_message(options)
end

def delete_message(options)
if options[:id].nil?
if options[:message_id].nil?
raise Chatkit::MissingParameterError.new("You must provide the ID of the message you want to delete")
end

if options[:room_id].nil?
raise Chatkit::MissingParameterError.new("You must provide the ID of the room to which the message belongs")
end

api_request({
method: "DELETE",
path: "/messages/#{options[:id]}",
path: "/rooms/#{options[:room_id]}/messages/#{options[:message_id]}",
jwt: generate_su_token[:token]
})
end
Expand Down
47 changes: 26 additions & 21 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@
expect(room_res[:body][:name]).to eq 'my room'
expect(room_res[:body][:custom_data][:foo]).to eq 'bar'
end

it "a room id, creator_id and name are provided" do
user_id = SecureRandom.uuid
res = @chatkit.create_user({ id: user_id, name: 'Ham' })
expect(res[:status]).to eq 201

room_res = @chatkit.create_room({ id: "testroom", creator_id: user_id, name: 'my room' })
expect(room_res[:status]).to eq 201
expect(room_res[:body]).to have_key :id
expect(room_res[:body][:id]).to eq 'testroom'
expect(room_res[:body][:name]).to eq 'my room'
expect(room_res[:body][:private]).to be false
expect(room_res[:body][:member_user_ids]).to eq [user_id]
end
end
end

Expand Down Expand Up @@ -522,18 +536,12 @@
room_res = @chatkit.create_room({ creator_id: user_id, name: 'my room' })
expect(room_res[:status]).to eq 201

room_res_two = @chatkit.create_room({ creator_id: user_id, name: 'my room 2' })
expect(room_res_two[:status]).to eq 201

get_rooms_res = @chatkit.get_rooms()
expect(get_rooms_res[:status]).to eq 200
expect(get_rooms_res[:body].count).to eq 2
expect(get_rooms_res[:body].count).to eq 1
expect(get_rooms_res[:body][0][:id]).to eq room_res[:body][:id]
expect(get_rooms_res[:body][0][:name]).to eq 'my room'
expect(get_rooms_res[:body][0][:private]).to be false
expect(get_rooms_res[:body][1][:id]).to eq room_res_two[:body][:id]
expect(get_rooms_res[:body][1][:name]).to eq 'my room 2'
expect(get_rooms_res[:body][1][:private]).to be false
end

it "include_private is specified" do
Expand All @@ -548,25 +556,16 @@
})
expect(room_res[:status]).to eq 201

room_res_two = @chatkit.create_room({ creator_id: user_id, name: 'my room 2' })
expect(room_res_two[:status]).to eq 201

get_rooms_res = @chatkit.get_rooms()
expect(get_rooms_res[:status]).to eq 200
expect(get_rooms_res[:body].count).to eq 1
expect(get_rooms_res[:body][0][:id]).to eq room_res_two[:body][:id]
expect(get_rooms_res[:body][0][:name]).to eq 'my room 2'
expect(get_rooms_res[:body][0][:private]).to be false
expect(get_rooms_res[:body].count).to eq 0

get_rooms_with_private_res = @chatkit.get_rooms({ include_private: true })
expect(get_rooms_with_private_res[:status]).to eq 200
expect(get_rooms_with_private_res[:body].count).to eq 2
expect(get_rooms_with_private_res[:body].count).to eq 1
expect(get_rooms_with_private_res[:body][0][:id]).to eq room_res[:body][:id]
expect(get_rooms_with_private_res[:body][0][:name]).to eq 'my room'
expect(get_rooms_with_private_res[:body][0][:private]).to be true
expect(get_rooms_with_private_res[:body][1][:id]).to eq room_res_two[:body][:id]
expect(get_rooms_with_private_res[:body][1][:name]).to eq 'my room 2'
expect(get_rooms_with_private_res[:body][1][:private]).to be false
end

it "include_private and from_id are specified" do
Expand All @@ -584,15 +583,20 @@
room_res_two = @chatkit.create_room({ creator_id: user_id, name: 'my room 2' })
expect(room_res_two[:status]).to eq 201

if room_res[:body][:id] > room_res_two[:body][:id] then
# swap the room responses to match the order we expect them to be returned in
room_res_two, room_res = room_res, room_res_two
end

get_rooms_res_one = @chatkit.get_rooms({
include_private: true,
from_id: room_res[:body][:id]
})
expect(get_rooms_res_one[:status]).to eq 200
expect(get_rooms_res_one[:body].count).to eq 1
expect(get_rooms_res_one[:body][0][:id]).to eq room_res_two[:body][:id]
expect(get_rooms_res_one[:body][0][:name]).to eq 'my room 2'
expect(get_rooms_res_one[:body][0][:private]).to be false
expect(get_rooms_res_one[:body][0][:name]).to eq room_res_two[:body][:name]
expect(get_rooms_res_one[:body][0][:private]).to eq room_res_two[:body][:private]

get_rooms_res_two = @chatkit.get_rooms({
include_private: true,
Expand Down Expand Up @@ -1262,7 +1266,8 @@
expect(send_message_res[:status]).to eq 201

delete_messages_res = @chatkit.delete_message({
id: send_message_res[:body][:message_id]
message_id: send_message_res[:body][:message_id],
room_id: room_res[:body][:id]
})
expect(delete_messages_res[:status]).to eq 204
expect(delete_messages_res[:body]).to be_nil
Expand Down

0 comments on commit acaa6e7

Please sign in to comment.