intercom 0.0.12 → 0.1.1

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/intercom.gemspec CHANGED
@@ -6,8 +6,8 @@ require "intercom/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "intercom"
8
8
  spec.version = Intercom::VERSION
9
- spec.authors = ["Ben McRedmond", "Ciaran Lee", "Darragh Curran", "Jeff Gardner"]
10
- spec.email = ["ben@intercom.io", "ciaran@intercom.io", "darragh@intercom.io", "jeff@intercom.io"]
9
+ spec.authors = ["Ben McRedmond", "Ciaran Lee", "Darragh Curran", "Jeff Gardner", "Kyle Daigle"]
10
+ spec.email = ["ben@intercom.io", "ciaran@intercom.io", "darragh@intercom.io", "jeff@intercom.io", "kyle@digitalworkbox.com"]
11
11
  spec.homepage = "https://www.intercom.io"
12
12
  spec.summary = %q{Ruby bindings for the Intercom API}
13
13
  spec.description = %Q{Intercom (https://www.intercom.io) is a customer relationship management and messaging tool for web app owners. This library wraps the api provided by Intercom. See http://docs.intercom.io/api for more details. }
@@ -1,7 +1,7 @@
1
1
  module Intercom
2
2
  # Sub-class of {Hash} for storing custom data attributes.
3
3
  # Doesn't allow nested Hashes or Arrays. And requires {String} or {Symbol} keys.
4
- class UserCustomData < Hash
4
+ class FlatStore < Hash
5
5
  def initialize(attributes={})
6
6
  (attributes).each do |key, value|
7
7
  validate_key_and_value(key, value)
@@ -20,8 +20,8 @@ module Intercom
20
20
 
21
21
  private
22
22
  def validate_key_and_value(key, value)
23
- raise ArgumentError.new("custom_data does not support nested data structures (key: #{key}, value: #{value}") if value.is_a?(Array) || value.is_a?(Hash)
24
- raise ArgumentError.new("custom_data key must be String or Symbol: #{key}") unless key.is_a?(String) || key.is_a?(Symbol)
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
25
  end
26
26
  end
27
27
  end
data/lib/intercom/user.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'intercom/user_resource'
2
- require 'intercom/user_custom_data'
2
+ require 'intercom/flat_store'
3
3
  require 'intercom/user_collection_proxy'
4
4
  require 'intercom/social_profile'
5
5
 
@@ -222,17 +222,40 @@ module Intercom
222
222
  # user.custom_data[:plan] = "pro"
223
223
  # user.save
224
224
  #
225
- # @return [UserCustomData]
225
+ # @return [FlatStore]
226
226
  def custom_data
227
- @attributes["custom_data"] ||= UserCustomData.new
227
+ @attributes["custom_data"] ||= FlatStore.new
228
228
  end
229
229
 
230
230
  # Set a {Hash} of custom data attributes to save/update on this user
231
231
  #
232
232
  # @param [Hash] custom_data
233
- # @return [UserCustomData]
233
+ # @return [FlatStore]
234
234
  def custom_data=(custom_data)
235
- @attributes["custom_data"] = UserCustomData.new(custom_data)
235
+ @attributes["custom_data"] = FlatStore.new(custom_data)
236
+ end
237
+
238
+ # Custom attributes stored for this Intercom::User
239
+ #
240
+ # See http://docs.intercom.io/#Companies for more information
241
+ #
242
+ # Example: Setting a company for an existing user
243
+ # user = Intercom::User.find(:email => "someone@example.com")
244
+ # user.company[:id] = 6
245
+ # user.company[:name] = "Intercom"
246
+ # user.save
247
+ #
248
+ # @return [FlatStore]
249
+ def company
250
+ @attributes["company"] ||= FlatStore.new
251
+ end
252
+
253
+ # Set a {Hash} of company attributes to save/update on this user
254
+ #
255
+ # @param [Hash] company
256
+ # @return [FlatStore]
257
+ def company=(company)
258
+ @attributes["company"] = FlatStore.new(company)
236
259
  end
237
260
 
238
261
  protected
@@ -1,5 +1,5 @@
1
1
  require 'intercom/user_resource'
2
- require 'intercom/user_custom_data'
2
+ require 'intercom/flat_store'
3
3
  require 'intercom/social_profile'
4
4
 
5
5
  module Intercom
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "0.0.12"
2
+ VERSION = "0.1.1"
3
3
  end
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/setup'
4
4
 
5
5
  def test_user(email="bob@example.com")
6
6
  {
@@ -1,26 +1,26 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Intercom::UserCustomData do
3
+ describe Intercom::FlatStore do
4
4
  it "raises if you try to set or merge in nested hash structures" do
5
- data = Intercom::UserCustomData.new()
5
+ data = Intercom::FlatStore.new()
6
6
  proc { data["thing"] = [1] }.must_raise ArgumentError
7
7
  proc { data["thing"] = {1 => 2} }.must_raise ArgumentError
8
- proc { Intercom::UserCustomData.new({1 => {2 => 3}}) }.must_raise ArgumentError
8
+ proc { Intercom::FlatStore.new({1 => {2 => 3}}) }.must_raise ArgumentError
9
9
  end
10
10
 
11
11
  it "raises if you try to use a non string key" do
12
- data = Intercom::UserCustomData.new()
12
+ data =Intercom::FlatStore.new()
13
13
  proc { data[1] = "something" }.must_raise ArgumentError
14
14
  end
15
15
 
16
16
  it "sets and merges valid entries" do
17
- data = Intercom::UserCustomData.new()
17
+ data = Intercom::FlatStore.new()
18
18
  data["a"] = 1
19
19
  data[:b] = 2
20
20
  data[:a].must_equal 1
21
21
  data["b"].must_equal 2
22
22
  data[:b].must_equal 2
23
- data = Intercom::UserCustomData.new({"a" => 1, :b => 2})
23
+ data = Intercom::FlatStore.new({"a" => 1, :b => 2})
24
24
  data["a"].must_equal 1
25
25
  data[:a].must_equal 1
26
26
  data["b"].must_equal 2
@@ -73,6 +73,14 @@ describe "Intercom::User" do
73
73
  user.to_hash["custom_data"].must_equal "mad" => 123, "other" => now, "thing" => "yay"
74
74
  end
75
75
 
76
+ it "allows easy setting of company data" do
77
+ now = Time.now
78
+ user = Intercom::User.new()
79
+ user.company["name"] = "Intercom"
80
+ user.company["id"] = 6
81
+ user.to_hash["company"].must_equal "name" => "Intercom", "id" => 6
82
+ end
83
+
76
84
  it "rejects nested data structures in custom_data" do
77
85
  user = Intercom::User.new()
78
86
  proc { user.custom_data["thing"] = [1] }.must_raise ArgumentError
@@ -97,6 +105,12 @@ describe "Intercom::User" do
97
105
  user.save
98
106
  end
99
107
 
108
+ it "saves a user with a company" do
109
+ user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :company => {:id => 6, :name => "Intercom"})
110
+ Intercom.expects(:post).with("/v1/users", {"email" => "jo@example.com", "user_id" => "i-1224242", "company" => {"id" => 6, "name" => "Intercom"}}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
111
+ user.save
112
+ end
113
+
100
114
  it "deletes a user" do
101
115
  Intercom.expects(:delete).with("/v1/users", {"email" => "jo@example.com", "user_id" => "i-1224242"}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
102
116
  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.0.12
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,11 @@ authors:
9
9
  - Ciaran Lee
10
10
  - Darragh Curran
11
11
  - Jeff Gardner
12
+ - Kyle Daigle
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2013-02-07 00:00:00.000000000 Z
16
+ date: 2013-02-22 00:00:00.000000000 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
19
  name: minitest
@@ -70,6 +71,7 @@ email:
70
71
  - ciaran@intercom.io
71
72
  - darragh@intercom.io
72
73
  - jeff@intercom.io
74
+ - kyle@digitalworkbox.com
73
75
  executables: []
74
76
  extensions: []
75
77
  extra_rdoc_files: []
@@ -84,6 +86,7 @@ files:
84
86
  - intercom.gemspec
85
87
  - lib/data/cacert.pem
86
88
  - lib/intercom.rb
89
+ - lib/intercom/flat_store.rb
87
90
  - lib/intercom/impression.rb
88
91
  - lib/intercom/message_thread.rb
89
92
  - lib/intercom/note.rb
@@ -92,16 +95,15 @@ files:
92
95
  - lib/intercom/unix_timestamp_unwrapper.rb
93
96
  - lib/intercom/user.rb
94
97
  - lib/intercom/user_collection_proxy.rb
95
- - lib/intercom/user_custom_data.rb
96
98
  - lib/intercom/user_resource.rb
97
99
  - lib/intercom/version.rb
98
100
  - spec/integration/intercom_api_integration_spec.rb
99
101
  - spec/spec_helper.rb
102
+ - spec/unit/intercom/flat_store_spec.rb
100
103
  - spec/unit/intercom/impression_spec.rb
101
104
  - spec/unit/intercom/message_thread_spec.rb
102
105
  - spec/unit/intercom/note_spec.rb
103
106
  - spec/unit/intercom/user_collection_proxy_spec.rb
104
- - spec/unit/intercom/user_custom_data_spec.rb
105
107
  - spec/unit/intercom/user_resource_spec.rb
106
108
  - spec/unit/intercom/user_spec.rb
107
109
  - spec/unit/intercom_spec.rb
@@ -125,18 +127,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
127
  version: '0'
126
128
  requirements: []
127
129
  rubyforge_project: intercom
128
- rubygems_version: 1.8.23
130
+ rubygems_version: 1.8.25
129
131
  signing_key:
130
132
  specification_version: 3
131
133
  summary: Ruby bindings for the Intercom API
132
134
  test_files:
133
135
  - spec/integration/intercom_api_integration_spec.rb
134
136
  - spec/spec_helper.rb
137
+ - spec/unit/intercom/flat_store_spec.rb
135
138
  - spec/unit/intercom/impression_spec.rb
136
139
  - spec/unit/intercom/message_thread_spec.rb
137
140
  - spec/unit/intercom/note_spec.rb
138
141
  - spec/unit/intercom/user_collection_proxy_spec.rb
139
- - spec/unit/intercom/user_custom_data_spec.rb
140
142
  - spec/unit/intercom/user_resource_spec.rb
141
143
  - spec/unit/intercom/user_spec.rb
142
144
  - spec/unit/intercom_spec.rb
145
+ has_rdoc: