intercom 3.5.10 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +35 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +5 -0
  4. data/Gemfile +1 -4
  5. data/README.md +418 -216
  6. data/RELEASING.md +9 -0
  7. data/Rakefile +1 -1
  8. data/changes.txt +141 -0
  9. data/intercom.gemspec +1 -2
  10. data/lib/intercom.rb +34 -19
  11. data/lib/intercom/api_operations/archive.rb +16 -0
  12. data/lib/intercom/api_operations/delete.rb +4 -1
  13. data/lib/intercom/api_operations/find.rb +5 -2
  14. data/lib/intercom/api_operations/find_all.rb +4 -3
  15. data/lib/intercom/api_operations/list.rb +4 -1
  16. data/lib/intercom/api_operations/load.rb +4 -2
  17. data/lib/intercom/api_operations/nested_resource.rb +70 -0
  18. data/lib/intercom/api_operations/request_hard_delete.rb +12 -0
  19. data/lib/intercom/api_operations/save.rb +6 -4
  20. data/lib/intercom/api_operations/scroll.rb +4 -5
  21. data/lib/intercom/api_operations/search.rb +18 -0
  22. data/lib/intercom/article.rb +7 -0
  23. data/lib/intercom/base_collection_proxy.rb +72 -0
  24. data/lib/intercom/client.rb +66 -18
  25. data/lib/intercom/client_collection_proxy.rb +17 -39
  26. data/lib/intercom/collection.rb +7 -0
  27. data/lib/intercom/company.rb +8 -0
  28. data/lib/intercom/contact.rb +22 -3
  29. data/lib/intercom/conversation.rb +5 -0
  30. data/lib/intercom/data_attribute.rb +7 -0
  31. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  32. data/lib/intercom/deprecated_resources.rb +13 -0
  33. data/lib/intercom/errors.rb +44 -4
  34. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  35. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  36. data/lib/intercom/lead.rb +21 -0
  37. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  38. data/lib/intercom/note.rb +4 -0
  39. data/lib/intercom/request.rb +162 -95
  40. data/lib/intercom/scroll_collection_proxy.rb +38 -42
  41. data/lib/intercom/search_collection_proxy.rb +47 -0
  42. data/lib/intercom/section.rb +23 -0
  43. data/lib/intercom/segment.rb +4 -0
  44. data/lib/intercom/service/article.rb +20 -0
  45. data/lib/intercom/service/base_service.rb +13 -0
  46. data/lib/intercom/service/collection.rb +24 -0
  47. data/lib/intercom/service/company.rb +4 -2
  48. data/lib/intercom/service/contact.rb +29 -6
  49. data/lib/intercom/service/conversation.rb +23 -2
  50. data/lib/intercom/service/data_attribute.rb +20 -0
  51. data/lib/intercom/service/event.rb +12 -0
  52. data/lib/intercom/service/lead.rb +41 -0
  53. data/lib/intercom/service/note.rb +4 -8
  54. data/lib/intercom/service/section.rb +7 -0
  55. data/lib/intercom/service/tag.rb +8 -8
  56. data/lib/intercom/service/team.rb +17 -0
  57. data/lib/intercom/service/user.rb +4 -2
  58. data/lib/intercom/service/visitor.rb +15 -6
  59. data/lib/intercom/tag.rb +4 -0
  60. data/lib/intercom/team.rb +7 -0
  61. data/lib/intercom/traits/api_resource.rb +48 -27
  62. data/lib/intercom/traits/dirty_tracking.rb +8 -1
  63. data/lib/intercom/user.rb +12 -3
  64. data/lib/intercom/utils.rb +13 -2
  65. data/lib/intercom/version.rb +1 -1
  66. data/lib/intercom/visitor.rb +0 -2
  67. data/spec/spec_helper.rb +881 -436
  68. data/spec/unit/intercom/admin_spec.rb +2 -2
  69. data/spec/unit/intercom/article_spec.rb +40 -0
  70. data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
  71. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  72. data/spec/unit/intercom/client_spec.rb +76 -9
  73. data/spec/unit/intercom/collection_spec.rb +32 -0
  74. data/spec/unit/intercom/company_spec.rb +29 -21
  75. data/spec/unit/intercom/contact_spec.rb +365 -29
  76. data/spec/unit/intercom/conversation_spec.rb +70 -7
  77. data/spec/unit/intercom/count_spec.rb +4 -4
  78. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  79. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  80. data/spec/unit/intercom/event_spec.rb +25 -8
  81. data/spec/unit/intercom/job_spec.rb +24 -24
  82. data/spec/unit/intercom/lead_spec.rb +57 -0
  83. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  84. data/spec/unit/intercom/message_spec.rb +1 -1
  85. data/spec/unit/intercom/note_spec.rb +4 -10
  86. data/spec/unit/intercom/request_spec.rb +150 -9
  87. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  88. data/spec/unit/intercom/search_collection_proxy_spec.rb +60 -0
  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 +22 -14
  93. data/spec/unit/intercom/team_spec.rb +21 -0
  94. data/spec/unit/intercom/traits/api_resource_spec.rb +129 -47
  95. data/spec/unit/intercom/user_spec.rb +227 -217
  96. data/spec/unit/intercom/visitor_spec.rb +49 -0
  97. data/spec/unit/intercom_spec.rb +5 -3
  98. metadata +63 -26
  99. data/.travis.yml +0 -6
  100. data/lib/intercom/extended_api_operations/users.rb +0 -16
  101. data/spec/unit/intercom/visitors_spec.rb +0 -61
data/RELEASING.md ADDED
@@ -0,0 +1,9 @@
1
+ # Releasing Intercom
2
+
3
+ We use https://github.com/svenfuchs/gem-release to tag, bump, and release new versions
4
+
5
+ Please add a line to changes.txt before you release a new version.
6
+
7
+ ```
8
+ gem bump --tag --release
9
+ ```
data/Rakefile CHANGED
@@ -18,4 +18,4 @@ Rake::TestTask.new("spec:integration") do |spec|
18
18
  end
19
19
 
20
20
  task :spec => "spec:unit"
21
- task :default => :spec
21
+ task :default => :spec
data/changes.txt CHANGED
@@ -1,3 +1,144 @@
1
+ 4.1.1
2
+ - Fixed bug with deprecated lead resource.
3
+
4
+ 4.1.0
5
+ - Added support for new Articles API.
6
+ - Added support for new Collections API.
7
+ - Added support for new Sections API.
8
+ - Added support to equate two resources.
9
+ - Fixed issue for dirty tracking nested typed objects.
10
+
11
+ 4.0.1
12
+ - Fixed bug with nested resources.
13
+ - Support for add/remove contact on conversation object.
14
+
15
+ 4.0.0
16
+ New version to support API version 2.0.
17
+ - Added support for new Contacts API.
18
+ - Added support for Conversation Search and for Conversation model changes.
19
+ - New DataAttribute class to support the Data Attributes. See README for details on usage.
20
+ - New method to run assignment rules on a conversation: `intercom.conversations.run_assignment_rules(<convo_id>)`.
21
+ - See Migration guide for breaking changes: https://github.com/intercom/intercom-ruby/wiki/Migration-guide-for-v4
22
+
23
+ 3.9.5
24
+ Add Unstable version support
25
+
26
+ 3.9.4
27
+ Add handling for Gateway Timeouts
28
+
29
+ 3.9.3
30
+ Fix regression added in 3.9.2
31
+
32
+ 3.9.2
33
+ Added error handling for malformed responses
34
+
35
+ 3.9.1
36
+ Version skipped in error
37
+
38
+ 3.9.0
39
+ Added Teams endpoint functionality
40
+
41
+ 3.8.1
42
+ Added error handling for company_not_found
43
+
44
+ 3.8.0
45
+ Add support for Customer Search (currently in Unstable API Version)
46
+ https://developers.intercom.com/intercom-api-reference/v0/reference#customers
47
+
48
+ 3.7.7
49
+ Remove deprecated features from Gemspec
50
+
51
+ 3.7.6
52
+ Added error handling for invalid_document error state
53
+
54
+ 3.7.5
55
+ Added error handling for scroll_exists error state
56
+
57
+ 3.7.4
58
+ Added support for API versioning via
59
+ Intercom::Client.new(token: "token", api_version "1.1")
60
+
61
+ 3.7.3
62
+ Added error handling for when an admin cannot be found.
63
+
64
+ 3.7.2
65
+ Added error handling for when an app's custom attribute limits have been reached.
66
+
67
+ 3.7.1
68
+ Extra version bump after faulty previous bump
69
+
70
+ 3.7.0
71
+ Providing the ability to hard delete users as described here:
72
+ https://developers.intercom.com/intercom-api-reference/reference#archive-a-user
73
+
74
+ This chaged the previous delete action to an archive action and added a new hard delete option
75
+ You can still use the delete method but it will archive a user, we added an alias for delete.
76
+ #442 archiving alias
77
+ #410 add ability to hard delete users
78
+
79
+ Alos enabling reply to last from the SDK
80
+ #443 Residently conversations last reply
81
+
82
+ 3.6.2
83
+ #384 Add ability to snooze conversation
84
+ You can now snooze conversations in your app via:
85
+ intercom.conversations.snooze(...)
86
+
87
+ 3.6.1
88
+ #430 Allow all conversations to be listed
89
+ You can now iterate over all conversations for your app via:
90
+ intercom.conversations.all.each { |convo| ... }
91
+
92
+ 3.6.0
93
+ BREAKING CHANGE companies
94
+ We updated companies to be able to list users via company_id as well as id (#428 )
95
+ Note that this is a breaking change as we had to remove the old way of listing users via company.
96
+
97
+ Previously it was:
98
+ intercom.companies.users(company.id)
99
+
100
+ Now you get a list of users in a company by Intercom Company ID
101
+ intercom.companies.users_by_intercom_company_id(company.id)
102
+
103
+ Now you get a list of users in a company by external company_id
104
+ intercom.companies.users_by_company_id(company.company_id)
105
+
106
+ Rate limit handling
107
+ We also improved the way we handle rate limits in PR #409 which was related to issue #405
108
+
109
+ 3.5.23
110
+ - New type of error (ResourceNotUniqueError). Thrown when trying to create a resource that already exists in Intercom
111
+
112
+ 3.5.22
113
+ - Return object type
114
+
115
+ 3.5.21
116
+ - Fix for PR-353 which addressed "NoMethodError in intercom/request"
117
+ - There were issues on older versions of Ruby (<2.3)
118
+ - This PR does not use lonely operator and instead simple checks for nil parsed_body
119
+
120
+ 3.5.17
121
+ - Fix BlockedUserError typo
122
+
123
+ 3.5.16
124
+ - Standardize comparison of attribute as string when input is Hash or JSON
125
+
126
+ 3.5.15
127
+ - UnauthorizedError on invalid token
128
+ - BlockerUserError on restoring blocked user
129
+
130
+ 3.5.14
131
+ - Rate Limit Exception (@jaimeiniesta)
132
+
133
+ 3.5.12
134
+ - Use base_url in initialize parameter
135
+
136
+ 3.5.11
137
+ - Add scroll api for companies
138
+
139
+ 3.5.10
140
+ - Add Support for find_all events pagination (@jkeyes)
141
+
1
142
  3.5.9
2
143
  - Fix event create method
3
144
 
data/intercom.gemspec CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Ruby bindings for the Intercom API}
13
13
  spec.description = %Q{Intercom (https://www.intercom.io) is a customer relationship management and messaging tool for web app owners. This library wraps the api provided by Intercom. See http://docs.intercom.io/api for more details. }
14
14
  spec.license = "MIT"
15
- spec.rubyforge_project = "intercom"
16
15
 
17
16
  spec.files = `git ls-files`.split("\n")
18
17
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -20,12 +19,12 @@ Gem::Specification.new do |spec|
20
19
  spec.require_paths = ["lib"]
21
20
 
22
21
  spec.add_development_dependency 'minitest', '~> 5.4'
22
+ spec.add_development_dependency "m", "~> 1.5.0"
23
23
  spec.add_development_dependency 'rake', '~> 10.3'
24
24
  spec.add_development_dependency 'mocha', '~> 1.0'
25
25
  spec.add_development_dependency "fakeweb", ["~> 1.3"]
26
26
  spec.add_development_dependency "pry"
27
27
 
28
- spec.add_dependency 'json', '>= 1.8'
29
28
  spec.required_ruby_version = '>= 2.1.0'
30
29
  spec.add_development_dependency 'gem-release'
31
30
  end
data/lib/intercom.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "intercom/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'intercom/version'
2
4
  require 'intercom/service/admin'
5
+ require 'intercom/service/article'
6
+ require 'intercom/service/collection'
3
7
  require 'intercom/service/company'
4
8
  require 'intercom/service/contact'
5
9
  require 'intercom/service/conversation'
@@ -10,28 +14,39 @@ require 'intercom/service/note'
10
14
  require 'intercom/service/job'
11
15
  require 'intercom/service/subscription'
12
16
  require 'intercom/service/segment'
17
+ require 'intercom/service/section'
13
18
  require 'intercom/service/tag'
14
- require 'intercom/service/user'
19
+ require 'intercom/service/team'
15
20
  require 'intercom/service/visitor'
21
+ require 'intercom/service/user'
22
+ require 'intercom/service/lead'
23
+ require 'intercom/deprecated_resources.rb'
16
24
  require 'intercom/options'
17
25
  require 'intercom/client'
18
- require "intercom/contact"
19
- require "intercom/count"
20
- require "intercom/user"
21
- require "intercom/company"
22
- require "intercom/note"
23
- require "intercom/job"
24
- require "intercom/tag"
25
- require "intercom/segment"
26
- require "intercom/event"
27
- require "intercom/conversation"
28
- require "intercom/message"
29
- require "intercom/admin"
30
- require "intercom/request"
31
- require "intercom/subscription"
32
- require "intercom/errors"
33
- require "intercom/visitor"
34
- require "json"
26
+ require 'intercom/contact'
27
+ require 'intercom/user'
28
+ require 'intercom/lead'
29
+ require 'intercom/count'
30
+ require 'intercom/collection'
31
+ require 'intercom/company'
32
+ require 'intercom/service/data_attribute'
33
+ require 'intercom/note'
34
+ require 'intercom/job'
35
+ require 'intercom/tag'
36
+ require 'intercom/segment'
37
+ require 'intercom/section'
38
+ require 'intercom/event'
39
+ require 'intercom/conversation'
40
+ require 'intercom/message'
41
+ require 'intercom/admin'
42
+ require 'intercom/article'
43
+ require 'intercom/request'
44
+ require 'intercom/subscription'
45
+ require 'intercom/team'
46
+ require 'intercom/errors'
47
+ require 'intercom/visitor'
48
+ require 'intercom/data_attribute'
49
+ require 'json'
35
50
 
36
51
  ##
37
52
  # Intercom is a customer relationship management and messaging tool for web app owners
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'intercom/utils'
4
+
5
+ module Intercom
6
+ module ApiOperations
7
+ module Archive
8
+ def archive(object)
9
+ @client.delete("/#{collection_name}/#{object.id}", {})
10
+ object
11
+ end
12
+
13
+ alias_method 'delete', 'archive'
14
+ end
15
+ end
16
+ end
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/utils'
2
4
 
3
5
  module Intercom
4
6
  module ApiOperations
5
7
  module Delete
6
8
  def delete(object)
7
- collection_name = Utils.resource_class_to_collection_name(collection_class)
8
9
  @client.delete("/#{collection_name}/#{object.id}", {})
9
10
  object
10
11
  end
12
+
13
+ alias_method 'archive', 'delete'
11
14
  end
12
15
  end
13
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/utils'
2
4
 
3
5
  module Intercom
@@ -5,14 +7,15 @@ module Intercom
5
7
  module Find
6
8
  def find(params)
7
9
  raise BadRequestError, "#{self}#find takes a hash as its parameter but you supplied #{params.inspect}" unless params.is_a? Hash
8
- collection_name = Utils.resource_class_to_collection_name(collection_class)
10
+
9
11
  if params[:id]
10
12
  id = params.delete(:id)
11
13
  response = @client.get("/#{collection_name}/#{id}", params)
12
14
  else
13
15
  response = @client.get("/#{collection_name}", params)
14
16
  end
15
- raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
17
+ raise Intercom::HttpError, 'Http Error - No response entity returned' unless response
18
+
16
19
  from_api(response)
17
20
  end
18
21
  end
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/client_collection_proxy'
2
4
  require 'intercom/utils'
3
5
 
4
6
  module Intercom
5
7
  module ApiOperations
6
8
  module FindAll
7
-
8
9
  def find_all(params)
9
10
  raise BadRequestError, "#find takes a hash as its parameter but you supplied #{params.inspect}" unless params.is_a? Hash
10
- collection_name = Utils.resource_class_to_collection_name(collection_class)
11
+
11
12
  finder_details = {}
12
13
  if params[:id] && !type_switched_finder?(params)
13
14
  finder_details[:url] = "/#{collection_name}/#{params[:id]}"
@@ -16,7 +17,7 @@ module Intercom
16
17
  finder_details[:url] = "/#{collection_name}"
17
18
  finder_details[:params] = params
18
19
  end
19
- ClientCollectionProxy.new(collection_name, finder_details: finder_details, client: @client)
20
+ collection_proxy_class.new(collection_name, collection_class, details: finder_details, client: @client)
20
21
  end
21
22
 
22
23
  private
@@ -1,11 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/client_collection_proxy'
4
+ require 'intercom/base_collection_proxy'
2
5
  require 'intercom/utils'
3
6
 
4
7
  module Intercom
5
8
  module ApiOperations
6
9
  module List
7
10
  def all
8
- ClientCollectionProxy.new(Utils.resource_class_to_collection_name(collection_class), client: @client)
11
+ collection_proxy_class.new(collection_name, collection_class, client: @client)
9
12
  end
10
13
  end
11
14
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom/utils'
2
4
 
3
5
  module Intercom
4
6
  module ApiOperations
5
7
  module Load
6
8
  def load(object)
7
- collection_name = Utils.resource_class_to_collection_name(collection_class)
8
9
  if object.id
9
10
  response = @client.get("/#{collection_name}/#{object.id}", {})
10
11
  else
11
12
  raise "Cannot load #{collection_class} as it does not have a valid id."
12
13
  end
13
- raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
14
+ raise Intercom::HttpError, 'Http Error - No response entity returned' unless response
15
+
14
16
  object.from_response(response)
15
17
  end
16
18
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Intercom
4
+ module ApiOperations
5
+ module NestedResource
6
+ module ClassMethods
7
+ def nested_resource_methods(resource,
8
+ path: nil,
9
+ operations: nil,
10
+ resource_plural: nil)
11
+ resource_plural ||= Utils.pluralize(resource.to_s)
12
+ path ||= resource_plural
13
+ raise ArgumentError, 'operations array required' if operations.nil?
14
+
15
+ resource_url_method = :"#{resource_plural}_url"
16
+
17
+ resource_name = Utils.resource_class_to_collection_name(self)
18
+
19
+ define_method(resource_url_method.to_sym) do |id, nested_id = nil|
20
+ url = "/#{resource_name}/#{id}/#{path}"
21
+ url += "/#{nested_id}" unless nested_id.nil?
22
+ url
23
+ end
24
+
25
+ operations.each do |operation|
26
+ case operation
27
+ when :create
28
+ define_method(:"create_#{resource}") do |params|
29
+ url = send(resource_url_method, self.id)
30
+ response = client.post(url, params)
31
+ raise_no_response_error unless response
32
+ self.class.from_api(response)
33
+ end
34
+ when :add
35
+ define_method(:"add_#{resource}") do |params|
36
+ url = send(resource_url_method, self.id)
37
+ response = client.post(url, params)
38
+ raise_no_response_error unless response
39
+ self.class.from_api(response)
40
+ end
41
+ when :delete
42
+ define_method(:"remove_#{resource}") do |params|
43
+ url = send(resource_url_method, self.id, params[:id])
44
+ response = client.delete(url, params)
45
+ raise_no_response_error unless response
46
+ self.class.from_api(response)
47
+ end
48
+ when :list
49
+ define_method(resource_plural.to_sym) do
50
+ url = send(resource_url_method, self.id)
51
+ resource_class = Utils.constantize_resource_name(resource.to_s)
52
+ resource_class.collection_proxy_class.new(resource_plural, resource_class, details: { url: url }, client: client)
53
+ end
54
+ else
55
+ raise ArgumentError, "Unknown operation: #{operation.inspect}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def self.included(base)
62
+ base.extend(ClassMethods)
63
+ end
64
+
65
+ private def raise_no_response_error
66
+ raise Intercom::HttpError, 'Http Error - No response entity returned'
67
+ end
68
+ end
69
+ end
70
+ end