From 65df1cb3e57191fc3d232a3ef4252fe8b9e5544e Mon Sep 17 00:00:00 2001 From: Rahul D'souza Date: Mon, 18 May 2020 17:20:57 +0530 Subject: [PATCH 1/2] Added Sections endpoint SDK support --- lib/intercom.rb | 2 ++ lib/intercom/client.rb | 4 ++++ lib/intercom/section.rb | 23 +++++++++++++++++++++++ lib/intercom/service/section.rb | 7 +++++++ 4 files changed, 36 insertions(+) create mode 100644 lib/intercom/section.rb create mode 100644 lib/intercom/service/section.rb diff --git a/lib/intercom.rb b/lib/intercom.rb index e6d76f2f..b1793064 100644 --- a/lib/intercom.rb +++ b/lib/intercom.rb @@ -14,6 +14,7 @@ require 'intercom/service/job' require 'intercom/service/subscription' require 'intercom/service/segment' +require 'intercom/service/section' require 'intercom/service/tag' require 'intercom/service/team' require 'intercom/service/visitor' @@ -33,6 +34,7 @@ require 'intercom/job' require 'intercom/tag' require 'intercom/segment' +require 'intercom/section' require 'intercom/event' require 'intercom/conversation' require 'intercom/message' diff --git a/lib/intercom/client.rb b/lib/intercom/client.rb index d889be55..ddc89940 100644 --- a/lib/intercom/client.rb +++ b/lib/intercom/client.rb @@ -88,6 +88,10 @@ def segments Intercom::Service::Segment.new(self) end + def sections + Intercom::Service::Section.new(self) + end + def tags Intercom::Service::Tag.new(self) end diff --git a/lib/intercom/section.rb b/lib/intercom/section.rb new file mode 100644 index 00000000..75e387ed --- /dev/null +++ b/lib/intercom/section.rb @@ -0,0 +1,23 @@ +require 'intercom/api_operations/list' +require 'intercom/api_operations/find' +require 'intercom/api_operations/save' +require 'intercom/api_operations/delete' + +module Intercom + module Service + class Section < BaseService + include ApiOperations::List + include ApiOperations::Find + include ApiOperations::Save + include ApiOperations::Delete + + def collection_class + Intercom::Section + end + + def collection_name + 'help_center/sections' + end + end + end +end diff --git a/lib/intercom/service/section.rb b/lib/intercom/service/section.rb new file mode 100644 index 00000000..2f03e746 --- /dev/null +++ b/lib/intercom/service/section.rb @@ -0,0 +1,7 @@ +require 'intercom/traits/api_resource' + +module Intercom + class Section + include Traits::ApiResource + end +end From 94da80a6aaa2fe806304829c8c05b5aadedf015f Mon Sep 17 00:00:00 2001 From: Rahul D'souza Date: Mon, 18 May 2020 17:22:49 +0530 Subject: [PATCH 2/2] Added test coverage --- spec/spec_helper.rb | 37 ++++++++++++++++++++++++++++++ spec/unit/intercom/section_spec.rb | 32 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 spec/unit/intercom/section_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7a7a721e..d94db57d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -850,6 +850,43 @@ def test_app_count } end +def test_section + { + 'id' => '18', + 'workspace_id' => 'tx2p130c', + 'name' => 'Section 1', + 'url' => 'http://www.intercom.test/help/', + 'order' => 0, + 'created_at' => 1_589_801_953, + 'updated_at' => 1_589_801_953, + 'type' => 'section', + 'parent_id' => 1 + } +end + +def test_section_list + { + 'type' => 'list', + 'total_count' => 1, + 'pages' => { + 'page' => 1, + 'per_page' => 20, + 'total_pages' => 1 + }, + 'data' => [{ + 'id' => '18', + 'workspace_id' => 'tx2p130c', + 'name' => 'Section 1', + 'url' => 'http://www.intercom.test/help/', + 'order' => 0, + 'created_at' => 1_589_801_953, + 'updated_at' => 1_589_801_953, + 'type' => 'section', + 'parent_id' => 1 + }] + } +end + def test_segment_count { 'type' => 'count', diff --git a/spec/unit/intercom/section_spec.rb b/spec/unit/intercom/section_spec.rb new file mode 100644 index 00000000..ff73f672 --- /dev/null +++ b/spec/unit/intercom/section_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Intercom::Section do + let(:client) { Intercom::Client.new(token: 'token') } + + it 'creates a section' do + client.expects(:post).with('/help_center/sections', { 'name' => 'Section 1', 'parent_id' => '1' }).returns(test_section) + client.sections.create(:name => 'Section 1', :parent_id => '1') + end + + it 'lists sections' do + client.expects(:get).with('/help_center/sections', {}).returns(test_section_list) + client.sections.all.each { |t| } + end + + it 'finds a section' do + client.expects(:get).with('/help_center/sections/1', {}).returns(test_section) + client.sections.find(id: '1') + end + + it 'updates a section' do + section = Intercom::Section.new(id: '12345') + client.expects(:put).with('/help_center/sections/12345', {}) + client.sections.save(section) + end + + it 'deletes a section' do + section = Intercom::Section.new(id: '12345') + client.expects(:delete).with('/help_center/sections/12345', {}) + client.sections.delete(section) + end +end \ No newline at end of file