intercom 3.9.5 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +483 -234
  3. data/Rakefile +1 -1
  4. data/changes.txt +37 -0
  5. data/lib/intercom/api_operations/archive.rb +2 -1
  6. data/lib/intercom/api_operations/delete.rb +16 -0
  7. data/lib/intercom/api_operations/find.rb +5 -2
  8. data/lib/intercom/api_operations/find_all.rb +4 -3
  9. data/lib/intercom/api_operations/list.rb +4 -1
  10. data/lib/intercom/api_operations/load.rb +4 -2
  11. data/lib/intercom/api_operations/nested_resource.rb +68 -0
  12. data/lib/intercom/api_operations/save.rb +6 -4
  13. data/lib/intercom/api_operations/scroll.rb +4 -5
  14. data/lib/intercom/api_operations/search.rb +3 -2
  15. data/lib/intercom/article.rb +7 -0
  16. data/lib/intercom/base_collection_proxy.rb +74 -0
  17. data/lib/intercom/client.rb +48 -25
  18. data/lib/intercom/client_collection_proxy.rb +17 -39
  19. data/lib/intercom/collection.rb +7 -0
  20. data/lib/intercom/company.rb +8 -0
  21. data/lib/intercom/contact.rb +23 -3
  22. data/lib/intercom/conversation.rb +5 -0
  23. data/lib/intercom/data_attribute.rb +7 -0
  24. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  25. data/lib/intercom/deprecated_resources.rb +13 -0
  26. data/lib/intercom/errors.rb +6 -0
  27. data/lib/intercom/export_content.rb +7 -0
  28. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  29. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  30. data/lib/intercom/lead.rb +21 -0
  31. data/lib/intercom/lib/dynamic_accessors.rb +9 -10
  32. data/lib/intercom/lib/typed_json_deserializer.rb +45 -35
  33. data/lib/intercom/note.rb +4 -0
  34. data/lib/intercom/phone_call_redirect.rb +7 -0
  35. data/lib/intercom/request.rb +39 -33
  36. data/lib/intercom/scroll_collection_proxy.rb +38 -42
  37. data/lib/intercom/search_collection_proxy.rb +30 -65
  38. data/lib/intercom/section.rb +23 -0
  39. data/lib/intercom/segment.rb +4 -0
  40. data/lib/intercom/service/article.rb +20 -0
  41. data/lib/intercom/service/base_service.rb +7 -0
  42. data/lib/intercom/service/collection.rb +24 -0
  43. data/lib/intercom/service/company.rb +2 -12
  44. data/lib/intercom/service/contact.rb +35 -10
  45. data/lib/intercom/service/conversation.rb +16 -3
  46. data/lib/intercom/service/data_attribute.rb +20 -0
  47. data/lib/intercom/service/export_content.rb +30 -0
  48. data/lib/intercom/service/lead.rb +41 -0
  49. data/lib/intercom/service/note.rb +4 -8
  50. data/lib/intercom/service/phone_call_redirect.rb +15 -0
  51. data/lib/intercom/service/section.rb +7 -0
  52. data/lib/intercom/service/subscription.rb +2 -2
  53. data/lib/intercom/service/subscription_type.rb +18 -0
  54. data/lib/intercom/service/tag.rb +9 -9
  55. data/lib/intercom/service/visitor.rb +17 -8
  56. data/lib/intercom/subscription_type.rb +12 -0
  57. data/lib/intercom/tag.rb +4 -0
  58. data/lib/intercom/traits/api_resource.rb +44 -18
  59. data/lib/intercom/traits/dirty_tracking.rb +8 -1
  60. data/lib/intercom/user.rb +12 -3
  61. data/lib/intercom/utils.rb +19 -3
  62. data/lib/intercom/version.rb +1 -1
  63. data/lib/intercom/visitor.rb +0 -2
  64. data/lib/intercom.rb +39 -22
  65. data/spec/spec_helper.rb +843 -520
  66. data/spec/unit/intercom/admin_spec.rb +2 -2
  67. data/spec/unit/intercom/article_spec.rb +40 -0
  68. data/spec/unit/intercom/base_collection_proxy_spec.rb +52 -0
  69. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  70. data/spec/unit/intercom/client_spec.rb +25 -26
  71. data/spec/unit/intercom/collection_spec.rb +32 -0
  72. data/spec/unit/intercom/company_spec.rb +19 -15
  73. data/spec/unit/intercom/contact_spec.rb +402 -33
  74. data/spec/unit/intercom/conversation_spec.rb +60 -7
  75. data/spec/unit/intercom/count_spec.rb +4 -4
  76. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  77. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  78. data/spec/unit/intercom/event_spec.rb +16 -11
  79. data/spec/unit/intercom/export_content_spec.rb +28 -0
  80. data/spec/unit/intercom/job_spec.rb +24 -24
  81. data/spec/unit/intercom/lead_spec.rb +57 -0
  82. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  83. data/spec/unit/intercom/message_spec.rb +1 -1
  84. data/spec/unit/intercom/note_spec.rb +4 -10
  85. data/spec/unit/intercom/phone_call_redirect.rb +12 -0
  86. data/spec/unit/intercom/request_spec.rb +14 -1
  87. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  88. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  89. data/spec/unit/intercom/section_spec.rb +32 -0
  90. data/spec/unit/intercom/segment_spec.rb +2 -2
  91. data/spec/unit/intercom/subscription_spec.rb +5 -6
  92. data/spec/unit/intercom/tag_spec.rb +28 -14
  93. data/spec/unit/intercom/team_spec.rb +2 -2
  94. data/spec/unit/intercom/traits/api_resource_spec.rb +107 -52
  95. data/spec/unit/intercom/user_spec.rb +224 -226
  96. data/spec/unit/intercom/visitor_spec.rb +49 -0
  97. data/spec/unit/intercom_spec.rb +5 -3
  98. metadata +44 -8
  99. data/lib/intercom/customer.rb +0 -10
  100. data/lib/intercom/service/customer.rb +0 -14
  101. data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,82 +1,47 @@
1
- require "intercom/utils"
1
+ # frozen_string_literal: true
2
2
 
3
- module Intercom
4
- class SearchCollectionProxy
5
-
6
- attr_reader :resource_name, :resource_class
7
-
8
- def initialize(resource_name, search_details: {}, client:)
9
- @resource_name = resource_name
10
- @resource_class = Utils.constantize_resource_name(resource_name)
11
- @search_url = search_details[:url]
12
- @search_params = search_details[:params]
13
- @client = client
14
- end
15
-
16
- def each(&block)
17
- loop do
18
- response_hash = @client.post(@search_url, payload)
19
- raise Intercom::HttpError.new('Http Error - No response entity returned') unless response_hash
20
- deserialize_response_hash(response_hash, block)
21
- break unless has_next_link?(response_hash)
22
- end
23
- self
24
- end
3
+ require 'intercom/utils'
4
+ require 'intercom/base_collection_proxy'
25
5
 
26
- def [](target_index)
27
- self.each_with_index do |item, index|
28
- return item if index == target_index
29
- end
30
- nil
6
+ module Intercom
7
+ class SearchCollectionProxy < BaseCollectionProxy
8
+ def initialize(resource_name, resource_class, details: {}, client:)
9
+ super(resource_name, resource_class, details: details, client: client, method: 'post')
31
10
  end
32
11
 
33
- include Enumerable
34
-
35
12
  private
36
13
 
37
- def deserialize_response_hash(response_hash, block)
38
- top_level_type = response_hash.delete('type')
39
- top_level_entity_key = Utils.entity_key_from_type(top_level_type)
40
- response_hash[top_level_entity_key].each do |object_json|
41
- block.call Lib::TypedJsonDeserializer.new(object_json).deserialize
42
- end
43
- end
44
-
45
- def has_next_link?(response_hash)
46
- paging_info = response_hash.delete('pages')
47
- paging_next = paging_info["next"]
48
- if paging_next
49
- @search_params[:starting_after] = paging_next["starting_after"]
50
- return true
51
- else
52
- return false
53
- end
54
- end
55
-
56
14
  def payload
57
15
  payload = {
58
- query: @search_params[:query]
16
+ query: @params[:query]
59
17
  }
60
- if @search_params[:sort_field] || @search_params[:sort_order]
18
+ if sort_field || sort_order
61
19
  payload[:sort] = {}
62
- if @search_params[:sort_field]
63
- payload[:sort][:field] = @search_params[:sort_field]
64
- end
65
- if @search_params[:sort_order]
66
- payload[:sort][:order] = @search_params[:sort_order]
67
- end
20
+ payload[:sort][:field] = sort_field if sort_field
21
+ payload[:sort][:order] = sort_order if sort_order
68
22
  end
69
- if @search_params[:per_page] || @search_params[:starting_after]
23
+ if per_page || starting_after
70
24
  payload[:pagination] = {}
71
- if @search_params[:per_page]
72
- payload[:pagination][:per_page] = @search_params[:per_page]
73
- end
74
- if @search_params[:starting_after]
75
- payload[:pagination][:starting_after] = @search_params[:starting_after]
76
- end
25
+ payload[:pagination][:per_page] = per_page if per_page
26
+ payload[:pagination][:starting_after] = starting_after if starting_after
77
27
  end
78
- return payload
28
+ payload
29
+ end
30
+
31
+ def sort_field
32
+ @params[:sort_field]
79
33
  end
80
34
 
35
+ def sort_order
36
+ @params[:sort_order]
37
+ end
38
+
39
+ def per_page
40
+ @params[:per_page]
41
+ end
42
+
43
+ def starting_after
44
+ @params[:starting_after]
45
+ end
81
46
  end
82
47
  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
@@ -3,5 +3,9 @@ require 'intercom/traits/api_resource'
3
3
  module Intercom
4
4
  class Segment
5
5
  include Traits::ApiResource
6
+
7
+ def self.collection_proxy_class
8
+ Intercom::BaseCollectionProxy
9
+ end
6
10
  end
7
11
  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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/client_collection_proxy'
2
4
 
3
5
  module Intercom
@@ -17,8 +19,13 @@ module Intercom
17
19
  Intercom::ClientCollectionProxy
18
20
  end
19
21
 
22
+ def collection_name
23
+ @collection_name ||= Utils.resource_class_to_collection_name(collection_class)
24
+ end
25
+
20
26
  def from_api(api_response)
21
27
  object = collection_class.new
28
+ object.client = @client
22
29
  object.from_response(api_response)
23
30
  object
24
31
  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
@@ -1,4 +1,5 @@
1
1
  require 'intercom/service/base_service'
2
+ require 'intercom/api_operations/delete'
2
3
  require 'intercom/api_operations/list'
3
4
  require 'intercom/api_operations/scroll'
4
5
  require 'intercom/api_operations/find'
@@ -11,6 +12,7 @@ require 'intercom/extended_api_operations/segments'
11
12
  module Intercom
12
13
  module Service
13
14
  class Company < BaseService
15
+ include ApiOperations::Delete
14
16
  include ApiOperations::Find
15
17
  include ApiOperations::FindAll
16
18
  include ApiOperations::Load
@@ -23,18 +25,6 @@ module Intercom
23
25
  def collection_class
24
26
  Intercom::Company
25
27
  end
26
-
27
- def users_by_intercom_company_id(id)
28
- get_users(url: "/companies/#{id}/users")
29
- end
30
-
31
- def users_by_company_id(id)
32
- get_users(url: "/companies", params: { company_id: id, type: "user" })
33
- end
34
-
35
- private def get_users(url:, params: {})
36
- ClientCollectionProxy.new("users", finder_details: { url: url, params: params }, client: @client)
37
- end
38
28
  end
39
29
  end
40
30
  end
@@ -2,12 +2,9 @@ require 'intercom/service/base_service'
2
2
  require 'intercom/api_operations/load'
3
3
  require 'intercom/api_operations/list'
4
4
  require 'intercom/api_operations/find'
5
- require 'intercom/api_operations/find_all'
6
5
  require 'intercom/api_operations/save'
7
- require 'intercom/api_operations/scroll'
8
- require 'intercom/api_operations/convert'
9
- require 'intercom/api_operations/archive'
10
- require 'intercom/api_operations/request_hard_delete'
6
+ require 'intercom/api_operations/delete'
7
+ require 'intercom/api_operations/search'
11
8
 
12
9
  module Intercom
13
10
  module Service
@@ -15,16 +12,44 @@ module Intercom
15
12
  include ApiOperations::Load
16
13
  include ApiOperations::List
17
14
  include ApiOperations::Find
18
- include ApiOperations::FindAll
19
15
  include ApiOperations::Save
20
- include ApiOperations::Scroll
21
- include ApiOperations::Convert
22
- include ApiOperations::Archive
23
- include ApiOperations::RequestHardDelete
16
+ include ApiOperations::Delete
17
+ include ApiOperations::Search
24
18
 
25
19
  def collection_class
26
20
  Intercom::Contact
27
21
  end
22
+
23
+ def collection_proxy_class
24
+ Intercom::BaseCollectionProxy
25
+ end
26
+
27
+ def merge(lead, user)
28
+ raise_invalid_merge_error unless lead.role == 'lead' && user.role == 'user'
29
+
30
+ response = @client.post('/contacts/merge', from: lead.id, into: user.id)
31
+ raise Intercom::HttpError, 'Http Error - No response entity returned' unless response
32
+
33
+ user.from_response(response)
34
+ end
35
+
36
+ def archive(contact)
37
+ @client.post("/#{collection_name}/#{contact.id}/archive", {})
38
+ contact
39
+ end
40
+
41
+ def unarchive(contact)
42
+ @client.post("/#{collection_name}/#{contact.id}/unarchive", {})
43
+ contact
44
+ end
45
+
46
+ def delete_archived_contact(id)
47
+ @client.delete("/#{collection_name}/#{id}", {})
48
+ end
49
+
50
+ private def raise_invalid_merge_error
51
+ raise Intercom::InvalidMergeError, 'Merging can only be performed on a lead into a user'
52
+ end
28
53
  end
29
54
  end
30
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/service/base_service'
2
4
  require 'intercom/api_operations/find_all'
3
5
  require 'intercom/api_operations/find'
@@ -13,11 +15,16 @@ module Intercom
13
15
  include ApiOperations::Find
14
16
  include ApiOperations::Load
15
17
  include ApiOperations::Save
18
+ include ApiOperations::Search
16
19
 
17
20
  def collection_class
18
21
  Intercom::Conversation
19
22
  end
20
23
 
24
+ def collection_proxy_class
25
+ Intercom::BaseCollectionProxy
26
+ end
27
+
21
28
  def mark_read(id)
22
29
  @client.put("/conversations/#{id}", read: true)
23
30
  end
@@ -25,7 +32,7 @@ module Intercom
25
32
  def reply(reply_data)
26
33
  id = reply_data.delete(:id)
27
34
  collection_name = Utils.resource_class_to_collection_name(collection_class)
28
- response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(:conversation_id => id))
35
+ response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(conversation_id: id))
29
36
  collection_class.new.from_response(response)
30
37
  end
31
38
 
@@ -44,14 +51,20 @@ module Intercom
44
51
  end
45
52
 
46
53
  def snooze(reply_data)
47
- snoozed_until = reply_data.fetch(:snoozed_until) { fail 'snoozed_until field is required' }
54
+ reply_data.fetch(:snoozed_until) { raise 'snoozed_until field is required' }
48
55
  reply reply_data.merge(message_type: 'snoozed', type: 'admin')
49
56
  end
50
57
 
51
58
  def assign(reply_data)
52
- assignee_id = reply_data.fetch(:assignee_id) { fail 'assignee_id is required' }
59
+ assignee_id = reply_data.fetch(:assignee_id) { raise 'assignee_id is required' }
53
60
  reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id, type: 'admin')
54
61
  end
62
+
63
+ def run_assignment_rules(id)
64
+ collection_name = Utils.resource_class_to_collection_name(collection_class)
65
+ response = @client.post("/#{collection_name}/#{id}/run_assignment_rules", {})
66
+ collection_class.new.from_response(response)
67
+ end
55
68
  end
56
69
  end
57
70
  end
@@ -0,0 +1,20 @@
1
+ require 'intercom/service/base_service'
2
+ require 'intercom/api_operations/load'
3
+ require 'intercom/api_operations/list'
4
+ require 'intercom/api_operations/find_all'
5
+ require 'intercom/api_operations/save'
6
+
7
+ module Intercom
8
+ module Service
9
+ class DataAttribute < BaseService
10
+ include ApiOperations::Load
11
+ include ApiOperations::List
12
+ include ApiOperations::FindAll
13
+ include ApiOperations::Save
14
+
15
+ def collection_class
16
+ Intercom::DataAttribute
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'intercom/service/base_service'
2
+ require 'intercom/api_operations/find'
3
+ require 'intercom/api_operations/list'
4
+ require 'intercom/api_operations/save'
5
+
6
+ module Intercom
7
+ module Service
8
+ class ExportContent < BaseService
9
+ include ApiOperations::Load
10
+ include ApiOperations::List
11
+ include ApiOperations::Find
12
+ include ApiOperations::Save
13
+
14
+ def collection_class
15
+ Intercom::ExportContent
16
+ end
17
+
18
+ def collection_name
19
+ 'export/content/data'
20
+ end
21
+
22
+ def cancel(id)
23
+ response = @client.post("/export/cancel/#{id}", {})
24
+ collection_class.new.from_response(response)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'intercom/service/base_service'
4
+ require 'intercom/api_operations/load'
5
+ require 'intercom/api_operations/list'
6
+ require 'intercom/api_operations/find'
7
+ require 'intercom/api_operations/find_all'
8
+ require 'intercom/api_operations/save'
9
+ require 'intercom/api_operations/scroll'
10
+ require 'intercom/api_operations/convert'
11
+ require 'intercom/api_operations/archive'
12
+ require 'intercom/api_operations/request_hard_delete'
13
+ require 'intercom/deprecated_leads_collection_proxy'
14
+
15
+ module Intercom
16
+ module Service
17
+ class Lead < BaseService
18
+ include ApiOperations::Load
19
+ include ApiOperations::List
20
+ include ApiOperations::Find
21
+ include ApiOperations::FindAll
22
+ include ApiOperations::Save
23
+ include ApiOperations::Scroll
24
+ include ApiOperations::Convert
25
+ include ApiOperations::Archive
26
+ include ApiOperations::RequestHardDelete
27
+
28
+ def collection_proxy_class
29
+ Intercom::DeprecatedLeadsCollectionProxy
30
+ end
31
+
32
+ def collection_class
33
+ Intercom::Lead
34
+ end
35
+
36
+ def collection_name
37
+ 'contacts'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,22 +1,18 @@
1
1
  require 'intercom/service/base_service'
2
- require 'intercom/api_operations/list'
3
- require 'intercom/api_operations/find_all'
4
2
  require 'intercom/api_operations/find'
5
- require 'intercom/api_operations/load'
6
- require 'intercom/api_operations/save'
7
3
 
8
4
  module Intercom
9
5
  module Service
10
6
  class Note < BaseService
11
- include ApiOperations::Save
12
- include ApiOperations::List
13
- include ApiOperations::FindAll
14
7
  include ApiOperations::Find
15
- include ApiOperations::Load
16
8
 
17
9
  def collection_class
18
10
  Intercom::Note
19
11
  end
12
+
13
+ def collection_proxy_class
14
+ Intercom::BaseCollectionProxy
15
+ end
20
16
  end
21
17
  end
22
18
  end
@@ -0,0 +1,15 @@
1
+ require 'intercom/service/base_service'
2
+ require 'intercom/api_operations/save'
3
+
4
+ module Intercom
5
+ module Service
6
+ class PhoneCallRedirect < BaseService
7
+ include ApiOperations::Save
8
+
9
+ def collection_class
10
+ Intercom::PhoneCallRedirect
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -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
@@ -2,7 +2,7 @@ require 'intercom/api_operations/list'
2
2
  require 'intercom/api_operations/find_all'
3
3
  require 'intercom/api_operations/find'
4
4
  require 'intercom/api_operations/save'
5
- require 'intercom/api_operations/archive'
5
+ require 'intercom/api_operations/delete'
6
6
 
7
7
  module Intercom
8
8
  module Service
@@ -11,7 +11,7 @@ module Intercom
11
11
  include ApiOperations::Find
12
12
  include ApiOperations::FindAll
13
13
  include ApiOperations::Save
14
- include ApiOperations::Archive
14
+ include ApiOperations::Delete
15
15
 
16
16
  def collection_class
17
17
  Intercom::Subscription
@@ -0,0 +1,18 @@
1
+ require 'intercom/api_operations/list'
2
+ require 'intercom/api_operations/find_all'
3
+ require 'intercom/api_operations/find'
4
+
5
+ module Intercom
6
+ module Service
7
+ class SubscriptionType < BaseService
8
+ include ApiOperations::List
9
+ include ApiOperations::Find
10
+ include ApiOperations::FindAll
11
+ include ApiOperations::Delete
12
+
13
+ def collection_class
14
+ Intercom::SubscriptionType
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,7 @@ require 'intercom/service/base_service'
2
2
  require 'intercom/api_operations/save'
3
3
  require 'intercom/api_operations/list'
4
4
  require 'intercom/api_operations/find_all'
5
+ require 'intercom/api_operations/find'
5
6
 
6
7
  module Intercom
7
8
  module Service
@@ -9,12 +10,17 @@ module Intercom
9
10
  include ApiOperations::Save
10
11
  include ApiOperations::List
11
12
  include ApiOperations::FindAll
12
- include ApiOperations::Archive
13
+ include ApiOperations::Delete
14
+ include ApiOperations::Find
13
15
 
14
16
  def collection_class
15
17
  Intercom::Tag
16
18
  end
17
19
 
20
+ def collection_proxy_class
21
+ Intercom::BaseCollectionProxy
22
+ end
23
+
18
24
  def tag(params)
19
25
  params['tag_or_untag'] = 'tag'
20
26
  create(params)
@@ -22,17 +28,11 @@ module Intercom
22
28
 
23
29
  def untag(params)
24
30
  params['tag_or_untag'] = 'untag'
25
- users_or_companies(params).each do |user_or_company|
26
- user_or_company[:untag] = true
31
+ params[:companies].each do |company|
32
+ company[:untag] = true
27
33
  end
28
34
  create(params)
29
35
  end
30
-
31
- private
32
-
33
- def users_or_companies(params)
34
- params[:users] || params[:companies]
35
- end
36
36
  end
37
37
  end
38
38
  end
@@ -1,26 +1,35 @@
1
1
  require 'intercom/service/base_service'
2
2
  require 'intercom/api_operations/load'
3
- require 'intercom/api_operations/list'
4
3
  require 'intercom/api_operations/find'
5
- require 'intercom/api_operations/find_all'
6
4
  require 'intercom/api_operations/save'
7
- require 'intercom/api_operations/convert'
8
- require 'intercom/api_operations/archive'
5
+ require 'intercom/api_operations/delete'
9
6
 
10
7
  module Intercom
11
8
  module Service
12
9
  class Visitor < BaseService
13
10
  include ApiOperations::Load
14
- include ApiOperations::List
15
11
  include ApiOperations::Find
16
- include ApiOperations::FindAll
17
12
  include ApiOperations::Save
18
- include ApiOperations::Convert
19
- include ApiOperations::Archive
13
+ include ApiOperations::Delete
20
14
 
21
15
  def collection_class
22
16
  Intercom::Visitor
23
17
  end
18
+
19
+ def convert(visitor, contact = false)
20
+ req = { visitor: { user_id: visitor.user_id } }
21
+ if contact
22
+ req[:user] = identity_hash(contact)
23
+ req[:type] = 'user'
24
+ else
25
+ req[:type] = 'lead'
26
+ end
27
+ Intercom::Contact.new.from_response(
28
+ @client.post(
29
+ "/visitors/convert", req
30
+ )
31
+ )
32
+ end
24
33
  end
25
34
  end
26
35
  end
@@ -0,0 +1,12 @@
1
+
2
+ require 'intercom/traits/api_resource'
3
+
4
+ module Intercom
5
+ class SubscriptionType
6
+ include Traits::ApiResource
7
+
8
+ def self.collection_proxy_class
9
+ Intercom::BaseCollectionProxy
10
+ end
11
+ end
12
+ end
data/lib/intercom/tag.rb CHANGED
@@ -3,5 +3,9 @@ require 'intercom/traits/api_resource'
3
3
  module Intercom
4
4
  class Tag
5
5
  include Traits::ApiResource
6
+
7
+ def self.collection_proxy_class
8
+ Intercom::BaseCollectionProxy
9
+ end
6
10
  end
7
11
  end