intercom 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/changes.txt +5 -2
- data/lib/intercom.rb +1 -0
- data/lib/intercom/tag.rb +108 -0
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +12 -1
- data/spec/unit/intercom/tag_spec.rb +32 -0
- metadata +6 -9
data/README.md
CHANGED
data/changes.txt
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
0.1.7
|
2
|
+
- add support for creating, updating, and fetching tags
|
3
|
+
|
1
4
|
0.1.6
|
2
|
-
-
|
5
|
+
- add unsubscribed_from_emails and unsubscribed_from_emails= to user
|
3
6
|
|
4
7
|
0.1.5
|
5
|
-
-
|
8
|
+
- always convert times to unix timestamps for the wire (thanks @jgwhite)
|
6
9
|
|
7
10
|
0.1.4
|
8
11
|
- Intercom::User.all now includes Enumerable
|
data/lib/intercom.rb
CHANGED
data/lib/intercom/tag.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'intercom/user_resource'
|
2
|
+
|
3
|
+
module Intercom
|
4
|
+
|
5
|
+
##
|
6
|
+
# Represents a tag
|
7
|
+
#
|
8
|
+
# A tag consists of a name, and (optionally) a color and users that you would like to tag.
|
9
|
+
#
|
10
|
+
# == Examples
|
11
|
+
#
|
12
|
+
# tag = Intercom::Tag.create(:name => "Super Tag", :color => "red", :user_ids => ['abc123', 'def456'])
|
13
|
+
# tag = Intercom::Tag.create(:name => "Super Tag", :color => "red", :emails => ['bob@example.com', 'joe@example.com'])
|
14
|
+
#
|
15
|
+
# You can also create a tag and save it like this:
|
16
|
+
# tag = Intercom::Tag.new
|
17
|
+
# tag.name = "Super Tag"
|
18
|
+
# tag.color = "red"
|
19
|
+
# tag.user_ids = ['abc123', 'def456']
|
20
|
+
# tag.tag_or_untag = "tag"
|
21
|
+
# tag.save
|
22
|
+
#
|
23
|
+
# Or update a tag and save it like this:
|
24
|
+
# tag = Intercom::Tag.find_by_name "Super Tag"
|
25
|
+
# tag.color = "green"
|
26
|
+
# tag.user_ids << 'abc123'
|
27
|
+
# tag.tag_or_untag = "untag"
|
28
|
+
# tag.save
|
29
|
+
|
30
|
+
class Tag < UserResource
|
31
|
+
|
32
|
+
def initialize(attributes={})
|
33
|
+
@attributes = attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Finds a Tag using params
|
38
|
+
def self.find(params)
|
39
|
+
response = Intercom.get("/v1/tags", params)
|
40
|
+
Tag.from_api(response)
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Finds a Tag using a name
|
45
|
+
def self.find_by_name(name)
|
46
|
+
find({:name => name})
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Creates a new Tag using params and saves it
|
51
|
+
# @see #save
|
52
|
+
def self.create(params)
|
53
|
+
requires_parameters(params, %W(name))
|
54
|
+
Tag.new(params).save
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Saves a Tag on your application
|
59
|
+
def save
|
60
|
+
response = Intercom.post("/v1/tags", to_hash)
|
61
|
+
self.update_from_api_response(response)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# The name of the tag
|
66
|
+
def name=(name)
|
67
|
+
@attributes["name"] = name
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# The color of the tag
|
72
|
+
def color=(color)
|
73
|
+
@attributes["color"] = color
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# An array of user_ids of the users you'd like to tag or untag
|
78
|
+
def user_ids
|
79
|
+
@attributes["user_ids"] ||= []
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# An array of user_ids of the users you'd like to tag or untag
|
84
|
+
def emails
|
85
|
+
@attributes["emails"] ||= []
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# An array of user_ids of the users you'd like to tag or untag
|
90
|
+
def user_ids=(user_ids)
|
91
|
+
@attributes["user_ids"] = user_ids
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# An array of emails of the users you'd like to tag or untag
|
96
|
+
def emails=(emails)
|
97
|
+
@attributes["emails"] = emails
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# A string to specify whether to tag or untag the specified users, can be left out if only creating a new tag.
|
102
|
+
def tag_or_untag=(tag_or_untag)
|
103
|
+
return unless ["tag", "untag"].include?(tag_or_untag)
|
104
|
+
@attributes["tag_or_untag"] = tag_or_untag
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'intercom'
|
2
2
|
require 'minitest/autorun'
|
3
|
-
require 'mocha
|
3
|
+
require 'mocha'
|
4
4
|
|
5
5
|
def test_user(email="bob@example.com")
|
6
6
|
{
|
@@ -88,6 +88,17 @@ def page_of_users(page=1, per_page=10)
|
|
88
88
|
}
|
89
89
|
end
|
90
90
|
|
91
|
+
def test_tag
|
92
|
+
{
|
93
|
+
"name" => "Test Tag",
|
94
|
+
"color" => "red",
|
95
|
+
"users" => [
|
96
|
+
{"email" => "bob@example.com", "user_id" => "abc123"},
|
97
|
+
{"email" => "tom@example.com", "user_id" => "def456"}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
91
102
|
def error_on_modify_frozen
|
92
103
|
RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
|
93
104
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Intercom::Tag" do
|
4
|
+
it "gets a tag" do
|
5
|
+
Intercom.expects(:get).with("/v1/tags", {:name => "Test Tag"}).returns(test_tag)
|
6
|
+
tag = Intercom::Tag.find(:name => "Test Tag")
|
7
|
+
tag.name.must_equal "Test Tag"
|
8
|
+
tag.color.must_equal "red"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "gets a tag by name" do
|
12
|
+
Intercom.expects(:get).with("/v1/tags", {:name => "Test Tag"}).returns(test_tag)
|
13
|
+
tag = Intercom::Tag.find_by_name "Test Tag"
|
14
|
+
tag.name.must_equal "Test Tag"
|
15
|
+
tag.color.must_equal "red"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "creates a tag" do
|
19
|
+
Intercom.expects(:post).with("/v1/tags", {:name => "Test Tag"}).returns(test_tag)
|
20
|
+
tag = Intercom::Tag.create(:name => "Test Tag")
|
21
|
+
tag.name.must_equal "Test Tag"
|
22
|
+
tag.color.must_equal "red"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "tags users" do
|
26
|
+
Intercom.expects(:post).with("/v1/tags", {:name => "Test Tag", :color => "red", :user_ids => ["abc123", "def456"], :tag_or_untag => "tag"}).returns(test_tag)
|
27
|
+
tag = Intercom::Tag.create(:name => "Test Tag", :color => "red", :user_ids => ["abc123", "def456"], :tag_or_untag => "tag")
|
28
|
+
tag.name.must_equal "Test Tag"
|
29
|
+
tag.color.must_equal "red"
|
30
|
+
tag.users.must_equal [{"email" => "bob@example.com", "user_id" => "abc123"}, {"email" => "tom@example.com", "user_id" => "def456"}]
|
31
|
+
end
|
32
|
+
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: 0.1.
|
4
|
+
version: 0.1.7
|
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-03
|
16
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: minitest
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/intercom/note.rb
|
93
93
|
- lib/intercom/request.rb
|
94
94
|
- lib/intercom/social_profile.rb
|
95
|
+
- lib/intercom/tag.rb
|
95
96
|
- lib/intercom/unix_timestamp_unwrapper.rb
|
96
97
|
- lib/intercom/user.rb
|
97
98
|
- lib/intercom/user_collection_proxy.rb
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- spec/unit/intercom/impression_spec.rb
|
104
105
|
- spec/unit/intercom/message_thread_spec.rb
|
105
106
|
- spec/unit/intercom/note_spec.rb
|
107
|
+
- spec/unit/intercom/tag_spec.rb
|
106
108
|
- spec/unit/intercom/user_collection_proxy_spec.rb
|
107
109
|
- spec/unit/intercom/user_resource_spec.rb
|
108
110
|
- spec/unit/intercom/user_spec.rb
|
@@ -119,21 +121,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
121
|
- - ! '>='
|
120
122
|
- !ruby/object:Gem::Version
|
121
123
|
version: '0'
|
122
|
-
segments:
|
123
|
-
- 0
|
124
|
-
hash: 2662975996063924397
|
125
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
125
|
none: false
|
127
126
|
requirements:
|
128
127
|
- - ! '>='
|
129
128
|
- !ruby/object:Gem::Version
|
130
129
|
version: '0'
|
131
|
-
segments:
|
132
|
-
- 0
|
133
|
-
hash: 2662975996063924397
|
134
130
|
requirements: []
|
135
131
|
rubyforge_project: intercom
|
136
|
-
rubygems_version: 1.8.
|
132
|
+
rubygems_version: 1.8.23
|
137
133
|
signing_key:
|
138
134
|
specification_version: 3
|
139
135
|
summary: Ruby bindings for the Intercom API
|
@@ -144,6 +140,7 @@ test_files:
|
|
144
140
|
- spec/unit/intercom/impression_spec.rb
|
145
141
|
- spec/unit/intercom/message_thread_spec.rb
|
146
142
|
- spec/unit/intercom/note_spec.rb
|
143
|
+
- spec/unit/intercom/tag_spec.rb
|
147
144
|
- spec/unit/intercom/user_collection_proxy_spec.rb
|
148
145
|
- spec/unit/intercom/user_resource_spec.rb
|
149
146
|
- spec/unit/intercom/user_spec.rb
|