From 05d90ccee2fe397d81bb408b966a2be3b88c3bed Mon Sep 17 00:00:00 2001 From: Daniel Quanz Date: Mon, 5 Jun 2017 15:58:47 +0200 Subject: [PATCH 1/4] Upgrade Layer Version to 2.0 --- lib/layer/client.rb | 2 +- lib/layer/client/platform.rb | 2 +- spec/layer/client/platform_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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 From e2d8846123ac2e7374fbdd25d38b60740b299728 Mon Sep 17 00:00:00 2001 From: Daniel Quanz Date: Mon, 5 Jun 2017 16:10:46 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Remove=20=E2=80=98mode=E2=80=99=20attribute?= =?UTF-8?q?=20for=20DELETE=20/conversations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/layer/conversation.rb | 6 ++---- spec/layer/conversation_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/layer/conversation.rb b/lib/layer/conversation.rb index 602a367..7e749a7 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,7 @@ def created_at # # @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error def destroy - delete(mode: :all_participants) + delete({}) end # Deletes the conversation, removing it from the user's devices by default @@ -122,7 +121,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/spec/layer/conversation_spec.rb b/spec/layer/conversation_spec.rb index b25ead4..efac9a1 100644 --- a/spec/layer/conversation_spec.rb +++ b/spec/layer/conversation_spec.rb @@ -94,19 +94,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 From c4d34de7b5f6c2c554ad29217b8a65875200806b Mon Sep 17 00:00:00 2001 From: Daniel Quanz Date: Mon, 5 Jun 2017 16:12:38 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Use=20new=20BasicIdentity=20Format=20(1=20?= =?UTF-8?q?=E2=80=94>=20layer:///identities/1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/layer/conversation.rb | 4 ++++ spec/layer/announcement_spec.rb | 10 +++++++--- spec/layer/conversation_spec.rb | 18 +++++++++++++++++- spec/layer/message_spec.rb | 10 +++++++--- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/layer/conversation.rb b/lib/layer/conversation.rb index 7e749a7..fc12193 100644 --- a/lib/layer/conversation.rb +++ b/lib/layer/conversation.rb @@ -116,6 +116,10 @@ def destroy 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`) 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/conversation_spec.rb b/spec/layer/conversation_spec.rb index efac9a1..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' }, 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" => [ { From 61a9e0fa0675a41f2feae1b78a5ac1190e52843a Mon Sep 17 00:00:00 2001 From: Daniel Quanz Date: Mon, 5 Jun 2017 16:13:11 +0200 Subject: [PATCH 4/4] Bumps to version 0.8.0 --- lib/layer/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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