Skip to content

Add a call to create thread in HelpScout #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/help_scout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ def reports_user_ratings(user_id, rating, start_date, end_date, options)
get("reports/user/ratings", options)
end


# Public: Creates conversation thread
#
# conversion_id - conversation id
# thread - thread content to be created
# imported - When set to true no outgoing emails or notifications will be
# generated
# reload - Set to true to get the entire conversation in the result
#
# More info: http://developer.helpscout.net/help-desk-api/conversations/create-thread/
#
# Returns true if created, false otherwise
def create_thread(conversation_id:, thread:, imported: nil, reload: nil)
query = {}
{ reload: reload, imported: imported }.each do |key, value|
query[key] = value unless value.nil?
end

post("conversations/#{conversation_id}", body: thread, query: query)

last_response.code == HTTP_CREATED
end

protected

def post(path, options = {})
Expand Down
24 changes: 24 additions & 0 deletions spec/helpscout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,28 @@
expect(client.search_conversations("tag:conversion")).to eq conversations["items"]
end
end

describe '#create_thread' do
let(:thread) do
{
createdBy: {
type: 'user',
id: 42,
},
type: 'note',
body: "Hello, I'm a noteworthy!"
}
end

it 'does the correct query' do
url = 'https://api.helpscout.net/v1/conversations/4242.json'
req = stub_request(:post, url).
with(body: thread.to_json).
to_return(status: 201)

expect(client.create_thread(conversation_id: 4242, thread: thread)).
to eq(true)
expect(req).to have_been_requested
end
end
end