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
2 changes: 1 addition & 1 deletion lib/layer/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def request(method, url, payload = {}, headers = {})
url = "https://api.layer.com#{url}" unless url.start_with?('https://api.layer.com')

headers = {
'Accept' => 'application/vnd.layer+json; version=1.0',
'Accept' => 'application/vnd.layer+json; version=2.0',
'Content-Type' => 'application/json',
'If-None-Match' => SecureRandom.uuid
}.merge(headers)
Expand Down
2 changes: 1 addition & 1 deletion lib/layer/client/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(app_id = Layer::Client.app_id, token = Layer::Client.token)

def request(method, url, payload = {}, headers = {})
url = "https://api.layer.com/apps/#{app_id}#{url}" unless url.start_with?('https://api.layer.com')
headers['Accept'] ||= 'application/vnd.layer+json; version=1.1'
headers['Accept'] ||= 'application/vnd.layer+json; version=2.0'
headers['Authorization'] ||= "Bearer #{token}"

super
Expand Down
10 changes: 6 additions & 4 deletions lib/layer/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Conversation < Resource
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
def self.delete(id, options = {}, client = self.client)
id = Layer::Client.normalize_id(id)
options = { mode: :my_devices }.merge(options)
client.delete("#{url}/#{id}", {}, { params: options })
end

Expand All @@ -48,7 +47,7 @@ def self.delete(id, options = {}, client = self.client)
# @param client [Layer::Client] the client to use to make this request
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
def self.destroy(id, client = self.client)
delete(id, { mode: :all_participants }, client)
delete(id, {}, client)
end

# Returns the conversations messages
Expand Down Expand Up @@ -114,15 +113,18 @@ def created_at
#
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
def destroy
delete(mode: :all_participants)
delete({})
end

def participants=(participants)
super(participants.map{|p| "layer:///identities/#{p}"})
end

# Deletes the conversation, removing it from the user's devices by default
#
# @param options [Hash] the options for the delete request (REST API only: `leave: true/false`, `mode: all_participants/my_devices`)
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
def delete(options = {})
options = { mode: :my_devices }.merge(options)
client.delete(url, {}, { params: options })
end

Expand Down
2 changes: 1 addition & 1 deletion lib/layer/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Layer
VERSION = '0.7.2'
VERSION = '0.8.0'
end
10 changes: 7 additions & 3 deletions spec/layer/announcement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
'sent_at' => '2015-06-19T11:00:00Z',
'id' => 'layer:///announcements/announcement_id',
'recipients' => [
'1',
'2'
'layer:///identities/1',
'layer:///identities/2'
],
'sender' => {
'name'=>'test'
'id' => 'layer:///identities/1234',
'url' => 'https://api.layer.com/identities/1234',
'user_id' => '1234',
'display_name' => 'One Two Three Four',
'avatar_url' => 'https://mycompany.co/images/1234.png'
},
'parts' => [
{
Expand Down
2 changes: 1 addition & 1 deletion spec/layer/client/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

it 'should set the Accept header' do
expect(RestClient::Request).to have_received(:execute)
.with(hash_including(headers: hash_including('Accept' => 'application/vnd.layer+json; version=1.1')))
.with(hash_including(headers: hash_including('Accept' => 'application/vnd.layer+json; version=2.0')))
end

it 'should set the Content-Type header' do
Expand Down
24 changes: 20 additions & 4 deletions spec/layer/conversation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@
let(:response) do
{
'url' => 'https://api.layer.com/apps/default_app_id/conversations/conversation_id',
'participants' => ['1', '2'],
'messages_url' => 'https://api.layer.com/apps/default_app_id/conversations/conversation_id/messages',
'participants' => [
{
'id' => 'layer:///identities/1',
'url' => 'https://api.layer.com/identities/1',
'user_id' => '1',
'display_name' => 'One',
'avatar_url' => 'https://mycompany.co/images/1.png'
},
{
'id' => 'layer:///identities/2',
'url' => 'https://api.layer.com/identities/2',
'user_id' => '2',
'display_name' => 'Two',
'avatar_url' => 'https://mycompany.co/images/2.png'
}
],
'id' => 'layer:///conversations/conversation_id',
'distinct' => false,
'metadata' => { 'foo' => 'bar' },
Expand Down Expand Up @@ -94,19 +110,19 @@

describe '#delete' do
it 'should delete the conversation' do
expect(client).to receive(:delete).with(subject.url, {}, { params: { mode: :my_devices } })
expect(client).to receive(:delete).with(subject.url, {}, { params: {} })
subject.delete
end

it 'should delete the conversation and respect the leave parameter' do
expect(client).to receive(:delete).with(subject.url, {}, { params: { mode: :my_devices, leave: true } })
expect(client).to receive(:delete).with(subject.url, {}, { params: { leave: true } })
subject.delete(leave: true)
end
end

describe '#destroy' do
it 'should destroy the conversation' do
expect(client).to receive(:delete).with(subject.url, {}, { params: { mode: :all_participants } })
expect(client).to receive(:delete).with(subject.url, {}, { params: {} })
subject.destroy
end
end
Expand Down
10 changes: 7 additions & 3 deletions spec/layer/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
"sent_at" => "2015-06-19T11:00:00Z",
"id" => "layer:///messages/message_id",
"recipient_status" => {
"1" => "sent",
"2" => "sent"
"layer:///identities/1" => "sent",
"layer:///identities/2" => "read"
},
"sender" => {
"name"=>"test"
'id' => 'layer:///identities/2',
'url' => 'https://api.layer.com/identities/2',
'user_id' => '2',
'display_name' => 'Two',
'avatar_url' => 'https://mycompany.co/images/2.png'
},
"parts" => [
{
Expand Down