Skip to content

Commit c23878f

Browse files
author
Jason Ball
authored
add teams endpoint (#488)
* add teams endpoint * fix newlines
1 parent 8042ec3 commit c23878f

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ You can also use the [omniauth-intercom lib](https://github.com/intercom/omniaut
4949
Resources this API supports:
5050

5151
https://api.intercom.io/users
52+
https://api.intercom.io/teams
5253
https://api.intercom.io/contacts
5354
https://api.intercom.io/companies
5455
https://api.intercom.io/counts
@@ -129,6 +130,14 @@ intercom.admins.find(id: admin_id)
129130
intercom.admins.all.each {|admin| puts admin.email }
130131
```
131132

133+
#### Teams
134+
```ruby
135+
# Find a team by id
136+
intercom.teams.find(id: team_id)
137+
# Iterate over all teams
138+
intercom.teams.all.each {|team| puts team.name }
139+
```
140+
132141
#### Companies
133142
```ruby
134143
# Add a user to one or more companies

lib/intercom.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require 'intercom/service/subscription'
1313
require 'intercom/service/segment'
1414
require 'intercom/service/tag'
15+
require 'intercom/service/team'
1516
require 'intercom/service/user'
1617
require 'intercom/service/visitor'
1718
require 'intercom/options'
@@ -31,6 +32,7 @@
3132
require "intercom/admin"
3233
require "intercom/request"
3334
require "intercom/subscription"
35+
require "intercom/team"
3436
require "intercom/errors"
3537
require "intercom/visitor"
3638
require "json"

lib/intercom/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def tags
9595
Intercom::Service::Tag.new(self)
9696
end
9797

98+
def teams
99+
Intercom::Service::Team.new(self)
100+
end
101+
98102
def users
99103
Intercom::Service::User.new(self)
100104
end

lib/intercom/service/team.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'intercom/service/base_service'
2+
require 'intercom/api_operations/list'
3+
require 'intercom/api_operations/find'
4+
5+
module Intercom
6+
module Service
7+
class Team < BaseService
8+
include ApiOperations::List
9+
include ApiOperations::Find
10+
11+
def collection_class
12+
Intercom::Team
13+
end
14+
15+
end
16+
end
17+
end

lib/intercom/team.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'intercom/traits/api_resource'
2+
3+
module Intercom
4+
class Team
5+
include Traits::ApiResource
6+
end
7+
end

spec/spec_helper.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,35 @@ def test_admin
145145
}
146146
end
147147

148+
def test_team_list
149+
{
150+
"type"=> "team.list",
151+
"teams" => [
152+
{
153+
"type"=> "team",
154+
"id"=> "2744328",
155+
"name"=> "the_a_team",
156+
"admin_ids"=> [646303, 814860],
157+
},
158+
{
159+
"type"=> "team",
160+
"id"=> "814865",
161+
"name"=> "BA_App",
162+
"admin_ids" => [492881, 1195856]
163+
},
164+
]
165+
}
166+
end
167+
168+
def test_team
169+
{
170+
"type" => "team",
171+
"id" => "2744328",
172+
"name" => "the_a_team",
173+
"admin_ids" => [646303, 814860]
174+
}
175+
end
176+
148177
def test_company
149178
{
150179
"type" => "company",

spec/unit/intercom/team_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require "spec_helper"
2+
3+
describe "Intercom::Team" do
4+
let (:client) { Intercom::Client.new(token: 'token') }
5+
6+
it "returns a CollectionProxy for all without making any requests" do
7+
client.expects(:execute_request).never
8+
all = client.teams.all
9+
all.must_be_instance_of(Intercom::ClientCollectionProxy)
10+
end
11+
12+
it 'gets an team list' do
13+
client.expects(:get).with("/teams", {}).returns(test_team_list)
14+
client.teams.all.each { |t| }
15+
end
16+
17+
it "gets an team" do
18+
client.expects(:get).with("/teams/1234", {}).returns(test_team)
19+
client.teams.find(:id => "1234")
20+
end
21+
end

0 commit comments

Comments
 (0)