intercom 0.1.9 → 0.1.10
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/changes.txt +3 -0
- data/lib/intercom/hashable_object.rb +6 -4
- data/lib/intercom/tag.rb +4 -2
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/intercom/tag_spec.rb +9 -0
- metadata +1 -1
data/changes.txt
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Intercom
|
2
2
|
module HashableObject
|
3
3
|
def from_hash(hash)
|
4
|
-
hash.each
|
5
|
-
instance_variable_set("@#{key}".to_sym, value)
|
6
|
-
end
|
4
|
+
hash.each {|attribute, value| instance_variable_set("@#{attribute}".to_sym, value) }
|
7
5
|
end
|
8
6
|
|
9
7
|
def to_hash
|
@@ -14,7 +12,11 @@ module Intercom
|
|
14
12
|
end
|
15
13
|
|
16
14
|
def displayable_attributes
|
17
|
-
to_hash.
|
15
|
+
to_hash.select {|attribute, value| self.respond_to?(attribute) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_wire
|
19
|
+
to_hash.select {|attribute, value| self.respond_to?("#{attribute.to_s}=") }
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/intercom/tag.rb
CHANGED
@@ -32,7 +32,9 @@ module Intercom
|
|
32
32
|
extend RequiresParameters
|
33
33
|
include HashableObject
|
34
34
|
|
35
|
-
|
35
|
+
attr_accessor :name, :color
|
36
|
+
attr_reader :segment, :tagged_user_count, :id
|
37
|
+
attr_writer :user_ids, :emails, :tag_or_untag
|
36
38
|
|
37
39
|
def initialize(attributes={})
|
38
40
|
from_hash(attributes)
|
@@ -68,7 +70,7 @@ module Intercom
|
|
68
70
|
##
|
69
71
|
# Saves a Tag on your application
|
70
72
|
def save
|
71
|
-
response = Intercom.post("/v1/tags",
|
73
|
+
response = Intercom.post("/v1/tags", to_wire)
|
72
74
|
self.from_hash(response)
|
73
75
|
displayable_self
|
74
76
|
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -98,6 +98,16 @@ def test_tag
|
|
98
98
|
}
|
99
99
|
end
|
100
100
|
|
101
|
+
def updated_test_tag
|
102
|
+
{
|
103
|
+
"id" => "4f73428b5e4dfc000b000112",
|
104
|
+
"name" => "Test Tag",
|
105
|
+
"color" => "green",
|
106
|
+
"segment" => false,
|
107
|
+
"tagged_user_count" => 2
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
101
111
|
def error_on_modify_frozen
|
102
112
|
RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
|
103
113
|
end
|
@@ -30,4 +30,13 @@ describe "Intercom::Tag" do
|
|
30
30
|
tag.tagged_user_count.must_equal 2
|
31
31
|
end
|
32
32
|
|
33
|
+
it "updates tags" do
|
34
|
+
Intercom.expects(:get).with("/v1/tags", {:name => "Test Tag"}).returns(test_tag)
|
35
|
+
tag = Intercom::Tag.find_by_name "Test Tag"
|
36
|
+
tag.color.must_equal "red"
|
37
|
+
tag.color = "green"
|
38
|
+
Intercom.expects(:post).with("/v1/tags", {:name => "Test Tag", :color => "green"}).returns(updated_test_tag)
|
39
|
+
tag.save
|
40
|
+
end
|
41
|
+
|
33
42
|
end
|