Skip to content

Commit 0f58b57

Browse files
authored
Add custom command support (#47)
1 parent a7794cc commit 0f58b57

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

lib/stream-chat/client.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,26 @@ def check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil)
352352
post('check_sqs', data: { sqs_key: sqs_key, sqs_secret: sqs_secret, sqs_url: sqs_url })
353353
end
354354

355+
def create_command(command)
356+
post('commands', data: command)
357+
end
358+
359+
def get_command(name)
360+
get("commands/#{name}")
361+
end
362+
363+
def update_command(name, command)
364+
put("commands/#{name}", data: command)
365+
end
366+
367+
def delete_command(name)
368+
delete("commands/#{name}")
369+
end
370+
371+
def list_commands
372+
get('commands')
373+
end
374+
355375
private
356376

357377
def get_default_params
@@ -364,8 +384,8 @@ def get_user_agent
364384

365385
def get_default_headers
366386
{
367-
"Content-Type": 'application/json',
368-
"X-Stream-Client": get_user_agent
387+
'Content-Type': 'application/json',
388+
'X-Stream-Client': get_user_agent
369389
}
370390
end
371391

spec/client_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,39 @@
394394
expect(resp['status']).to eq 'error'
395395
expect(resp['error']).to include 'invalid SQS url'
396396
end
397+
398+
describe 'custom commands' do
399+
before(:all) do
400+
@cmd = SecureRandom.uuid
401+
end
402+
403+
it 'create a command' do
404+
cmd = @client.create_command({ name: @cmd, description: 'I am testing' })['command']
405+
expect(cmd['name']).to eq @cmd
406+
expect(cmd['description']).to eq 'I am testing'
407+
end
408+
409+
it 'get that command' do
410+
cmd = @client.get_command(@cmd)
411+
expect(cmd['name']).to eq @cmd
412+
expect(cmd['description']).to eq 'I am testing'
413+
end
414+
415+
it 'update that command' do
416+
cmd = @client.update_command(@cmd, { description: 'I tested' })['command']
417+
expect(cmd['name']).to eq @cmd
418+
expect(cmd['description']).to eq 'I tested'
419+
end
420+
421+
it 'delete that command' do
422+
@client.delete_command(@cmd)
423+
end
424+
425+
it 'list commands' do
426+
cmds = @client.list_commands['commands']
427+
cmds.each do |cmd|
428+
expect(cmd['name']).not_to eq @cmd
429+
end
430+
end
431+
end
397432
end

0 commit comments

Comments
 (0)