Skip to content

Commit c49b824

Browse files
authored
Sections Endpoint Support (#524)
* Added Sections endpoint SDK support * Added test coverage
1 parent ce7149b commit c49b824

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

lib/intercom.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require 'intercom/service/job'
1515
require 'intercom/service/subscription'
1616
require 'intercom/service/segment'
17+
require 'intercom/service/section'
1718
require 'intercom/service/tag'
1819
require 'intercom/service/team'
1920
require 'intercom/service/visitor'
@@ -33,6 +34,7 @@
3334
require 'intercom/job'
3435
require 'intercom/tag'
3536
require 'intercom/segment'
37+
require 'intercom/section'
3638
require 'intercom/event'
3739
require 'intercom/conversation'
3840
require 'intercom/message'

lib/intercom/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def segments
8888
Intercom::Service::Segment.new(self)
8989
end
9090

91+
def sections
92+
Intercom::Service::Section.new(self)
93+
end
94+
9195
def tags
9296
Intercom::Service::Tag.new(self)
9397
end

lib/intercom/section.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'intercom/api_operations/list'
2+
require 'intercom/api_operations/find'
3+
require 'intercom/api_operations/save'
4+
require 'intercom/api_operations/delete'
5+
6+
module Intercom
7+
module Service
8+
class Section < BaseService
9+
include ApiOperations::List
10+
include ApiOperations::Find
11+
include ApiOperations::Save
12+
include ApiOperations::Delete
13+
14+
def collection_class
15+
Intercom::Section
16+
end
17+
18+
def collection_name
19+
'help_center/sections'
20+
end
21+
end
22+
end
23+
end

lib/intercom/service/section.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 Section
5+
include Traits::ApiResource
6+
end
7+
end

spec/spec_helper.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,43 @@ def test_app_count
850850
}
851851
end
852852

853+
def test_section
854+
{
855+
'id' => '18',
856+
'workspace_id' => 'tx2p130c',
857+
'name' => 'Section 1',
858+
'url' => 'http://www.intercom.test/help/',
859+
'order' => 0,
860+
'created_at' => 1_589_801_953,
861+
'updated_at' => 1_589_801_953,
862+
'type' => 'section',
863+
'parent_id' => 1
864+
}
865+
end
866+
867+
def test_section_list
868+
{
869+
'type' => 'list',
870+
'total_count' => 1,
871+
'pages' => {
872+
'page' => 1,
873+
'per_page' => 20,
874+
'total_pages' => 1
875+
},
876+
'data' => [{
877+
'id' => '18',
878+
'workspace_id' => 'tx2p130c',
879+
'name' => 'Section 1',
880+
'url' => 'http://www.intercom.test/help/',
881+
'order' => 0,
882+
'created_at' => 1_589_801_953,
883+
'updated_at' => 1_589_801_953,
884+
'type' => 'section',
885+
'parent_id' => 1
886+
}]
887+
}
888+
end
889+
853890
def test_segment_count
854891
{
855892
'type' => 'count',

spec/unit/intercom/section_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper'
2+
3+
describe Intercom::Section do
4+
let(:client) { Intercom::Client.new(token: 'token') }
5+
6+
it 'creates a section' do
7+
client.expects(:post).with('/help_center/sections', { 'name' => 'Section 1', 'parent_id' => '1' }).returns(test_section)
8+
client.sections.create(:name => 'Section 1', :parent_id => '1')
9+
end
10+
11+
it 'lists sections' do
12+
client.expects(:get).with('/help_center/sections', {}).returns(test_section_list)
13+
client.sections.all.each { |t| }
14+
end
15+
16+
it 'finds a section' do
17+
client.expects(:get).with('/help_center/sections/1', {}).returns(test_section)
18+
client.sections.find(id: '1')
19+
end
20+
21+
it 'updates a section' do
22+
section = Intercom::Section.new(id: '12345')
23+
client.expects(:put).with('/help_center/sections/12345', {})
24+
client.sections.save(section)
25+
end
26+
27+
it 'deletes a section' do
28+
section = Intercom::Section.new(id: '12345')
29+
client.expects(:delete).with('/help_center/sections/12345', {})
30+
client.sections.delete(section)
31+
end
32+
end

0 commit comments

Comments
 (0)