intercom 4.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +101 -1
- data/changes.txt +5 -1
- data/lib/intercom.rb +6 -0
- data/lib/intercom/article.rb +7 -0
- data/lib/intercom/client.rb +12 -0
- data/lib/intercom/collection.rb +7 -0
- data/lib/intercom/section.rb +23 -0
- data/lib/intercom/service/article.rb +20 -0
- data/lib/intercom/service/collection.rb +24 -0
- data/lib/intercom/service/section.rb +7 -0
- data/lib/intercom/traits/api_resource.rb +16 -1
- data/lib/intercom/traits/dirty_tracking.rb +8 -1
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +98 -0
- data/spec/unit/intercom/article_spec.rb +40 -0
- data/spec/unit/intercom/collection_spec.rb +32 -0
- data/spec/unit/intercom/section_spec.rb +32 -0
- data/spec/unit/intercom/traits/api_resource_spec.rb +55 -2
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0243df2d2e2715b541588cb09ed335e70bd1962767f06f475fd9b968ee4dace5
|
4
|
+
data.tar.gz: 9695060c87906c18d77c049eff37e742fadca1bdc21355d4471d4fcbe6447042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ffece71e912927db02751a1d6ee8e84cf535c16491a75e6fd6a2ea1c4564b17eed584d4ea480b215bb93bb215a540b0f683c257211c672151d0c08cc4c9ea3d
|
7
|
+
data.tar.gz: a60b0b793bab1f96d98fae70c75b7ceb3d609bd1b6239d115869c35acd8406119f9ceb8fcf0b7ad374f6d95eb510938098ef9cd9f6c29a46fb28760ede661665
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ intercom = Intercom::Client.new(token: 'my_token')
|
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
# With a versioned app:
|
39
|
-
intercom = Intercom::Client.new(token: 'my_token', api_version: '2.
|
39
|
+
intercom = Intercom::Client.new(token: 'my_token', api_version: '2.1')
|
40
40
|
```
|
41
41
|
|
42
42
|
If you are building a third party application you can get your access_tokens by [setting-up-oauth](https://developers.intercom.io/page/setting-up-oauth) for Intercom.
|
@@ -61,6 +61,9 @@ Resources this API supports:
|
|
61
61
|
https://api.intercom.io/counts
|
62
62
|
https://api.intercom.io/subscriptions
|
63
63
|
https://api.intercom.io/jobs
|
64
|
+
https://api.intercom.io/articles
|
65
|
+
https://api.intercom.io/help_center/collections
|
66
|
+
https://api.intercom.io/help_center/sections
|
64
67
|
|
65
68
|
|
66
69
|
### Examples
|
@@ -525,6 +528,103 @@ intercom.subscriptions.delete(subscription)
|
|
525
528
|
intercom.subscriptions.all
|
526
529
|
```
|
527
530
|
|
531
|
+
#### Articles
|
532
|
+
```ruby
|
533
|
+
# Create an article
|
534
|
+
article = intercom.articles.create(title: "New Article", author_id: "123456")
|
535
|
+
|
536
|
+
# Create an article with translations
|
537
|
+
article = intercom.articles.create(title: "New Article",
|
538
|
+
author_id: "123456",
|
539
|
+
translated_content: {fr: {title: "Nouvel Article"}, es: {title: "Nuevo artículo"}})
|
540
|
+
|
541
|
+
# Fetch an article
|
542
|
+
intercom.articles.find(id: "123456")
|
543
|
+
|
544
|
+
# List all articles
|
545
|
+
articles = intercom.articles.all
|
546
|
+
articles.each { |article| p article.title }
|
547
|
+
|
548
|
+
# Update an article
|
549
|
+
article.title = "Article Updated!"
|
550
|
+
intercom.articles.save(article)
|
551
|
+
|
552
|
+
# Update an article's existing translation
|
553
|
+
article.translated_content.en.title = "English Updated!"
|
554
|
+
intercom.articles.save(article)
|
555
|
+
|
556
|
+
# Update an article by adding a new translation
|
557
|
+
article.translated_content.es = {title: "Artículo en español"}
|
558
|
+
intercom.articles.save(article)
|
559
|
+
|
560
|
+
# Delete an article
|
561
|
+
intercom.articles.delete(article)
|
562
|
+
```
|
563
|
+
|
564
|
+
#### Collections
|
565
|
+
```ruby
|
566
|
+
# Create a collection
|
567
|
+
collection = intercom.collections.create(name: "New Collection")
|
568
|
+
|
569
|
+
# Create a collection with translations
|
570
|
+
collection = intercom.collections.create(name: "New Collection",
|
571
|
+
translated_content: {fr: {name: "Nouvelle collection"}, es: {name: "Nueva colección"}})
|
572
|
+
|
573
|
+
# Fetch a collection
|
574
|
+
intercom.collections.find(id: "123456")
|
575
|
+
|
576
|
+
# List all collections
|
577
|
+
collections = intercom.collections.all
|
578
|
+
collections.each { |collection| p collection.name }
|
579
|
+
|
580
|
+
# Update a collection
|
581
|
+
collection.name = "Collection updated!"
|
582
|
+
intercom.collections.save(collection)
|
583
|
+
|
584
|
+
# Update a collection's existing translation
|
585
|
+
collection.translated_content.en.name = "English Updated!"
|
586
|
+
intercom.collections.save(collection)
|
587
|
+
|
588
|
+
# Update a collection by adding a new translation
|
589
|
+
collection.translated_content.es = {name: "Colección en español", description: "Descripción en español"}
|
590
|
+
intercom.collections.save(collection)
|
591
|
+
|
592
|
+
# Delete an collection
|
593
|
+
intercom.collections.delete(collection)
|
594
|
+
```
|
595
|
+
|
596
|
+
#### Sections
|
597
|
+
```ruby
|
598
|
+
# Create a section
|
599
|
+
section = intercom.sections.create(name: "New Section", parent_id: "123456")
|
600
|
+
|
601
|
+
# Create a section with translations
|
602
|
+
section = intercom.sections.create(name: "New Section",
|
603
|
+
translated_content: {fr: {name: "Nouvelle section"}, es: {name: "Nueva sección"}})
|
604
|
+
|
605
|
+
# Fetch a section
|
606
|
+
intercom.sections.find(id: "123456")
|
607
|
+
|
608
|
+
# List all sections
|
609
|
+
sections = intercom.sections.all
|
610
|
+
sections.each { |section| p section.name }
|
611
|
+
|
612
|
+
# Update a section
|
613
|
+
section.name = "Section updated!"
|
614
|
+
intercom.sections.save(section)
|
615
|
+
|
616
|
+
# Update a section's existing translation
|
617
|
+
section.translated_content.en.name = "English Updated!"
|
618
|
+
intercom.collections.save(section)
|
619
|
+
|
620
|
+
# Update a section by adding a new translation
|
621
|
+
section.translated_content.es = {name: "Sección en español"}
|
622
|
+
intercom.collections.save(section)
|
623
|
+
|
624
|
+
# Delete an section
|
625
|
+
intercom.sections.delete(section)
|
626
|
+
```
|
627
|
+
|
528
628
|
### Errors
|
529
629
|
|
530
630
|
There are different styles for error handling - some people prefer exceptions; some prefer nil and check; some prefer error objects/codes. Balancing these preferences alongside our wish to provide an idiomatic gem has brought us to use the current mechanism of throwing specific exceptions. Our approach in the client is to propagate errors and signal our failure loudly so that erroneous data does not get propagated through our customers' systems - in other words, if you see a `Intercom::ServiceUnavailableError` you know where the problem is.
|
data/changes.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
4.0
|
1
|
+
4.0.1
|
2
|
+
- Fixed bug with nested resources.
|
3
|
+
- Support for add/remove contact on conversation object.
|
4
|
+
|
5
|
+
4.0.0
|
2
6
|
New version to support API version 2.0.
|
3
7
|
- Added support for new Contacts API.
|
4
8
|
- Added support for Conversation Search and for Conversation model changes.
|
data/lib/intercom.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'intercom/version'
|
4
4
|
require 'intercom/service/admin'
|
5
|
+
require 'intercom/service/article'
|
6
|
+
require 'intercom/service/collection'
|
5
7
|
require 'intercom/service/company'
|
6
8
|
require 'intercom/service/contact'
|
7
9
|
require 'intercom/service/conversation'
|
@@ -12,6 +14,7 @@ require 'intercom/service/note'
|
|
12
14
|
require 'intercom/service/job'
|
13
15
|
require 'intercom/service/subscription'
|
14
16
|
require 'intercom/service/segment'
|
17
|
+
require 'intercom/service/section'
|
15
18
|
require 'intercom/service/tag'
|
16
19
|
require 'intercom/service/team'
|
17
20
|
require 'intercom/service/visitor'
|
@@ -24,16 +27,19 @@ require 'intercom/contact'
|
|
24
27
|
require 'intercom/user'
|
25
28
|
require 'intercom/lead'
|
26
29
|
require 'intercom/count'
|
30
|
+
require 'intercom/collection'
|
27
31
|
require 'intercom/company'
|
28
32
|
require 'intercom/service/data_attribute'
|
29
33
|
require 'intercom/note'
|
30
34
|
require 'intercom/job'
|
31
35
|
require 'intercom/tag'
|
32
36
|
require 'intercom/segment'
|
37
|
+
require 'intercom/section'
|
33
38
|
require 'intercom/event'
|
34
39
|
require 'intercom/conversation'
|
35
40
|
require 'intercom/message'
|
36
41
|
require 'intercom/admin'
|
42
|
+
require 'intercom/article'
|
37
43
|
require 'intercom/request'
|
38
44
|
require 'intercom/subscription'
|
39
45
|
require 'intercom/team'
|
data/lib/intercom/client.rb
CHANGED
@@ -48,6 +48,10 @@ module Intercom
|
|
48
48
|
Intercom::Service::Admin.new(self)
|
49
49
|
end
|
50
50
|
|
51
|
+
def articles
|
52
|
+
Intercom::Service::Article.new(self)
|
53
|
+
end
|
54
|
+
|
51
55
|
def companies
|
52
56
|
Intercom::Service::Company.new(self)
|
53
57
|
end
|
@@ -84,6 +88,10 @@ module Intercom
|
|
84
88
|
Intercom::Service::Segment.new(self)
|
85
89
|
end
|
86
90
|
|
91
|
+
def sections
|
92
|
+
Intercom::Service::Section.new(self)
|
93
|
+
end
|
94
|
+
|
87
95
|
def tags
|
88
96
|
Intercom::Service::Tag.new(self)
|
89
97
|
end
|
@@ -108,6 +116,10 @@ module Intercom
|
|
108
116
|
Intercom::Service::DataAttribute.new(self)
|
109
117
|
end
|
110
118
|
|
119
|
+
def collections
|
120
|
+
Intercom::Service::Collection.new(self)
|
121
|
+
end
|
122
|
+
|
111
123
|
def get(path, params)
|
112
124
|
execute_request Intercom::Request.get(path, params)
|
113
125
|
end
|
@@ -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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/find'
|
3
|
+
require 'intercom/api_operations/list'
|
4
|
+
require 'intercom/api_operations/delete'
|
5
|
+
require 'intercom/api_operations/save'
|
6
|
+
|
7
|
+
module Intercom
|
8
|
+
module Service
|
9
|
+
class Article < BaseService
|
10
|
+
include ApiOperations::Find
|
11
|
+
include ApiOperations::List
|
12
|
+
include ApiOperations::Delete
|
13
|
+
include ApiOperations::Save
|
14
|
+
|
15
|
+
def collection_class
|
16
|
+
Intercom::Article
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/list'
|
3
|
+
require 'intercom/api_operations/find'
|
4
|
+
require 'intercom/api_operations/delete'
|
5
|
+
require 'intercom/api_operations/save'
|
6
|
+
|
7
|
+
module Intercom
|
8
|
+
module Service
|
9
|
+
class Collection < BaseService
|
10
|
+
include ApiOperations::List
|
11
|
+
include ApiOperations::Find
|
12
|
+
include ApiOperations::Delete
|
13
|
+
include ApiOperations::Save
|
14
|
+
|
15
|
+
def collection_class
|
16
|
+
Intercom::Collection
|
17
|
+
end
|
18
|
+
|
19
|
+
def collection_name
|
20
|
+
"help_center/collections"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -17,6 +17,10 @@ module Intercom
|
|
17
17
|
from_hash(attributes)
|
18
18
|
end
|
19
19
|
|
20
|
+
def ==(other)
|
21
|
+
self.class == other.class && to_json == other.to_json
|
22
|
+
end
|
23
|
+
|
20
24
|
def from_response(response)
|
21
25
|
from_hash(response)
|
22
26
|
reset_changed_fields!
|
@@ -37,10 +41,21 @@ module Intercom
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
def to_json(*args)
|
45
|
+
instance_variables_excluding_dirty_tracking_field.each_with_object({}) do |variable, hash|
|
46
|
+
next if variable == :@client
|
47
|
+
|
48
|
+
value = instance_variable_get(variable)
|
49
|
+
hash[variable.to_s.delete('@')] = value.respond_to?(:to_json) ? value.to_json(*args) : value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
40
53
|
def to_submittable_hash
|
41
54
|
submittable_hash = {}
|
42
55
|
to_hash.each do |attribute, value|
|
43
|
-
|
56
|
+
next unless submittable_attribute?(attribute, value)
|
57
|
+
|
58
|
+
submittable_hash[attribute] = value.respond_to?(:to_submittable_hash) ? value.to_submittable_hash : value
|
44
59
|
end
|
45
60
|
submittable_hash
|
46
61
|
end
|
@@ -22,7 +22,14 @@ module Intercom
|
|
22
22
|
|
23
23
|
def field_changed?(field_name)
|
24
24
|
@changed_fields ||= Set.new
|
25
|
-
|
25
|
+
field = instance_variable_get("@#{field_name}")
|
26
|
+
if field.respond_to?(:field_changed?)
|
27
|
+
field.to_hash.any? do |attribute, _|
|
28
|
+
field.field_changed?(attribute)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
@changed_fields.include?(field_name.to_s)
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
def instance_variables_excluding_dirty_tracking_field
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,32 @@ require 'time'
|
|
8
8
|
require 'pry'
|
9
9
|
include WebMock::API
|
10
10
|
|
11
|
+
def test_article
|
12
|
+
{
|
13
|
+
"id": "1",
|
14
|
+
"type": "article",
|
15
|
+
"workspace_id": "tx2p130c",
|
16
|
+
"title": "new title",
|
17
|
+
"description": "test Finished articles are visible when they're added to a Help Center collection",
|
18
|
+
"body": "<p>thingbop</p>",
|
19
|
+
"author_id": 1,
|
20
|
+
"state": "draft"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_updated_article
|
25
|
+
{
|
26
|
+
"id": "1",
|
27
|
+
"type": "article",
|
28
|
+
"workspace_id": "tx2p130c",
|
29
|
+
"title": "new updated title",
|
30
|
+
"description": "test Finished articles are visible when they're added to a Help Center collection",
|
31
|
+
"body": "<p>thingbop</p>",
|
32
|
+
"author_id": 1,
|
33
|
+
"state": "draft"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
11
37
|
def test_user(email = 'bob@example.com')
|
12
38
|
{
|
13
39
|
'type' => 'user',
|
@@ -131,6 +157,41 @@ def test_contact(email = 'bob@example.com', role = 'user')
|
|
131
157
|
}
|
132
158
|
end
|
133
159
|
|
160
|
+
def test_collection
|
161
|
+
{
|
162
|
+
'id' => '1',
|
163
|
+
'workspace_id' => 'tx2p130c',
|
164
|
+
'name' => 'Collection 1',
|
165
|
+
'url' => 'http://www.intercom.test/help/',
|
166
|
+
'order' => 1,
|
167
|
+
'type' => 'collection',
|
168
|
+
'description' => 'Collection desc',
|
169
|
+
'icon' => 'book-bookmark'
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_collection_list
|
174
|
+
{
|
175
|
+
'type' => 'list',
|
176
|
+
'total_count' => 1,
|
177
|
+
'pages' => {
|
178
|
+
'page' => 1,
|
179
|
+
'per_page' => 20,
|
180
|
+
'total_pages' => 1
|
181
|
+
},
|
182
|
+
'data' => [{
|
183
|
+
'id' => '1',
|
184
|
+
'workspace_id' => 'tx2p130c',
|
185
|
+
'name' => 'Collection 1',
|
186
|
+
'url' => 'http://www.intercom.test/help/',
|
187
|
+
'order' => 1,
|
188
|
+
'type' => 'collection',
|
189
|
+
'description' => 'Collection desc',
|
190
|
+
'icon' => 'book-bookmark'
|
191
|
+
}]
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
134
195
|
def test_visitor
|
135
196
|
{
|
136
197
|
'type' => 'visitor',
|
@@ -789,6 +850,43 @@ def test_app_count
|
|
789
850
|
}
|
790
851
|
end
|
791
852
|
|
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
|
+
|
792
890
|
def test_segment_count
|
793
891
|
{
|
794
892
|
'type' => 'count',
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Intercom::Article" do
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
|
+
|
6
|
+
describe "Getting an Article" do
|
7
|
+
it "successfully finds an article" do
|
8
|
+
client.expects(:get).with("/articles/1", {}).returns(test_article)
|
9
|
+
client.articles.find(id: "1")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Creating an Article" do
|
14
|
+
it "successfully creates and article with information passed individually" do
|
15
|
+
client.expects(:post).with("/articles", {"title" => "new title", "author_id" => 1, "body" => "<p>thingbop</p>", "state" => "draft"}).returns(test_article)
|
16
|
+
client.articles.create(:title => "new title", :author_id => 1, :body => "<p>thingbop</p>", :state => "draft")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "successfully creates and article with information in json" do
|
20
|
+
client.expects(:post).with("/articles", {"title" => "new title", "author_id" => 1, "body" => "<p>thingbop</p>", "state" => "draft"}).returns(test_article)
|
21
|
+
client.articles.create({title: "new title", author_id: 1, body: "<p>thingbop</p>", state: "draft"})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Updating an article" do
|
26
|
+
it "successfully updates an article" do
|
27
|
+
article = Intercom::Article.new(id: 12345)
|
28
|
+
client.expects(:put).with('/articles/12345', {})
|
29
|
+
client.articles.save(article)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "Deleting an article" do
|
34
|
+
it "successfully deletes an article" do
|
35
|
+
article = Intercom::Article.new(id: 12345)
|
36
|
+
client.expects(:delete).with('/articles/12345', {})
|
37
|
+
client.articles.delete(article)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Intercom::Collection do
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
|
+
|
6
|
+
it 'creates a collection' do
|
7
|
+
client.expects(:post).with('/help_center/collections', { 'name' => 'Collection 1', 'description' => 'Collection desc' }).returns(test_collection)
|
8
|
+
client.collections.create(:name => 'Collection 1', :description => 'Collection desc')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'lists collections' do
|
12
|
+
client.expects(:get).with('/help_center/collections', {}).returns(test_collection_list)
|
13
|
+
client.collections.all.each { |t| }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'finds a collection' do
|
17
|
+
client.expects(:get).with('/help_center/collections/1', {}).returns(test_collection)
|
18
|
+
client.collections.find(id: '1')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'updates a collection' do
|
22
|
+
collection = Intercom::Collection.new(id: '12345')
|
23
|
+
client.expects(:put).with('/help_center/collections/12345', {})
|
24
|
+
client.collections.save(collection)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'deletes a collection' do
|
28
|
+
collection = Intercom::Collection.new(id: '12345')
|
29
|
+
client.expects(:delete).with('/help_center/collections/12345', {})
|
30
|
+
client.collections.delete(collection)
|
31
|
+
end
|
32
|
+
end
|
@@ -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
|
@@ -17,7 +17,15 @@ describe Intercom::Traits::ApiResource do
|
|
17
17
|
'metadata' => {
|
18
18
|
'type' => 'user',
|
19
19
|
'color' => 'cyan'
|
20
|
-
}
|
20
|
+
},
|
21
|
+
'nested_fields' => {
|
22
|
+
'type' => 'nested_fields_content',
|
23
|
+
'field_1' => {
|
24
|
+
'type' => 'field_content',
|
25
|
+
'name' => 'Nested Field'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
21
29
|
end
|
22
30
|
|
23
31
|
let(:object_hash) do
|
@@ -35,6 +43,13 @@ describe Intercom::Traits::ApiResource do
|
|
35
43
|
metadata: {
|
36
44
|
type: 'user',
|
37
45
|
color: 'cyan'
|
46
|
+
},
|
47
|
+
nested_fields: {
|
48
|
+
type: 'nested_fields_content',
|
49
|
+
field_1: {
|
50
|
+
type: 'field_content',
|
51
|
+
name: 'Nested Field'
|
52
|
+
}
|
38
53
|
}
|
39
54
|
}
|
40
55
|
end
|
@@ -107,12 +122,50 @@ describe Intercom::Traits::ApiResource do
|
|
107
122
|
|
108
123
|
api_resource.from_hash(object_hash)
|
109
124
|
initialized_api_resource = ConcreteApiResource.new(object_hash)
|
110
|
-
|
111
125
|
except(object_json, 'type').keys.each do |attribute|
|
112
126
|
assert_equal initialized_api_resource.send(attribute), api_resource.send(attribute)
|
113
127
|
end
|
114
128
|
end
|
115
129
|
|
130
|
+
describe 'correctly equates two resources' do
|
131
|
+
class DummyResource; include Intercom::Traits::ApiResource; end
|
132
|
+
|
133
|
+
specify 'if each resource has the same class and same value' do
|
134
|
+
api_resource1 = DummyResource.new(object_json)
|
135
|
+
api_resource2 = DummyResource.new(object_json)
|
136
|
+
assert_equal (api_resource1 == api_resource2), true
|
137
|
+
end
|
138
|
+
|
139
|
+
specify 'if each resource has the same class and different value' do
|
140
|
+
object2_json = object_json.merge('id' => 'bbbbbb')
|
141
|
+
api_resource1 = DummyResource.new(object_json)
|
142
|
+
api_resource2 = DummyResource.new(object2_json)
|
143
|
+
assert_equal (api_resource1 == api_resource2), false
|
144
|
+
end
|
145
|
+
|
146
|
+
specify 'if each resource has a different class' do
|
147
|
+
dummy_resource = DummyResource.new(object_json)
|
148
|
+
assert_equal (dummy_resource == api_resource), false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'correctly generates submittable hash when no updates' do
|
153
|
+
assert_equal api_resource.to_submittable_hash, {}
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'correctly generates submittable hash when there are updates' do
|
157
|
+
api_resource.name = 'SuperSuite updated'
|
158
|
+
api_resource.nested_fields.field_1.name = 'Updated Name'
|
159
|
+
assert_equal api_resource.to_submittable_hash, {
|
160
|
+
'name' => 'SuperSuite updated',
|
161
|
+
'nested_fields' => {
|
162
|
+
'field_1' => {
|
163
|
+
'name' => 'Updated Name'
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
116
169
|
def except(h, *keys)
|
117
170
|
keys.each { |key| h.delete(key) }
|
118
171
|
h
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intercom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McRedmond
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2020-
|
18
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -160,9 +160,11 @@ files:
|
|
160
160
|
- lib/intercom/api_operations/save.rb
|
161
161
|
- lib/intercom/api_operations/scroll.rb
|
162
162
|
- lib/intercom/api_operations/search.rb
|
163
|
+
- lib/intercom/article.rb
|
163
164
|
- lib/intercom/base_collection_proxy.rb
|
164
165
|
- lib/intercom/client.rb
|
165
166
|
- lib/intercom/client_collection_proxy.rb
|
167
|
+
- lib/intercom/collection.rb
|
166
168
|
- lib/intercom/company.rb
|
167
169
|
- lib/intercom/contact.rb
|
168
170
|
- lib/intercom/conversation.rb
|
@@ -186,9 +188,12 @@ files:
|
|
186
188
|
- lib/intercom/request.rb
|
187
189
|
- lib/intercom/scroll_collection_proxy.rb
|
188
190
|
- lib/intercom/search_collection_proxy.rb
|
191
|
+
- lib/intercom/section.rb
|
189
192
|
- lib/intercom/segment.rb
|
190
193
|
- lib/intercom/service/admin.rb
|
194
|
+
- lib/intercom/service/article.rb
|
191
195
|
- lib/intercom/service/base_service.rb
|
196
|
+
- lib/intercom/service/collection.rb
|
192
197
|
- lib/intercom/service/company.rb
|
193
198
|
- lib/intercom/service/contact.rb
|
194
199
|
- lib/intercom/service/conversation.rb
|
@@ -199,6 +204,7 @@ files:
|
|
199
204
|
- lib/intercom/service/lead.rb
|
200
205
|
- lib/intercom/service/message.rb
|
201
206
|
- lib/intercom/service/note.rb
|
207
|
+
- lib/intercom/service/section.rb
|
202
208
|
- lib/intercom/service/segment.rb
|
203
209
|
- lib/intercom/service/subscription.rb
|
204
210
|
- lib/intercom/service/tag.rb
|
@@ -217,9 +223,11 @@ files:
|
|
217
223
|
- lib/intercom/visitor.rb
|
218
224
|
- spec/spec_helper.rb
|
219
225
|
- spec/unit/intercom/admin_spec.rb
|
226
|
+
- spec/unit/intercom/article_spec.rb
|
220
227
|
- spec/unit/intercom/base_collection_proxy_spec.rb
|
221
228
|
- spec/unit/intercom/client_collection_proxy_spec.rb
|
222
229
|
- spec/unit/intercom/client_spec.rb
|
230
|
+
- spec/unit/intercom/collection_spec.rb
|
223
231
|
- spec/unit/intercom/company_spec.rb
|
224
232
|
- spec/unit/intercom/contact_spec.rb
|
225
233
|
- spec/unit/intercom/conversation_spec.rb
|
@@ -235,6 +243,7 @@ files:
|
|
235
243
|
- spec/unit/intercom/request_spec.rb
|
236
244
|
- spec/unit/intercom/scroll_collection_proxy_spec.rb
|
237
245
|
- spec/unit/intercom/search_collection_proxy_spec.rb
|
246
|
+
- spec/unit/intercom/section_spec.rb
|
238
247
|
- spec/unit/intercom/segment_spec.rb
|
239
248
|
- spec/unit/intercom/subscription_spec.rb
|
240
249
|
- spec/unit/intercom/tag_spec.rb
|
@@ -269,9 +278,11 @@ summary: Ruby bindings for the Intercom API
|
|
269
278
|
test_files:
|
270
279
|
- spec/spec_helper.rb
|
271
280
|
- spec/unit/intercom/admin_spec.rb
|
281
|
+
- spec/unit/intercom/article_spec.rb
|
272
282
|
- spec/unit/intercom/base_collection_proxy_spec.rb
|
273
283
|
- spec/unit/intercom/client_collection_proxy_spec.rb
|
274
284
|
- spec/unit/intercom/client_spec.rb
|
285
|
+
- spec/unit/intercom/collection_spec.rb
|
275
286
|
- spec/unit/intercom/company_spec.rb
|
276
287
|
- spec/unit/intercom/contact_spec.rb
|
277
288
|
- spec/unit/intercom/conversation_spec.rb
|
@@ -287,6 +298,7 @@ test_files:
|
|
287
298
|
- spec/unit/intercom/request_spec.rb
|
288
299
|
- spec/unit/intercom/scroll_collection_proxy_spec.rb
|
289
300
|
- spec/unit/intercom/search_collection_proxy_spec.rb
|
301
|
+
- spec/unit/intercom/section_spec.rb
|
290
302
|
- spec/unit/intercom/segment_spec.rb
|
291
303
|
- spec/unit/intercom/subscription_spec.rb
|
292
304
|
- spec/unit/intercom/tag_spec.rb
|