Skip to content

Commit

Permalink
Support updating customer emails
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemanrubia committed Dec 15, 2020
1 parent 918008e commit 87c7243
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/help_scout/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions spec/integration/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
describe 'list' 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

0 comments on commit 87c7243

Please sign in to comment.