Skip to content

Commit 8e96c77

Browse files
authored
Merge pull request #238 from dhiemstra/conversation_count_all
Get global conversation count
2 parents cb6840b + 19e92dc commit 8e96c77

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/intercom/service/count.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def for_app
1515
end
1616

1717
def for_type(type:, count: nil)
18-
find(type: type, count: count)
18+
params = {type: type}
19+
params[:count] = count if count
20+
find(params)
1921
end
2022
end
2123
end

spec/spec_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,18 @@ def test_segment_count
520520
}
521521
end
522522

523+
def test_conversation_count
524+
{
525+
"type" => "count",
526+
"conversation" => {
527+
"assigned" => 1,
528+
"closed" => 15,
529+
"open" => 1,
530+
"unassigned" => 0
531+
}
532+
}
533+
end
534+
523535
def error_on_modify_frozen
524536
RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
525537
end

spec/unit/intercom/count_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@
1414
counts = client.counts.for_type(type: 'user', count: 'segment')
1515
counts.user['segment'][4]["segment 1"].must_equal(1)
1616
end
17+
18+
it 'should not include count param when nil' do
19+
client.expects(:get).with("/counts", {type: 'conversation'}).returns(test_conversation_count)
20+
counts = client.counts.for_type(type: 'conversation')
21+
counts.conversation.must_equal({
22+
"assigned" => 1,
23+
"closed" => 15,
24+
"open" => 1,
25+
"unassigned" => 0
26+
})
27+
end
1728
end

0 commit comments

Comments
 (0)