intercom 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39ff3f29f239b7890f520cf8218ba43d271d4923
4
- data.tar.gz: ac6433a1f09441a1c060f066530df24cfa32cb00
3
+ metadata.gz: 2853f9208fb251cd3a7cf50ff37cf6c650e0b689
4
+ data.tar.gz: dbd8ea0ee7fffed060e8c76827dbc7d3fa75bcfc
5
5
  SHA512:
6
- metadata.gz: d9d4ad05c27d11cc40499894bad90bb88450cfe6cfee6ad39ff9a5ac9c025ceab6683b58ffd883085c4302f19c9e6773b226e7ed3027df3f9a4c15527d839402
7
- data.tar.gz: f8c9665740085e86ee5fe6787f754cc2b539e0f7c576df1f55f920c8c3cbfd43bd2721768791c720aaa3795c4c58ef8f35b432edb9eecbdae61319040a201154
6
+ metadata.gz: 90837953885802d3e3fefeb511c3eedbcd96eac382d274e179873a2e66ed2e43d6526befbbd90fd2a2e3fc711fcfe58fa49a0cd5faee9eca104a0c881ed577a7
7
+ data.tar.gz: 8ba9b140e61579bcbe2b9b73752023fe9594d5c0f9399fcaee53e36cb6b267db854f6f7ea656e2ed8b07e620f7e086dee053480108220115cab99a17f08ae68e
@@ -76,19 +76,23 @@ module Intercom
76
76
  # Save a list of User Events, with an optional base_user
77
77
  def self.save_batch_events(events, base_user=nil)
78
78
  hash = { :type => 'event.list', :data => []}
79
- hash[:user] = { :user_id => base_user.user_id } if base_user
79
+ hash[:user] = user_hash(base_user) if base_user
80
80
  events.each do |event|
81
81
  hash[:data] << event.event_hash
82
82
  end
83
83
  post_to_intercom(hash)
84
84
  end
85
+
86
+ def self.user_hash(user)
87
+ user.user_id ? { :user_id => user.user_id } : { :email => user.email }
88
+ end
85
89
 
86
90
  def self.post_to_intercom(hash)
87
91
  Intercom.post('/events', hash)
88
92
  end
89
93
 
90
94
  def user_hash
91
- { :user_id => user.user_id }
95
+ UserEvent.user_hash(user)
92
96
  end
93
97
 
94
98
  def event_hash
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -9,10 +9,10 @@ describe "Intercom::UserEvent" do
9
9
  Intercom.expects(:post).with("/events",
10
10
  { :type => 'event.list',
11
11
  :data => [ {:event_name => "signup", :created => created_time.to_i, :type => 'event',
12
- :user => { :user_id => user.user_id}, :metadata => {:some => "data"}
12
+ :user => { :user_id => user.user_id},
13
13
  }]}).returns(:status => 200)
14
14
 
15
- Intercom::UserEvent.create({ :event_name => "signup", :user => user, :created_at => created_time, :metadata => {:some => "data"} })
15
+ Intercom::UserEvent.create({ :event_name => "signup", :user => user, :created_at => created_time })
16
16
  end
17
17
 
18
18
  it 'automatically adds a created time upon creation' do
@@ -39,6 +39,17 @@ describe "Intercom::UserEvent" do
39
39
  proc { user_event.save }.must_raise ArgumentError, "Missing User"
40
40
  end
41
41
 
42
+ it 'uses the user.email if no user.id found' do
43
+ user2 = Intercom::User.new("email" => "jim@example.com", :created_at => Time.now, :name => "Jim Bob")
44
+ Intercom.expects(:post).with("/events",
45
+ { :type => 'event.list',
46
+ :data => [ {:event_name => "signup", :created => created_time.to_i, :type => 'event',
47
+ :user => { :email => user2.email}
48
+ }]}).returns(:status => 200)
49
+
50
+ Intercom::UserEvent.create({ :event_name => "signup", :user => user2, :created_at => created_time })
51
+ end
52
+
42
53
  describe 'while batching events' do
43
54
 
44
55
  let (:event1) do
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond