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
@@ -1,10 +0,0 @@
1
- module Intercom
2
- module RequiresParameters
3
-
4
- def requires_parameters(parameters, required)
5
- missing = Array(required) - parameters.keys.map(&:to_s)
6
- raise ArgumentError.new("Missing required parameters (#{missing.join(', ')}).") unless missing.empty?
7
- end
8
-
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- require 'intercom/user_resource'
2
-
3
- module Intercom
4
- # object representing a social profile for the User (see )http://docs.intercom.io/#SocialProfiles).
5
- # Read only part of the {User} object
6
- class SocialProfile
7
- # @return [String] type e.g. twitter, facebook etc.
8
- attr_reader :type
9
- # @return [String] id
10
- attr_reader :id
11
- # @return [String] url
12
- attr_reader :url
13
- # @return [String] username
14
- attr_reader :username
15
-
16
- # @private
17
- def initialize(params)
18
- @type = params["type"]
19
- @id = params["id"]
20
- @url = params["url"]
21
- @username = params["username"]
22
- end
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- module Intercom
2
- # Our api returns date as unix time stamps. This module helps marshall to and from {Time} objects.
3
- module UnixTimestampUnwrapper
4
- def time_at(attribute_name)
5
- Time.at(@attributes[attribute_name]) if @attributes[attribute_name]
6
- end
7
-
8
- def set_time_at(attribute_name, time)
9
- @attributes[attribute_name.to_s] = (time.nil?) ? nil : time.to_i
10
- end
11
- end
12
- end
@@ -1,52 +0,0 @@
1
- require 'intercom/user_resource'
2
- require 'intercom/flat_store'
3
- require 'intercom/social_profile'
4
-
5
- module Intercom
6
- # A collection of your Users from Intercom
7
- # Uses the paginated users api under the covers (http://docs.intercom.io/api#getting_all_users)
8
- #
9
- # == Examples:
10
- #
11
- # Iterating over each user
12
- # Intercom::User.all.each do |user|
13
- # puts user.inspect
14
- # end
15
- #
16
- class UserCollectionProxy
17
-
18
- QUERYABLE_ATTRIBUTES = [:tag_id, :tag_name]
19
-
20
- attr_accessor :query
21
-
22
- def initialize(attributes={})
23
- self.query = attributes.reject{ |key, value| !QUERYABLE_ATTRIBUTES.include?(key) }
24
- end
25
-
26
- # yields each {User} to the block provided
27
- # @return [void]
28
- def each(&block)
29
- page = 1
30
- fetch_another_page = true
31
- while fetch_another_page
32
- current_page = Intercom.get("/v1/users", query.merge({:page => page}))
33
- current_page["users"].each do |user|
34
- block.call User.from_api(user)
35
- end
36
- page = page + 1
37
- fetch_another_page = !current_page["next_page"].nil?
38
- end
39
- end
40
-
41
- include Enumerable
42
-
43
- # This method exists as an optimisation of Enumerable#count,
44
- # which would potentially fetch multiple pages of users.
45
- def count(item=nil) #:nodoc:
46
- return super unless item.nil?
47
- return super if block_given?
48
-
49
- Intercom::User.count
50
- end
51
- end
52
- end
@@ -1,82 +0,0 @@
1
- require 'intercom/unix_timestamp_unwrapper'
2
- require 'intercom/requires_parameters'
3
-
4
- module Intercom
5
- # Base class for resources tied off a {User}, all of which are scoped by either the users :email or :user_id.
6
- class UserResource
7
- extend RequiresParameters
8
- include UnixTimestampUnwrapper
9
-
10
- def initialize(attributes={})
11
- self.attributes = attributes
12
- end
13
-
14
- # @return [Hash] hash of all the attributes in the structure they will be sent to the api
15
- def to_hash
16
- UserResource.for_wire(@attributes)
17
- end
18
-
19
- # @return [String] email address
20
- def email
21
- @attributes["email"]
22
- end
23
-
24
- # @param [String] email
25
- # @return [String]
26
- def email=(email)
27
- @attributes["email"] = email
28
- end
29
-
30
- # @return [String] user_id
31
- def user_id
32
- @attributes["user_id"]
33
- end
34
-
35
- # @param [String] user_id
36
- # @return [String]
37
- def user_id=(user_id)
38
- @attributes["user_id"] = user_id
39
- end
40
-
41
- # updates the internal state of this {UserResource} based on the response from the API
42
- # @return [UserResource] self
43
- def update_from_api_response(api_response)
44
- api_response.each do |key, value|
45
- setter_method = "#{key.to_s}="
46
- if self.respond_to?(setter_method, true)
47
- self.send(setter_method, value)
48
- else
49
- @attributes[key.to_s] = value
50
- end
51
- end
52
- self
53
- end
54
-
55
- private
56
-
57
- def attributes=(attributes={})
58
- @attributes = {}
59
- (attributes || {}).each do |key, value|
60
- self.send("#{key.to_s}=", value)
61
- end
62
- end
63
-
64
- def self.for_wire(object)
65
- return object.for_wire if object.respond_to?(:for_wire)
66
- return object.map { |item| for_wire(item) } if object.is_a?(Array)
67
- return object.inject({}) { |result, (k, value)| result[k] = for_wire(value); result } if object.is_a?(Hash)
68
- return object.to_i if object.is_a?(Time)
69
- object
70
- end
71
-
72
- def self.from_api(api_response)
73
- obj = self.new
74
- obj.update_from_api_response(api_response)
75
- end
76
-
77
- def method_missing(method, *args, &block)
78
- return @attributes[method.to_s] if @attributes.has_key?(method.to_s)
79
- super
80
- end
81
- end
82
- end
@@ -1,45 +0,0 @@
1
- {
2
- "intercom_id": "528f291df8d4a41d8c000088",
3
- "email": "somebody@example.com",
4
- "user_id": "123",
5
- "name": "Somebody",
6
- "created_at": 1270000000,
7
- "last_impression_at": 1300000000,
8
- "custom_data": {
9
- "app_name": "Genesis",
10
- "monthly_spend": 155.5,
11
- "team_mates": 7
12
- },
13
- "social_profiles": [
14
- {
15
- "type": "twitter",
16
- "url": "http://twitter.com/abc",
17
- "username": "abc"
18
- },
19
- {
20
- "type": "facebook",
21
- "url": "http://facebook.com/vanity",
22
- "username": "vanity",
23
- "id": "13241141441141413"
24
- }
25
- ],
26
- "location_data": {
27
- "city_name": "Santiago",
28
- "continent_code": "SA",
29
- "country_name": "Chile",
30
- "latitude": -33.44999999999999,
31
- "longitude": -70.6667,
32
- "postal_code": "",
33
- "region_name": "12",
34
- "timezone": "Chile/Continental",
35
- "country_code": "CHL"
36
- },
37
- "session_count": 0,
38
- "last_seen_ip": "127.0.0.1",
39
- "last_seen_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
40
- "unsubscribed_from_emails": false,
41
- "avatar_url": "https://graph.facebook.com/13241141441141413/picture?width=24&height=24",
42
- "company_ids": [
43
-
44
- ]
45
- }
@@ -1,3 +0,0 @@
1
- {
2
- "unread_messages": 1
3
- }
@@ -1,44 +0,0 @@
1
- {
2
- "created_at": 1385114541,
3
- "updated_at": 1385028141,
4
- "read": true,
5
- "created_by_user": true,
6
- "thread_id": 5591,
7
- "message_id": 5591,
8
- "message_type": "conversation",
9
- "interrupt": true,
10
- "messages": [
11
- {
12
- "created_at": 1385114541,
13
- "url": null,
14
- "html": "<p>Hey Intercom, What is up?</p>\n\n<p></p>",
15
- "subject": "",
16
- "from": {
17
- "email": "bob@example.com",
18
- "user_id": "456",
19
- "name": "Bob",
20
- "is_admin": false,
21
- "avatar": {
22
- }
23
- }
24
- },
25
- {
26
- "created_at": 1384941741,
27
- "url": null,
28
- "html": "<p>Not much, you?\n</p>"
29
- },
30
- {
31
- "created_at": 1385028141,
32
- "url": null,
33
- "html": "<p>Not much either :(</p>\n\n<p></p>",
34
- "from": {
35
- "email": "bob@example.com",
36
- "user_id": "123",
37
- "name": "Bob",
38
- "is_admin": false,
39
- "avatar": {
40
- }
41
- }
42
- }
43
- ]
44
- }
@@ -1,46 +0,0 @@
1
- [
2
- {
3
- "created_at": 1385114400,
4
- "updated_at": 1385028000,
5
- "read": true,
6
- "created_by_user": true,
7
- "thread_id": 5591,
8
- "message_id": 5591,
9
- "message_type": "conversation",
10
- "interrupt": true,
11
- "messages": [
12
- {
13
- "created_at": 1385114400,
14
- "url": null,
15
- "html": "<p>Hey Intercom, What is up?</p>\n\n<p></p>",
16
- "subject": "",
17
- "from": {
18
- "email": "somebody@example.com",
19
- "user_id": "123",
20
- "name": "Somebody",
21
- "is_admin": false,
22
- "avatar": {
23
- }
24
- }
25
- },
26
- {
27
- "created_at": 1384941600,
28
- "url": null,
29
- "html": "<p>Not much, you?\n</p>"
30
- },
31
- {
32
- "created_at": 1385028000,
33
- "url": null,
34
- "html": "<p>Not much either :(</p>\n\n<p></p>",
35
- "from": {
36
- "email": "somebody@example.com",
37
- "user_id": "123",
38
- "name": "Somebody",
39
- "is_admin": false,
40
- "avatar": {
41
- }
42
- }
43
- }
44
- ]
45
- }
46
- ]
@@ -1,49 +0,0 @@
1
- {
2
- "html": "<p>This is a note</p>",
3
- "created_at": null,
4
- "user": {
5
- "intercom_id": "528f2cbb1b393a6e470000e6",
6
- "email": "somebody@example.com",
7
- "user_id": "123",
8
- "name": "Somebody",
9
- "created_at": 1270000000,
10
- "last_impression_at": 1300000000,
11
- "custom_data": {
12
- "app_name": "Genesis",
13
- "monthly_spend": 155.5,
14
- "team_mates": 7
15
- },
16
- "social_profiles": [
17
- {
18
- "type": "twitter",
19
- "url": "http://twitter.com/abc",
20
- "username": "abc"
21
- },
22
- {
23
- "type": "facebook",
24
- "url": "http://facebook.com/vanity",
25
- "username": "vanity",
26
- "id": "13241141441141413"
27
- }
28
- ],
29
- "location_data": {
30
- "city_name": "Santiago",
31
- "continent_code": "SA",
32
- "country_name": "Chile",
33
- "latitude": -33.44999999999999,
34
- "longitude": -70.6667,
35
- "postal_code": "",
36
- "region_name": "12",
37
- "timezone": "Chile/Continental",
38
- "country_code": "CHL"
39
- },
40
- "session_count": 0,
41
- "last_seen_ip": "127.0.0.1",
42
- "last_seen_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
43
- "unsubscribed_from_emails": false,
44
- "avatar_url": "https://graph.facebook.com/13241141441141413/picture?width=24&height=24",
45
- "company_ids": [
46
-
47
- ]
48
- }
49
- }
@@ -1,144 +0,0 @@
1
- {
2
- "users": [
3
- {
4
- "intercom_id": "528f27c330972d783600006d",
5
- "email": "first.user@example.com",
6
- "user_id": "123",
7
- "name": "First User",
8
- "created_at": 1270000000,
9
- "last_impression_at": 1300000000,
10
- "custom_data": {
11
- "app_name": "Genesis",
12
- "monthly_spend": 155.5,
13
- "team_mates": 7
14
- },
15
- "social_profiles": [
16
- {
17
- "type": "twitter",
18
- "url": "http://twitter.com/abc",
19
- "username": "abc"
20
- },
21
- {
22
- "type": "facebook",
23
- "url": "http://facebook.com/vanity",
24
- "username": "vanity",
25
- "id": "13241141441141413"
26
- }
27
- ],
28
- "location_data": {
29
- "city_name": "Santiago",
30
- "continent_code": "SA",
31
- "country_name": "Chile",
32
- "latitude": -33.44999999999999,
33
- "longitude": -70.6667,
34
- "postal_code": "",
35
- "region_name": "12",
36
- "timezone": "Chile/Continental",
37
- "country_code": "CHL"
38
- },
39
- "session_count": 0,
40
- "last_seen_ip": "127.0.0.1",
41
- "last_seen_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
42
- "unsubscribed_from_emails": false,
43
- "avatar_url": "https://graph.facebook.com/13241141441141413/picture?width=24&height=24",
44
- "company_ids": [
45
-
46
- ]
47
- },
48
- {
49
- "intercom_id": "528f27c330972d7836000070",
50
- "email": "second.user@example.com",
51
- "user_id": "123",
52
- "name": "Second User",
53
- "created_at": 1270000000,
54
- "last_impression_at": 1300000000,
55
- "custom_data": {
56
- "app_name": "Genesis",
57
- "monthly_spend": 155.5,
58
- "team_mates": 7
59
- },
60
- "social_profiles": [
61
- {
62
- "type": "twitter",
63
- "url": "http://twitter.com/abc",
64
- "username": "abc"
65
- },
66
- {
67
- "type": "facebook",
68
- "url": "http://facebook.com/vanity",
69
- "username": "vanity",
70
- "id": "13241141441141413"
71
- }
72
- ],
73
- "location_data": {
74
- "city_name": "Santiago",
75
- "continent_code": "SA",
76
- "country_name": "Chile",
77
- "latitude": -33.44999999999999,
78
- "longitude": -70.6667,
79
- "postal_code": "",
80
- "region_name": "12",
81
- "timezone": "Chile/Continental",
82
- "country_code": "CHL"
83
- },
84
- "session_count": 0,
85
- "last_seen_ip": "127.0.0.1",
86
- "last_seen_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
87
- "unsubscribed_from_emails": false,
88
- "avatar_url": "https://graph.facebook.com/13241141441141413/picture?width=24&height=24",
89
- "company_ids": [
90
-
91
- ]
92
- },
93
- {
94
- "intercom_id": "528f27c330972d7836000073",
95
- "email": "third.user@example.com",
96
- "user_id": "123",
97
- "name": "Third User",
98
- "created_at": 1270000000,
99
- "last_impression_at": 1300000000,
100
- "custom_data": {
101
- "app_name": "Genesis",
102
- "monthly_spend": 155.5,
103
- "team_mates": 7
104
- },
105
- "social_profiles": [
106
- {
107
- "type": "twitter",
108
- "url": "http://twitter.com/abc",
109
- "username": "abc"
110
- },
111
- {
112
- "type": "facebook",
113
- "url": "http://facebook.com/vanity",
114
- "username": "vanity",
115
- "id": "13241141441141413"
116
- }
117
- ],
118
- "location_data": {
119
- "city_name": "Santiago",
120
- "continent_code": "SA",
121
- "country_name": "Chile",
122
- "latitude": -33.44999999999999,
123
- "longitude": -70.6667,
124
- "postal_code": "",
125
- "region_name": "12",
126
- "timezone": "Chile/Continental",
127
- "country_code": "CHL"
128
- },
129
- "session_count": 0,
130
- "last_seen_ip": "127.0.0.1",
131
- "last_seen_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
132
- "unsubscribed_from_emails": false,
133
- "avatar_url": "https://graph.facebook.com/13241141441141413/picture?width=24&height=24",
134
- "company_ids": [
135
-
136
- ]
137
- }
138
- ],
139
- "total_count": 3,
140
- "page": 1,
141
- "next_page": null,
142
- "previous_page": null,
143
- "total_pages": 1
144
- }