intercom 0.1.1 → 0.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.
- data/{README.rdoc → README.md} +26 -13
- data/lib/intercom/user.rb +24 -1
- data/lib/intercom/version.rb +1 -1
- data/spec/unit/intercom/user_spec.rb +22 -0
- metadata +4 -4
data/{README.rdoc → README.md}
RENAMED
@@ -1,24 +1,29 @@
|
|
1
|
-
|
1
|
+
# intercom-ruby
|
2
2
|
|
3
|
-
|
3
|
+
Ruby bindings for the Intercom API (https://api.intercom.io).
|
4
4
|
|
5
|
-
|
5
|
+
[API Documentation](https://api.intercom.io)
|
6
|
+
|
7
|
+
[Gem Documentation](http://rubydoc.info/github/intercom/intercom-ruby/master/frames)
|
8
|
+
|
9
|
+
For generating Intercom javascript script tags for Rails, please see https://github.com/intercom/intercom-rails
|
10
|
+
|
11
|
+
## Installation
|
6
12
|
|
7
|
-
== Installation
|
8
13
|
gem install intercom
|
9
14
|
|
10
15
|
Using bundler:
|
11
16
|
|
12
17
|
gem 'intercom'
|
13
18
|
|
14
|
-
|
19
|
+
## Basic Usage
|
15
20
|
|
16
|
-
|
21
|
+
### Configure your access credentials
|
17
22
|
|
18
23
|
Intercom.app_id = "my_app_iddd"
|
19
24
|
Intercom.api_key = "my-super-crazy-api-key"
|
20
25
|
|
21
|
-
|
26
|
+
### Resources
|
22
27
|
|
23
28
|
The API supports:
|
24
29
|
|
@@ -27,9 +32,9 @@ The API supports:
|
|
27
32
|
POST https://api.intercom.io/v1/users/impressions
|
28
33
|
POST https://api.intercom.io/v1/users/notes
|
29
34
|
|
30
|
-
|
35
|
+
### Examples
|
31
36
|
|
32
|
-
|
37
|
+
#### Users
|
33
38
|
user = Intercom::User.find_by_email("bob@example.com")
|
34
39
|
user.custom_data["average_monthly_spend"] = 1234.56
|
35
40
|
user.save
|
@@ -41,23 +46,31 @@ The API supports:
|
|
41
46
|
Intercom::User.all.each {|user| puts %Q(#{user.email} - #{user.custom_data["average_monthly_spend"]}) }
|
42
47
|
Intercom::User.all.map {|user| user.email }
|
43
48
|
|
49
|
+
#### Companies
|
50
|
+
user = Intercom::User.find_by_email("bob@example.com")
|
51
|
+
user.company = {:id => 6, :name => "Intercom"}
|
52
|
+
user.companies = [{:id => 6, :name => "Intercom"}, {:id => 9, :name => "Test Company"}]
|
53
|
+
|
54
|
+
You can also pass custom data within a company:
|
55
|
+
|
56
|
+
user.company = {:id => 6, :name => "Intercom", :referral_source => "Google"}
|
44
57
|
|
45
|
-
|
58
|
+
#### Messages
|
46
59
|
|
47
60
|
Intercom::Message.create(:email => "bob@example.com", :body => "Example message from bob@example.com to your application on Intercom.")
|
48
61
|
Intercom::Message.find(:email => "bob@example.com", :thread_id => 123)
|
49
62
|
Intercom::Message.find_all(:email => "bob@example.com")
|
50
63
|
Intercom::Message.mark_as_read(:email => "bob@example.com", :thread_id => 123)
|
51
64
|
|
52
|
-
|
65
|
+
#### Impressions
|
53
66
|
|
54
67
|
Intercom::Impression.create(:email => "bob@example.com", :location => "/path/in/my/app", :user_ip => "1.2.3.4", :user_agent => "my-savage-iphone-app-0.1"
|
55
68
|
|
56
|
-
|
69
|
+
#### Notes
|
57
70
|
|
58
71
|
Intercom::Note.create(:email => "bob@example.com", :body => "This is the text of the note")
|
59
72
|
|
60
|
-
|
73
|
+
### Errors
|
61
74
|
|
62
75
|
Intercom::AuthenticationError
|
63
76
|
Intercom::ServerError
|
data/lib/intercom/user.rb
CHANGED
@@ -235,7 +235,7 @@ module Intercom
|
|
235
235
|
@attributes["custom_data"] = FlatStore.new(custom_data)
|
236
236
|
end
|
237
237
|
|
238
|
-
#
|
238
|
+
# Company stored for this Intercom::User
|
239
239
|
#
|
240
240
|
# See http://docs.intercom.io/#Companies for more information
|
241
241
|
#
|
@@ -258,6 +258,29 @@ module Intercom
|
|
258
258
|
@attributes["company"] = FlatStore.new(company)
|
259
259
|
end
|
260
260
|
|
261
|
+
# Multiple companies for this Intercom::User
|
262
|
+
#
|
263
|
+
# See http://docs.intercom.io/#Companies for more information
|
264
|
+
#
|
265
|
+
# Example: Setting a company for an existing user
|
266
|
+
# user = Intercom::User.find(:email => "someone@example.com")
|
267
|
+
# user.companies = [{:id => 6, :name => "intercom"}, {:id => 9, :name => "Test Company"}]
|
268
|
+
# user.save
|
269
|
+
#
|
270
|
+
# @return [Array]
|
271
|
+
def companies
|
272
|
+
@attributes["companies"] ||= []
|
273
|
+
end
|
274
|
+
|
275
|
+
# Set an {Array} of {Hash} company attributes to save/update on this user
|
276
|
+
#
|
277
|
+
# @param [Array] companies
|
278
|
+
# @return [Array]
|
279
|
+
def companies=(companies)
|
280
|
+
raise ArgumentError.new("Companies requires an array of hashes of companies") unless companies.is_a?(Array) && companies.all? {|company| company.is_a?(Hash)}
|
281
|
+
@attributes["companies"] = companies.collect {|company| FlatStore.new(company) }
|
282
|
+
end
|
283
|
+
|
261
284
|
protected
|
262
285
|
def social_profiles=(social_profiles) #:nodoc:
|
263
286
|
@social_profiles = social_profiles.map { |account| SocialProfile.new(account) }.freeze
|
data/lib/intercom/version.rb
CHANGED
@@ -81,6 +81,22 @@ describe "Intercom::User" do
|
|
81
81
|
user.to_hash["company"].must_equal "name" => "Intercom", "id" => 6
|
82
82
|
end
|
83
83
|
|
84
|
+
it "allows easy setting of multiple companies" do
|
85
|
+
user = Intercom::User.new()
|
86
|
+
companies = [
|
87
|
+
{"name" => "Intercom", "id" => "6"},
|
88
|
+
{"name" => "Test", "id" => "9"}
|
89
|
+
]
|
90
|
+
user.companies = companies
|
91
|
+
user.to_hash["companies"].must_equal companies
|
92
|
+
end
|
93
|
+
|
94
|
+
it "rejects setting companies without an array of hashes" do
|
95
|
+
user = Intercom::User.new()
|
96
|
+
proc { user.companies = {"name" => "test"} }.must_raise ArgumentError
|
97
|
+
proc { user.companies = [ ["name", "test"] ]}.must_raise ArgumentError
|
98
|
+
end
|
99
|
+
|
84
100
|
it "rejects nested data structures in custom_data" do
|
85
101
|
user = Intercom::User.new()
|
86
102
|
proc { user.custom_data["thing"] = [1] }.must_raise ArgumentError
|
@@ -111,6 +127,12 @@ describe "Intercom::User" do
|
|
111
127
|
user.save
|
112
128
|
end
|
113
129
|
|
130
|
+
it "saves a user with a companies" do
|
131
|
+
user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :companies => [{:id => 6, :name => "Intercom"}])
|
132
|
+
Intercom.expects(:post).with("/v1/users", {"email" => "jo@example.com", "user_id" => "i-1224242", "companies" => [{"id" => 6, "name" => "Intercom"}]}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
|
133
|
+
user.save
|
134
|
+
end
|
135
|
+
|
114
136
|
it "deletes a user" do
|
115
137
|
Intercom.expects(:delete).with("/v1/users", {"email" => "jo@example.com", "user_id" => "i-1224242"}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
|
116
138
|
Intercom::User.delete("email" => "jo@example.com", "user_id" => "i-1224242")
|
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: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-02-
|
16
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: minitest
|
@@ -80,7 +80,7 @@ files:
|
|
80
80
|
- .travis.yml
|
81
81
|
- Gemfile
|
82
82
|
- MIT-LICENSE
|
83
|
-
- README.
|
83
|
+
- README.md
|
84
84
|
- Rakefile
|
85
85
|
- changes.txt
|
86
86
|
- intercom.gemspec
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project: intercom
|
130
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.23
|
131
131
|
signing_key:
|
132
132
|
specification_version: 3
|
133
133
|
summary: Ruby bindings for the Intercom API
|