Skip to content

Collections Endpoint Support #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/intercom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'intercom/version'
require 'intercom/service/admin'
require 'intercom/service/article'
require 'intercom/service/collection'
require 'intercom/service/company'
require 'intercom/service/contact'
require 'intercom/service/conversation'
Expand All @@ -25,6 +26,7 @@
require 'intercom/user'
require 'intercom/lead'
require 'intercom/count'
require 'intercom/collection'
require 'intercom/company'
require 'intercom/service/data_attribute'
require 'intercom/note'
Expand Down
4 changes: 4 additions & 0 deletions lib/intercom/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def data_attributes
Intercom::Service::DataAttribute.new(self)
end

def collections
Intercom::Service::Collection.new(self)
end

def get(path, params)
execute_request Intercom::Request.get(path, params)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/intercom/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'intercom/traits/api_resource'

module Intercom
class Collection
include Traits::ApiResource
end
end
24 changes: 24 additions & 0 deletions lib/intercom/service/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'intercom/service/base_service'
require 'intercom/api_operations/list'
require 'intercom/api_operations/find'
require 'intercom/api_operations/delete'
require 'intercom/api_operations/save'

module Intercom
module Service
class Collection < BaseService
include ApiOperations::List
include ApiOperations::Find
include ApiOperations::Delete
include ApiOperations::Save

def collection_class
Intercom::Collection
end

def collection_name
"help_center/collections"
end
end
end
end
35 changes: 35 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,41 @@ def test_contact(email = 'bob@example.com', role = 'user')
}
end

def test_collection
{
'id' => '1',
'workspace_id' => 'tx2p130c',
'name' => 'Collection 1',
'url' => 'http://www.intercom.test/help/',
'order' => 1,
'type' => 'collection',
'description' => 'Collection desc',
'icon' => 'book-bookmark'
}
end

def test_collection_list
{
'type' => 'list',
'total_count' => 1,
'pages' => {
'page' => 1,
'per_page' => 20,
'total_pages' => 1
},
'data' => [{
'id' => '1',
'workspace_id' => 'tx2p130c',
'name' => 'Collection 1',
'url' => 'http://www.intercom.test/help/',
'order' => 1,
'type' => 'collection',
'description' => 'Collection desc',
'icon' => 'book-bookmark'
}]
}
end

def test_visitor
{
'type' => 'visitor',
Expand Down
32 changes: 32 additions & 0 deletions spec/unit/intercom/collection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Intercom::Collection do
let(:client) { Intercom::Client.new(token: 'token') }

it 'creates a collection' do
client.expects(:post).with('/help_center/collections', { 'name' => 'Collection 1', 'description' => 'Collection desc' }).returns(test_collection)
client.collections.create(:name => 'Collection 1', :description => 'Collection desc')
end

it 'lists collections' do
client.expects(:get).with('/help_center/collections', {}).returns(test_collection_list)
client.collections.all.each { |t| }
end

it 'finds a collection' do
client.expects(:get).with('/help_center/collections/1', {}).returns(test_collection)
client.collections.find(id: '1')
end

it 'updates a collection' do
collection = Intercom::Collection.new(id: '12345')
client.expects(:put).with('/help_center/collections/12345', {})
client.collections.save(collection)
end

it 'deletes a collection' do
collection = Intercom::Collection.new(id: '12345')
client.expects(:delete).with('/help_center/collections/12345', {})
client.collections.delete(collection)
end
end