intercom 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -8
  3. data/Gemfile +3 -0
  4. data/README.md +208 -52
  5. data/changes.txt +3 -0
  6. data/intercom.gemspec +2 -2
  7. data/lib/ext/hash.rb +18 -0
  8. data/lib/intercom.rb +38 -43
  9. data/lib/intercom/api_operations/count.rb +16 -0
  10. data/lib/intercom/api_operations/delete.rb +15 -0
  11. data/lib/intercom/api_operations/find.rb +22 -0
  12. data/lib/intercom/api_operations/find_all.rb +33 -0
  13. data/lib/intercom/api_operations/list.rb +17 -0
  14. data/lib/intercom/api_operations/load.rb +15 -0
  15. data/lib/intercom/api_operations/save.rb +44 -0
  16. data/lib/intercom/collection_proxy.rb +66 -0
  17. data/lib/intercom/company.rb +29 -0
  18. data/lib/intercom/conversation.rb +15 -0
  19. data/lib/intercom/count.rb +21 -0
  20. data/lib/intercom/errors.rb +52 -0
  21. data/lib/intercom/event.rb +4 -101
  22. data/lib/intercom/extended_api_operations/reply.rb +16 -0
  23. data/lib/intercom/extended_api_operations/tags.rb +14 -0
  24. data/lib/intercom/extended_api_operations/users.rb +17 -0
  25. data/lib/intercom/generic_handlers/base_handler.rb +22 -0
  26. data/lib/intercom/generic_handlers/count.rb +59 -0
  27. data/lib/intercom/generic_handlers/tag.rb +71 -0
  28. data/lib/intercom/generic_handlers/tag_find_all.rb +47 -0
  29. data/lib/intercom/lib/dynamic_accessors.rb +59 -0
  30. data/lib/intercom/lib/dynamic_accessors_on_method_missing.rb +53 -0
  31. data/lib/intercom/lib/flat_store.rb +31 -0
  32. data/lib/intercom/lib/typed_json_deserializer.rb +52 -0
  33. data/lib/intercom/message.rb +9 -0
  34. data/lib/intercom/note.rb +14 -42
  35. data/lib/intercom/request.rb +40 -4
  36. data/lib/intercom/segment.rb +14 -0
  37. data/lib/intercom/tag.rb +19 -78
  38. data/lib/intercom/traits/api_resource.rb +120 -0
  39. data/lib/intercom/traits/dirty_tracking.rb +33 -0
  40. data/lib/intercom/traits/generic_handler_binding.rb +29 -0
  41. data/lib/intercom/traits/incrementable_attributes.rb +23 -0
  42. data/lib/intercom/user.rb +25 -361
  43. data/lib/intercom/utils.rb +50 -0
  44. data/lib/intercom/version.rb +1 -1
  45. data/spec/spec_helper.rb +64 -33
  46. data/spec/unit/intercom/collection_proxy_spec.rb +34 -0
  47. data/spec/unit/intercom/event_spec.rb +25 -0
  48. data/spec/unit/intercom/{flat_store_spec.rb → lib/flat_store_spec.rb} +7 -7
  49. data/spec/unit/intercom/note_spec.rb +5 -4
  50. data/spec/unit/intercom/tag_spec.rb +3 -3
  51. data/spec/unit/intercom/traits/api_resource_spec.rb +79 -0
  52. data/spec/unit/intercom/user_spec.rb +101 -119
  53. data/spec/unit/intercom_spec.rb +7 -7
  54. metadata +50 -26
  55. data/lib/intercom/flat_store.rb +0 -27
  56. data/lib/intercom/hashable_object.rb +0 -22
  57. data/lib/intercom/impression.rb +0 -63
  58. data/lib/intercom/message_thread.rb +0 -189
  59. data/lib/intercom/requires_parameters.rb +0 -10
  60. data/lib/intercom/social_profile.rb +0 -24
  61. data/lib/intercom/unix_timestamp_unwrapper.rb +0 -12
  62. data/lib/intercom/user_collection_proxy.rb +0 -52
  63. data/lib/intercom/user_resource.rb +0 -82
  64. data/spec/integration/fixtures/v1-user.json +0 -45
  65. data/spec/integration/fixtures/v1-users-impression.json +0 -3
  66. data/spec/integration/fixtures/v1-users-message_thread.json +0 -44
  67. data/spec/integration/fixtures/v1-users-message_threads.json +0 -46
  68. data/spec/integration/fixtures/v1-users-note.json +0 -49
  69. data/spec/integration/fixtures/v1-users.json +0 -144
  70. data/spec/integration/intercom_api_integration_spec.rb +0 -134
  71. data/spec/unit/intercom/impression_spec.rb +0 -18
  72. data/spec/unit/intercom/message_thread_spec.rb +0 -74
  73. data/spec/unit/intercom/user_collection_proxy_spec.rb +0 -46
  74. data/spec/unit/intercom/user_event_spec.rb +0 -83
  75. data/spec/unit/intercom/user_resource_spec.rb +0 -13
@@ -8,18 +8,18 @@ describe Intercom do
8
8
  describe "API" do
9
9
  before do
10
10
  Intercom.app_id = "abc123"
11
- Intercom.api_key = "super-secret-key"
11
+ Intercom.app_api_key = "super-secret-key"
12
12
  end
13
13
 
14
- it "raises ArgumentError if no app_id or api_key specified" do
14
+ it "raises ArgumentError if no app_id or app_api_key specified" do
15
15
  Intercom.app_id = nil
16
- Intercom.api_key = nil
17
- proc { Intercom.target_base_url }.must_raise ArgumentError, "You must set both Intercom.app_id and Intercom.api_key to use this client. See https://github.com/intercom/intercom-ruby for usage examples."
16
+ Intercom.app_api_key = nil
17
+ proc { Intercom.target_base_url }.must_raise ArgumentError, "You must set both Intercom.app_id and Intercom.app_api_key to use this client. See https://github.com/intercom/intercom-ruby for usage examples."
18
18
  end
19
19
 
20
- it "returns the app_id and api_key previously set" do
20
+ it "returns the app_id and app_api_key previously set" do
21
21
  Intercom.app_id.must_equal "abc123"
22
- Intercom.api_key.must_equal "super-secret-key"
22
+ Intercom.app_api_key.must_equal "super-secret-key"
23
23
  end
24
24
 
25
25
  it "defaults to https to api.intercom.io" do
@@ -81,4 +81,4 @@ describe Intercom do
81
81
  Intercom.check_required_params("email" => "bob@example.com", :something => "else")
82
82
  Intercom.check_required_params(:user_id => "123")
83
83
  end
84
- end
84
+ end
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: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -11,10 +11,11 @@ authors:
11
11
  - Kyle Daigle
12
12
  - Declan McGrath
13
13
  - Jamie Osler
14
+ - Bob Long
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
- date: 2014-05-27 00:00:00.000000000 Z
18
+ date: 2014-06-17 00:00:00.000000000 Z
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: minitest
@@ -97,6 +98,7 @@ email:
97
98
  - kyle@digitalworkbox.com
98
99
  - declan@intercom.io
99
100
  - jamie@intercom.io
101
+ - bob@intercom.io
100
102
  executables: []
101
103
  extensions: []
102
104
  extra_rdoc_files: []
@@ -110,38 +112,51 @@ files:
110
112
  - changes.txt
111
113
  - intercom.gemspec
112
114
  - lib/data/cacert.pem
115
+ - lib/ext/hash.rb
113
116
  - lib/intercom.rb
117
+ - lib/intercom/api_operations/count.rb
118
+ - lib/intercom/api_operations/delete.rb
119
+ - lib/intercom/api_operations/find.rb
120
+ - lib/intercom/api_operations/find_all.rb
121
+ - lib/intercom/api_operations/list.rb
122
+ - lib/intercom/api_operations/load.rb
123
+ - lib/intercom/api_operations/save.rb
124
+ - lib/intercom/collection_proxy.rb
125
+ - lib/intercom/company.rb
126
+ - lib/intercom/conversation.rb
127
+ - lib/intercom/count.rb
128
+ - lib/intercom/errors.rb
114
129
  - lib/intercom/event.rb
115
- - lib/intercom/flat_store.rb
116
- - lib/intercom/hashable_object.rb
117
- - lib/intercom/impression.rb
118
- - lib/intercom/message_thread.rb
130
+ - lib/intercom/extended_api_operations/reply.rb
131
+ - lib/intercom/extended_api_operations/tags.rb
132
+ - lib/intercom/extended_api_operations/users.rb
133
+ - lib/intercom/generic_handlers/base_handler.rb
134
+ - lib/intercom/generic_handlers/count.rb
135
+ - lib/intercom/generic_handlers/tag.rb
136
+ - lib/intercom/generic_handlers/tag_find_all.rb
137
+ - lib/intercom/lib/dynamic_accessors.rb
138
+ - lib/intercom/lib/dynamic_accessors_on_method_missing.rb
139
+ - lib/intercom/lib/flat_store.rb
140
+ - lib/intercom/lib/typed_json_deserializer.rb
141
+ - lib/intercom/message.rb
119
142
  - lib/intercom/note.rb
120
143
  - lib/intercom/request.rb
121
- - lib/intercom/requires_parameters.rb
122
- - lib/intercom/social_profile.rb
144
+ - lib/intercom/segment.rb
123
145
  - lib/intercom/tag.rb
124
- - lib/intercom/unix_timestamp_unwrapper.rb
146
+ - lib/intercom/traits/api_resource.rb
147
+ - lib/intercom/traits/dirty_tracking.rb
148
+ - lib/intercom/traits/generic_handler_binding.rb
149
+ - lib/intercom/traits/incrementable_attributes.rb
125
150
  - lib/intercom/user.rb
126
- - lib/intercom/user_collection_proxy.rb
127
- - lib/intercom/user_resource.rb
151
+ - lib/intercom/utils.rb
128
152
  - lib/intercom/version.rb
129
- - spec/integration/fixtures/v1-user.json
130
- - spec/integration/fixtures/v1-users-impression.json
131
- - spec/integration/fixtures/v1-users-message_thread.json
132
- - spec/integration/fixtures/v1-users-message_threads.json
133
- - spec/integration/fixtures/v1-users-note.json
134
- - spec/integration/fixtures/v1-users.json
135
- - spec/integration/intercom_api_integration_spec.rb
136
153
  - spec/spec_helper.rb
137
- - spec/unit/intercom/flat_store_spec.rb
138
- - spec/unit/intercom/impression_spec.rb
139
- - spec/unit/intercom/message_thread_spec.rb
154
+ - spec/unit/intercom/collection_proxy_spec.rb
155
+ - spec/unit/intercom/event_spec.rb
156
+ - spec/unit/intercom/lib/flat_store_spec.rb
140
157
  - spec/unit/intercom/note_spec.rb
141
158
  - spec/unit/intercom/tag_spec.rb
142
- - spec/unit/intercom/user_collection_proxy_spec.rb
143
- - spec/unit/intercom/user_event_spec.rb
144
- - spec/unit/intercom/user_resource_spec.rb
159
+ - spec/unit/intercom/traits/api_resource_spec.rb
145
160
  - spec/unit/intercom/user_spec.rb
146
161
  - spec/unit/intercom_spec.rb
147
162
  homepage: https://www.intercom.io
@@ -164,9 +179,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
179
  version: '0'
165
180
  requirements: []
166
181
  rubyforge_project: intercom
167
- rubygems_version: 2.0.3
182
+ rubygems_version: 2.0.14
168
183
  signing_key:
169
184
  specification_version: 4
170
185
  summary: Ruby bindings for the Intercom API
171
- test_files: []
186
+ test_files:
187
+ - spec/spec_helper.rb
188
+ - spec/unit/intercom/collection_proxy_spec.rb
189
+ - spec/unit/intercom/event_spec.rb
190
+ - spec/unit/intercom/lib/flat_store_spec.rb
191
+ - spec/unit/intercom/note_spec.rb
192
+ - spec/unit/intercom/tag_spec.rb
193
+ - spec/unit/intercom/traits/api_resource_spec.rb
194
+ - spec/unit/intercom/user_spec.rb
195
+ - spec/unit/intercom_spec.rb
172
196
  has_rdoc:
@@ -1,27 +0,0 @@
1
- module Intercom
2
- # Sub-class of {Hash} for storing custom data attributes.
3
- # Doesn't allow nested Hashes or Arrays. And requires {String} or {Symbol} keys.
4
- class FlatStore < Hash
5
- def initialize(attributes={})
6
- (attributes).each do |key, value|
7
- validate_key_and_value(key, value)
8
- self[key] = value
9
- end
10
- end
11
-
12
- def []=(key, value)
13
- validate_key_and_value(key, value)
14
- super(key.to_s, value)
15
- end
16
-
17
- def [](key)
18
- super(key.to_s)
19
- end
20
-
21
- private
22
- def validate_key_and_value(key, value)
23
- raise ArgumentError.new("This does not support nested data structures (key: #{key}, value: #{value}") if value.is_a?(Array) || value.is_a?(Hash)
24
- raise ArgumentError.new("Key must be String or Symbol: #{key}") unless key.is_a?(String) || key.is_a?(Symbol)
25
- end
26
- end
27
- end
@@ -1,22 +0,0 @@
1
- module Intercom
2
- module HashableObject
3
- def from_hash(hash)
4
- hash.each {|attribute, value| instance_variable_set("@#{attribute}".to_sym, value) }
5
- end
6
-
7
- def to_hash
8
- instance_variables.inject({}) do |hash, var|
9
- hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
10
- hash
11
- end
12
- end
13
-
14
- def displayable_attributes
15
- Hash[ to_hash.select {|attribute, value| self.respond_to?(attribute) } ]
16
- end
17
-
18
- def to_wire
19
- Hash[ to_hash.select {|attribute, value| self.respond_to?("#{attribute.to_s}=") } ]
20
- end
21
- end
22
- end
@@ -1,63 +0,0 @@
1
- require 'intercom/user_resource'
2
-
3
- module Intercom
4
-
5
- ##
6
- # Represents a users interaction with your app (eg page view, or using a particular feature)
7
- #
8
- # An impressions contains user_ip, user_agent and location.
9
- #
10
- # == Examples
11
- #
12
- # impression = Intercom::Impression.create(:email => "person@example.com", :location => "/pricing/upgrade",
13
- # :user_ip => '1.2.3.4', :user_agent => "my-service-iphone-app-1.2")
14
- # The impression response will contain {#unread_messages}
15
- # impression.unread_messages
16
- # You can also create an impression and save it like this:
17
- # impression = Intercom::Impression.new
18
- # impression.email = "person@example.com"
19
- # impression.location = "person@example.com"
20
- # ....
21
- # impression.save
22
- class Impression < UserResource
23
- ##
24
- # Creates a new Impression using params and saves it
25
- # @see #save
26
- def self.create(params)
27
- Impression.new(params).save
28
- end
29
-
30
- ##
31
- # Records that a user has interacted with your application, including the 'location' within the app they used
32
- def save
33
- response = Intercom.post("/v1/users/impressions", to_hash)
34
- self.update_from_api_response(response)
35
- end
36
-
37
- ##
38
- # Set the ip address of the user for this impression
39
- def user_ip=(user_ip)
40
- @attributes["user_ip"] = user_ip
41
- end
42
-
43
- ##
44
- # Set the location in your application that this impression occurred. E.g. the url in a web app, or perhaps the screen in a desktop or phone application.
45
- def location=(location)
46
- @attributes["location"] = location
47
- end
48
-
49
- ##
50
- # Set the user agent of the user this impression (E.g. their browser user agent, or the name and version of a desktop or phone application)
51
- def user_agent=(user_agent)
52
- @attributes["user_agent"] = user_agent
53
- end
54
-
55
- ##
56
- # For convenience, after saving, the unread_messages count will be updated with the number of unread messages for the user for their current location.
57
- #
58
- # Remember, Auto Messages (http://docs.intercom.io/#AutoMessages) can be targeted to only show when a user views a particular page in your application.
59
- def unread_messages
60
- @attributes["unread_messages"]
61
- end
62
- end
63
- end
@@ -1,189 +0,0 @@
1
- require 'intercom/user_resource'
2
-
3
- module Intercom
4
- # A conversation with a user. Either started by the users sending a message to your application using Intercom, or by an Admin sending a message to the user.
5
- # == Examples
6
- #
7
- # Fetching all {MessageThread}'s for a user
8
- # message_threads = Intercom::MessageThread.find_all(:email => "bob@example.com")
9
- # message_threads.size
10
- # message_thread = message_threads[0]
11
- #
12
- # Fetching a particular {MessageThread}
13
- # message_thread = Intercom::MessageThread.find(:email => "bob@example.com", :thread_id => 123)
14
- # message_thread.messages.map{|message| message.html }
15
- #
16
- # Creating a {MessageThread} on behalf of a user:
17
- # message_thread = Intercom::MessageThread.create(:email => "bob@example.com", :body => "Hello, I need some help....")
18
- #
19
- class MessageThread < UserResource
20
- include UnixTimestampUnwrapper
21
-
22
- # Finds a particular Message identified by thread_id
23
- # @return [Message]
24
- def self.find(params)
25
- requires_parameters(params, %W(thread_id))
26
- api_response = Intercom.get("/v1/users/message_threads", params)
27
- MessageThread.from_api(api_response)
28
- end
29
-
30
- # Finds all Messages to show a particular user
31
- # @return [Array<Message>]
32
- def self.find_all(params)
33
- response = Intercom.get("/v1/users/message_threads", params)
34
- response.map { |message| MessageThread.from_api(message) }
35
- end
36
-
37
- # Either creates a new message from this user to your application admins, or a comment on an existing one
38
- # @return [Message]
39
- def self.create(params)
40
- requires_parameters(params, %W(body))
41
- MessageThread.new(params).save
42
- end
43
-
44
- # Marks a message (identified by thread_id) as read
45
- # @return [Message]
46
- def self.mark_as_read(params)
47
- requires_parameters(params, %W(thread_id))
48
- MessageThread.new({"read" => true}.merge(params)).save(:put)
49
- end
50
-
51
- # @return [Message]
52
- def save(method=:post)
53
- response = Intercom.send(method, "/v1/users/message_threads", to_hash)
54
- self.update_from_api_response(response)
55
- end
56
-
57
- # @return [Message]
58
- def mark_as_read!
59
- Intercom::MessageThread.mark_as_read(:thread_id => thread_id, :email => email)
60
- end
61
-
62
- # Set the content of the message for new message creation.
63
- # @param [String] body of the message. Supports markdown syntax
64
- # @return [String]
65
- def body=(body)
66
- @attributes["body"] = body
67
- end
68
-
69
- # @return [Time] when this {MessageThread} was created
70
- def created_at
71
- time_at("created_at")
72
- end
73
-
74
- # @return [Time] when the last update to this {MessageThread} happened
75
- def updated_at
76
- time_at("updated_at")
77
- end
78
-
79
- # @return [Integer]
80
- # @param [Integer thread_id]
81
- def thread_id=(thread_id)
82
- @attributes["thread_id"] = thread_id
83
- end
84
-
85
- # @return [Integer]
86
- def thread_id
87
- @attributes["thread_id"]
88
- end
89
-
90
- # @return [Boolean]
91
- # @param [Boolean] read whether the latest revision of the thread has been read by the user
92
- def read=(read)
93
- @attributes["read"] = read
94
- end
95
-
96
- # @return [Boolean]
97
- def read
98
- @attributes["read"]
99
- end
100
-
101
- # @return [String]
102
- # @param [String] read the url that was being viewed when the comment was sent
103
- def url=(url)
104
- @attributes["url"] = url
105
- end
106
-
107
- # @return [String]
108
- def url
109
- @attributes["url"]
110
- end
111
-
112
- # @return [Array<Message>]
113
- def messages
114
- @attributes["messages"].map {|message_hash| Message.new(message_hash)}
115
- end
116
- end
117
-
118
- # a {MessageThread} contains multiple {Message}'s
119
- #
120
- # {Message}'s are a read only part of a {MessageThread}
121
- class Message
122
- include UnixTimestampUnwrapper
123
-
124
- # Used to create a {Message} from part of the response from the API
125
- def initialize(params)
126
- @attributes = params
127
- end
128
-
129
- # @return [MessageAuthor] Author, which can be either an end user, or an Admin for your application
130
- def from
131
- MessageAuthor.new(@attributes["from"])
132
- end
133
-
134
- # @return [String] html markup for the message
135
- def html
136
- @attributes["html"]
137
- end
138
-
139
- # @return [Time] when this message was posted
140
- def created_at
141
- time_at("created_at")
142
- end
143
- end
144
-
145
- # each {Message} in a {MessageThread} has a {MessageAuthor}
146
- #
147
- # Admin authors have a name, avatar_path_25, avatar_path_50, and avatar_path_128. Non-admin authors have a name, user_id and email.
148
- class MessageAuthor
149
- # Used to create a {MessageAuthor} from part of the response from the API
150
- def initialize(params)
151
- @attributes = params
152
- end
153
-
154
- # @return [Boolean] whether this author is an admin or not
155
- def admin?
156
- @attributes['is_admin']
157
- end
158
-
159
- # @return [String] email address of the author (only available when {#admin?} is false)
160
- def email
161
- @attributes['email']
162
- end
163
-
164
- # @return [String] user_id of the author (only available when {#admin?} is false)
165
- def user_id
166
- @attributes['user_id']
167
- end
168
-
169
- # @return [String] url of 25x25 avatar of the admin who posted this message (only available when {#admin?} is true)
170
- def avatar_path_25
171
- self.admin? ? @attributes['avatar']['square_25'] : nil
172
- end
173
-
174
- # @return [String] url of 50x50 avatar of the admin who posted this message (only available when {#admin?} is true)
175
- def avatar_path_50
176
- self.admin? ? @attributes['avatar']['square_50'] : nil
177
- end
178
-
179
- # @return [String] url of 128x128 avatar of the admin who posted this message (only available when {#admin?} is true)
180
- def avatar_path_128
181
- self.admin? ? @attributes['avatar']['square_128'] : nil
182
- end
183
-
184
- # @return [String] real name of the Admin/User, when available.
185
- def name
186
- @attributes['name']
187
- end
188
- end
189
- end