diff --git a/lib/layer/client.rb b/lib/layer/client.rb index 2907cbe..e1f3f7b 100644 --- a/lib/layer/client.rb +++ b/lib/layer/client.rb @@ -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) diff --git a/lib/layer/client/platform.rb b/lib/layer/client/platform.rb index 79da4bf..0a85370 100644 --- a/lib/layer/client/platform.rb +++ b/lib/layer/client/platform.rb @@ -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 diff --git a/lib/layer/conversation.rb b/lib/layer/conversation.rb index 602a367..fc12193 100644 --- a/lib/layer/conversation.rb +++ b/lib/layer/conversation.rb @@ -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 @@ -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 @@ -114,7 +113,11 @@ 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 @@ -122,7 +125,6 @@ def destroy # @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 diff --git a/lib/layer/version.rb b/lib/layer/version.rb index cc66c29..a92be4d 100644 --- a/lib/layer/version.rb +++ b/lib/layer/version.rb @@ -1,3 +1,3 @@ module Layer - VERSION = '0.7.2' + VERSION = '0.8.0' end diff --git a/spec/layer/announcement_spec.rb b/spec/layer/announcement_spec.rb index f6a29fd..92cf5dd 100644 --- a/spec/layer/announcement_spec.rb +++ b/spec/layer/announcement_spec.rb @@ -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' => [ { diff --git a/spec/layer/client/platform_spec.rb b/spec/layer/client/platform_spec.rb index 39a49e9..b5a1107 100644 --- a/spec/layer/client/platform_spec.rb +++ b/spec/layer/client/platform_spec.rb @@ -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 diff --git a/spec/layer/conversation_spec.rb b/spec/layer/conversation_spec.rb index b25ead4..95da676 100644 --- a/spec/layer/conversation_spec.rb +++ b/spec/layer/conversation_spec.rb @@ -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' }, @@ -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 diff --git a/spec/layer/message_spec.rb b/spec/layer/message_spec.rb index 1027b9e..0e80f01 100644 --- a/spec/layer/message_spec.rb +++ b/spec/layer/message_spec.rb @@ -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" => [ {