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