Skip to content

Commit 0ebf99a

Browse files
committed
add conversations_search endpoint
1 parent 37ec2ca commit 0ebf99a

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/frontapp/client/conversations.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ def conversations(params = {})
66
list("conversations", params)
77
end
88

9+
# Docs: https://dev.frontapp.com/docs/search-1
10+
def conversations_search(
11+
search_phrases: [],
12+
search_params: {},
13+
limit: nil,
14+
page_token: nil
15+
)
16+
encoded =
17+
[
18+
*search_phrases.map { |c| c.include?(" ") ? "\"#{c}\"" : c },
19+
*search_params.map { |key, value| "#{key}:#{value}" },
20+
].compact.join(" ")
21+
22+
if encoded.empty?
23+
raise ArgumentError,
24+
"You must specify either search_text or search_params"
25+
end
26+
27+
encoded = CGI.escape(encoded).gsub("+", "%20")
28+
29+
list(
30+
"conversations/search/#{encoded}",
31+
{ limit: limit, page_token: page_token }.compact,
32+
)
33+
end
34+
935
# Parameters
1036
# Name Type Description
1137
# ------------------------------------

spec/conversations_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,18 @@
540540
frontapp.conversations
541541
end
542542

543+
it "can search conversations" do
544+
stub_request(:get, "#{base_url}/conversations/search/#{
545+
URI.encode_www_form_component("\"foo bar\" status:archived")
546+
}").
547+
with( headers: headers).
548+
to_return(status: 200, body: all_conversations_response)
549+
frontapp.conversations_search(
550+
search_text: "foo bar",
551+
search_params: { status: "archived" }
552+
)
553+
end
554+
543555
it "can get a specific conversation" do
544556
stub_request(:get, "#{base_url}/conversations/#{conversation_id}").
545557
with( headers: headers).
@@ -609,7 +621,7 @@
609621
frontapp.add_conversation_links!(conversation_id, data)
610622
end
611623

612-
it "can remove conversation links by id" do
624+
xit "can remove conversation links by id" do
613625
data = {
614626
link_ids: ["top_55c8c149"]
615627
}

spec/links_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
}
184184
}
185185
end
186-
let(:create_link_response) {
186+
let(:create_link_response) do
187187
%Q{
188188
{
189189
"_links"=>{"self"=>"https://lending-home.api.frontapp.com/links/top_3ij8h"},

0 commit comments

Comments
 (0)