File tree Expand file tree Collapse file tree 7 files changed +107
-1
lines changed
Expand file tree Collapse file tree 7 files changed +107
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ Using bundler:
3232intercom = Intercom ::Client .new (app_id: ' my_app_id' , api_key: ' my_api_key' )
3333```
3434
35- You can get your ` app_id ` from the URL when you're logged into Intercom (it's the alphanumeric just after ` /apps/ ` ) and your API key from the API keys integration settings page (under your app settings - integrations in Intercom).
35+ You can get your ` app_id ` from the URL when you're logged into Intercom (it's the alphanumeric just after ` /apps/ ` ) and your API key from the API keys integration settings page (under your app settings - integrations in Intercom).
3636
3737### Resources
3838
@@ -41,6 +41,7 @@ Resources this API supports:
4141 https://api.intercom.io/users
4242 https://api.intercom.io/contacts
4343 https://api.intercom.io/companies
44+ https://api.intercom.io/counts
4445 https://api.intercom.io/tags
4546 https://api.intercom.io/notes
4647 https://api.intercom.io/segments
@@ -313,6 +314,16 @@ contacts = intercom.contacts.find_all(email: "
[email protected] ")
313314intercom.contacts.convert(contact, user)
314315```
315316
317+ ### Counts
318+
319+ ``` ruby
320+ # App-wide counts
321+ intercom.counts.for_app
322+
323+ # Users in segment counts
324+ intercom.counts.for_type(type: ' user' , count: ' segment' )
325+ ```
326+
316327### Subscriptions
317328
318329Subscribe to events in Intercom to receive webhooks.
Original file line number Diff line number Diff line change 33require 'intercom/service/company'
44require 'intercom/service/contact'
55require 'intercom/service/conversation'
6+ require 'intercom/service/count'
67require 'intercom/service/event'
78require 'intercom/service/message'
89require 'intercom/service/note'
1314require 'intercom/options'
1415require 'intercom/client'
1516require "intercom/contact"
17+ require "intercom/count"
1618require "intercom/user"
1719require "intercom/company"
1820require "intercom/note"
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ def conversations
3636 Intercom ::Service ::Conversation . new ( self )
3737 end
3838
39+ def counts
40+ Intercom ::Service ::Counts . new ( self )
41+ end
42+
3943 def events
4044 Intercom ::Service ::Event . new ( self )
4145 end
Original file line number Diff line number Diff line change 1+ require 'intercom/traits/api_resource'
2+
3+ module Intercom
4+ class Count
5+ include Traits ::ApiResource
6+ end
7+ end
Original file line number Diff line number Diff line change 1+ require 'intercom/service/base_service'
2+ require 'intercom/api_operations/find'
3+
4+ module Intercom
5+ module Service
6+ class Counts < BaseService
7+ include ApiOperations ::Find
8+
9+ def collection_class
10+ Intercom ::Count
11+ end
12+
13+ def for_app
14+ find ( { } )
15+ end
16+
17+ def for_type ( type :, count : nil )
18+ find ( type : type , count : count )
19+ end
20+ end
21+ end
22+ end
Original file line number Diff line number Diff line change @@ -405,6 +405,49 @@ def test_subscription
405405 "notes" => [ ] } }
406406end
407407
408+ def test_app_count
409+ {
410+ "type" => "count.hash" ,
411+ "company" => {
412+ "count" => 8
413+ } ,
414+ "segment" => {
415+ "count" => 47
416+ } ,
417+ "tag" => {
418+ "count" => 341
419+ } ,
420+ "user" => {
421+ "count" => 12239
422+ }
423+ }
424+ end
425+
426+ def test_segment_count
427+ {
428+ "type" => "count" ,
429+ "user" => {
430+ "segment" => [
431+ {
432+ "Active" => 1
433+ } ,
434+ {
435+ "New" => 0
436+ } ,
437+ {
438+ "VIP" => 0
439+ } ,
440+ {
441+ "Slipping Away" => 0
442+ } ,
443+ {
444+ "segment 1" => 1
445+ }
446+ ]
447+ }
448+ }
449+ end
450+
408451def error_on_modify_frozen
409452 RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
410453end
Original file line number Diff line number Diff line change 1+ require "spec_helper"
2+
3+ describe "Intercom::Count" do
4+ let ( :client ) { Intercom ::Client . new ( app_id : 'app_id' , api_key : 'api_key' ) }
5+
6+ it 'should get app wide counts' do
7+ client . expects ( :get ) . with ( "/counts" , { } ) . returns ( test_app_count )
8+ counts = client . counts . for_app
9+ counts . tag [ 'count' ] . must_equal ( 341 )
10+ end
11+
12+ it 'should get type counts' do
13+ client . expects ( :get ) . with ( "/counts" , { type : 'user' , count : 'segment' } ) . returns ( test_segment_count )
14+ counts = client . counts . for_type ( type : 'user' , count : 'segment' )
15+ counts . user [ 'segment' ] [ 4 ] [ "segment 1" ] . must_equal ( 1 )
16+ end
17+ end
You can’t perform that action at this time.
0 commit comments