From e3d11a7127408a7139d1fe9d01619134d9c41b15 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 15 Dec 2020 10:20:25 +0100 Subject: [PATCH] Support updating customer emails https://developer.helpscout.com/mailbox-api/endpoints/customers/emails/update/ --- lib/help_scout/customer.rb | 6 ++++++ spec/integration/customer_spec.rb | 14 +++++++++++++- spec/shared_examples/integration/listable.rb | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/help_scout/customer.rb b/lib/help_scout/customer.rb index b371ae8..0d501dc 100644 --- a/lib/help_scout/customer.rb +++ b/lib/help_scout/customer.rb @@ -47,5 +47,11 @@ def initialize(params = {}) @hrefs = HelpScout::Util.map_links(params[:_links]) end + + def update_email(email_id, new_email, type: :other) + email_path = "#{URI.parse(hrefs[:self]).path}/emails/#{email_id}" + HelpScout.api.put(email_path, { type: type, value: new_email }) + true + end end end diff --git a/spec/integration/customer_spec.rb b/spec/integration/customer_spec.rb index c4f1be2..13f4da2 100644 --- a/spec/integration/customer_spec.rb +++ b/spec/integration/customer_spec.rb @@ -10,10 +10,22 @@ include_examples 'listable integration' describe 'list' do - it "finds customers filtered with query" do + it 'finds customers filtered with query' do result = described_class.list(query: '(email="some@email.com")') + expect(result).to be_a Array expect(result).to all(be_a(described_class)) end end + + describe '#update_email' do + it 'updates the customer email' do + customer = described_class.get(id) + original_email = customer.emails.first + new_email = "changed#{original_email[:value]}" + + expect(customer.update_email(original_email[:id], new_email, type: original_email[:type])).to be_truthy + expect(described_class.get(id).emails.first[:value]).to eq(new_email) + end + end end diff --git a/spec/shared_examples/integration/listable.rb b/spec/shared_examples/integration/listable.rb index 44a38c8..dc199ef 100644 --- a/spec/shared_examples/integration/listable.rb +++ b/spec/shared_examples/integration/listable.rb @@ -9,4 +9,4 @@ expect(subject).to all(be_a(described_class)) end end -end +end \ No newline at end of file