amplitude-api 0.0.8 → 0.0.9

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: 67727755b54bfef1fc3ffa5889e11c7931420a13
4
- data.tar.gz: 52feec8f51522d7f2c17b0db39d4e033f76efe2b
3
+ metadata.gz: 2613d299e9d407475b3a03eecb1633f0a5359b40
4
+ data.tar.gz: 7a48cebc3d4c592cb894c5d2bf9b814f0ff55a70
5
5
  SHA512:
6
- metadata.gz: f3b3bf19725cda0082c7cf0acb7ca40614430a63ff5d929e803c3074955d9b35e5674987745a5fb17d2cc0e030fb7319a5903e012d40c98f5e171efea8f3b0f6
7
- data.tar.gz: 09b6ca4ddb4ec2bdbed9980a41356b6f0096feace6819209c98ce37eb2a83722f509ca60762ccd7731a10308693bdce1eddf88f9e5cb27338fdf92be84dffd74
6
+ metadata.gz: 14739845274080c65ef0afb13b9547a91191ded8a935fae3a99bd04ffac16eb6f632fe4f83d4e209d3ef55f0dd3cd4eedfe645f030836423f42c530ac401363c
7
+ data.tar.gz: 1e6933e33ec4ae42076b57e8f9c6cc72797fb6cb25ce708f76182224f5fb02f4b4657fc00811e81211dcb23de1989879dda88ec4c5ec21ce98b96de9f1300fe3
@@ -22,15 +22,17 @@ class AmplitudeAPI
22
22
  #
23
23
  # @param [ String ] event_name a string that describes the event, e.g. "clicked on Home"
24
24
  # @param [ String ] user a string or integer that uniquely identifies a user.
25
+ # @param [ String ] device a string that uniquely identifies the device.
25
26
  # @param [ Hash ] event_properties a hash that is serialized to JSON,
26
27
  # and can contain any other property to be stored on the Event
27
28
  # @param [ Hash ] user_properties a hash that is serialized to JSON,
28
29
  # and contains user properties to be associated with the user
29
30
  #
30
31
  # @return [ Typhoeus::Response ]
31
- def send_event(event_name, user, options = {})
32
+ def send_event(event_name, user, device, options = {})
32
33
  event = AmplitudeAPI::Event.new(
33
34
  user_id: user,
35
+ device_id: device,
34
36
  event_type: event_name,
35
37
  event_properties: options.fetch(:event_properties, {}),
36
38
  user_properties: options.fetch(:user_properties, {})
@@ -72,8 +74,12 @@ class AmplitudeAPI
72
74
 
73
75
  # ==== Identification related methods
74
76
 
75
- def send_identify(user_id, user_properties = {})
76
- identification = AmplitudeAPI::Identification.new(user_id: user_id, user_properties: user_properties)
77
+ def send_identify(user_id, device_id, user_properties = {})
78
+ identification = AmplitudeAPI::Identification.new(
79
+ user_id: user_id,
80
+ device_id: device_id,
81
+ user_properties: user_properties
82
+ )
77
83
  identify(identification)
78
84
  end
79
85
 
@@ -4,6 +4,9 @@ class AmplitudeAPI
4
4
  # @!attribute [ rw ] user_id
5
5
  # @return [ String ] the user_id to be sent to Amplitude
6
6
  attr_accessor :user_id
7
+ # @!attribute [ rw ] device_id
8
+ # @return [ String ] the device_id to be sent to Amplitude
9
+ attr_accessor :device_id
7
10
  # @!attribute [ rw ] event_type
8
11
  # @return [ String ] the event_type to be sent to Amplitude
9
12
  attr_accessor :event_type
@@ -43,6 +46,7 @@ class AmplitudeAPI
43
46
  # Create a new Event
44
47
  #
45
48
  # @param [ String ] user_id a user_id to associate with the event
49
+ # @param [ String ] device_id a device_id to associate with the event
46
50
  # @param [ String ] event_type a name for the event
47
51
  # @param [ Hash ] event_properties various properties to attach to the event
48
52
  # @param [ Time ] Time that the event occurred (defaults to now)
@@ -52,15 +56,16 @@ class AmplitudeAPI
52
56
  # @param [ String ] revenue_type (optional) type of revenue
53
57
  # @param [ String ] IP address of the user
54
58
  # @param [ String ] insert_id a unique identifier for the event
55
- def initialize(options = {})
56
- self.user_id = options.fetch(:user_id, '')
57
- self.event_type = options.fetch(:event_type, '')
58
- self.event_properties = options.fetch(:event_properties, {})
59
- self.user_properties = options.fetch(:user_properties, {})
60
- self.time = options[:time]
61
- self.ip = options.fetch(:ip, '')
62
- self.insert_id = options[:insert_id]
63
- validate_revenue_arguments(options)
59
+ def initialize(attributes = {})
60
+ self.user_id = getopt(attributes, :user_id, '')
61
+ self.device_id = getopt(attributes, :device_id, nil)
62
+ self.event_type = getopt(attributes, :event_type, '')
63
+ self.event_properties = getopt(attributes, :event_properties, {})
64
+ self.user_properties = getopt(attributes, :user_properties, {})
65
+ self.time = getopt(attributes, :time)
66
+ self.ip = getopt(attributes, :ip, '')
67
+ self.insert_id = getopt(attributes, :insert_id)
68
+ validate_revenue_arguments(attributes)
64
69
  end
65
70
 
66
71
  def user_id=(value)
@@ -81,11 +86,17 @@ class AmplitudeAPI
81
86
  serialized_event[:user_id] = user_id
82
87
  serialized_event[:event_properties] = event_properties
83
88
  serialized_event[:user_properties] = user_properties
89
+ serialized_event = add_optional_properties(serialized_event)
90
+ serialized_event.merge(revenue_hash)
91
+ end
92
+
93
+ # @return [ Hash ] A serialized Event with optional properties
94
+ def add_optional_properties(serialized_event)
95
+ serialized_event[:device_id] = device_id if device_id
84
96
  serialized_event[:time] = formatted_time if time
85
97
  serialized_event[:ip] = ip if ip
86
98
  serialized_event[:insert_id] = insert_id if insert_id
87
-
88
- serialized_event.merge(revenue_hash)
99
+ serialized_event
89
100
  end
90
101
 
91
102
  # @return [ true, false ]
@@ -106,10 +117,10 @@ class AmplitudeAPI
106
117
  end
107
118
 
108
119
  def validate_revenue_arguments(options)
109
- self.price = options[:price]
110
- self.quantity = options[:quantity] || 1 if price
111
- self.product_id = options[:product_id]
112
- self.revenue_type = options[:revenue_type]
120
+ self.price = getopt(options, :price)
121
+ self.quantity = getopt(options, :quantity, 1) if price
122
+ self.product_id = getopt(options, :product_id)
123
+ self.revenue_type = getopt(options, :revenue_type)
113
124
  return if price
114
125
  raise ArgumentError, 'You must provide a price in order to use the product_id' if product_id
115
126
  raise ArgumentError, 'You must provide a price in order to use the revenue_type' if revenue_type
@@ -123,5 +134,9 @@ class AmplitudeAPI
123
134
  revenue_hash[:price] = price if price
124
135
  revenue_hash
125
136
  end
137
+
138
+ def getopt(options, key, default = nil)
139
+ options.fetch(key.to_sym, options.fetch(key.to_s, default))
140
+ end
126
141
  end
127
142
  end
@@ -4,6 +4,9 @@ class AmplitudeAPI
4
4
  # @!attribute [ rw ] user_id
5
5
  # @return [ String ] the user_id to be sent to Amplitude
6
6
  attr_accessor :user_id
7
+ # @!attribute [ rw ] device_id
8
+ # @return [ String ] the device_id to be sent to Amplitude
9
+ attr_accessor :device_id
7
10
  # @!attribute [ rw ] user_properties
8
11
  # @return [ String ] the user_properties to be attached to the Amplitude Identify
9
12
  attr_accessor :user_properties
@@ -11,9 +14,11 @@ class AmplitudeAPI
11
14
  # Create a new Identification
12
15
  #
13
16
  # @param [ String ] user_id a user_id to associate with the identification
17
+ # @param [ String ] device_id a device_id to associate with the identification
14
18
  # @param [ Hash ] user_properties various properties to attach to the user identification
15
- def initialize(user_id: '', user_properties: {})
19
+ def initialize(user_id: '', device_id: nil, user_properties: {})
16
20
  self.user_id = user_id
21
+ self.device_id = device_id if device_id
17
22
  self.user_properties = user_properties
18
23
  end
19
24
 
@@ -33,7 +38,7 @@ class AmplitudeAPI
33
38
  {
34
39
  user_id: user_id,
35
40
  user_properties: user_properties
36
- }
41
+ }.tap { |hsh| hsh[:device_id] = device_id if device_id }
37
42
  end
38
43
 
39
44
  # @return [ true, false ]
@@ -1,3 +1,3 @@
1
1
  class AmplitudeAPI
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
data/readme.md CHANGED
@@ -35,7 +35,6 @@ Currently, we are using this in Rails and using ActiveJob to dispatch events asy
35
35
  ## What's Next
36
36
 
37
37
  * Thread support for background dispatching in bulk
38
- * `device_id` support as an alternative to `user_id`
39
38
  * Configurable default account to use when no `user_id` present
40
39
 
41
40
  ## Other useful resources
@@ -40,6 +40,54 @@ describe AmplitudeAPI::Event do
40
40
  end
41
41
 
42
42
  describe 'init' do
43
+ context 'attributes' do
44
+ it 'accepts string attributes' do
45
+ time = Time.parse('2016-01-01 00:00:00 -0000')
46
+ event = described_class.new(
47
+ 'user_id' => 123,
48
+ 'device_id' => 'abcd',
49
+ 'event_type' => 'sausage',
50
+ 'event_properties' => { 'a' => 'b' },
51
+ 'user_properties' => { 'c' => 'd' },
52
+ 'time' => time,
53
+ 'ip' => '127.0.0.1',
54
+ 'insert_id' => 'bestId'
55
+ )
56
+
57
+ expect(event.to_hash).to eq(event_type: 'sausage',
58
+ user_id: 123,
59
+ device_id: 'abcd',
60
+ event_properties: { 'a' => 'b' },
61
+ user_properties: { 'c' => 'd' },
62
+ time: 1_451_606_400_000,
63
+ ip: '127.0.0.1',
64
+ insert_id: 'bestId')
65
+ end
66
+
67
+ it 'accepts symbol attributes' do
68
+ time = Time.parse('2016-01-01 00:00:00 -0000')
69
+ event = described_class.new(
70
+ user_id: 123,
71
+ device_id: 'abcd',
72
+ event_type: 'sausage',
73
+ event_properties: { 'a' => 'b' },
74
+ user_properties: { 'c' => 'd' },
75
+ time: time,
76
+ ip: '127.0.0.1',
77
+ insert_id: 'bestId'
78
+ )
79
+
80
+ expect(event.to_hash).to eq(event_type: 'sausage',
81
+ user_id: 123,
82
+ device_id: 'abcd',
83
+ event_properties: { 'a' => 'b' },
84
+ user_properties: { 'c' => 'd' },
85
+ time: 1_451_606_400_000,
86
+ ip: '127.0.0.1',
87
+ insert_id: 'bestId')
88
+ end
89
+ end
90
+
43
91
  context 'the user does not send in a price' do
44
92
  it 'raises an error if the user sends in a product_id' do
45
93
  expect do
@@ -63,7 +111,7 @@ describe AmplitudeAPI::Event do
63
111
  end
64
112
  end
65
113
 
66
- describe '#body' do
114
+ describe '#to_hash' do
67
115
  it 'includes the event type' do
68
116
  event = described_class.new(
69
117
  user_id: 123,
@@ -36,6 +36,11 @@ describe AmplitudeAPI::Identification do
36
36
  expect(identification.to_hash[:user_id]).to eq(123)
37
37
  end
38
38
 
39
+ it 'includes the device id' do
40
+ identification = described_class.new(user_id: 123, device_id: 'abc')
41
+ expect(identification.to_hash[:device_id]).to eq('abc')
42
+ end
43
+
39
44
  it 'includes arbitrary user properties' do
40
45
  identification = described_class.new(
41
46
  user_id: 123,
@@ -2,22 +2,58 @@ require 'spec_helper'
2
2
 
3
3
  describe AmplitudeAPI do
4
4
  let(:user) { Struct.new(:id).new(123) }
5
+ let(:device_id) { 'abcdef' }
5
6
 
6
7
  describe '.track' do
7
8
  context 'with a single event' do
8
- it 'sends the event to Amplitude' do
9
- event = AmplitudeAPI::Event.new(
10
- user_id: 123,
11
- event_type: 'clicked on sign up'
12
- )
13
- body = {
14
- api_key: described_class.api_key,
15
- event: JSON.generate([event.to_hash])
16
- }
9
+ context 'with only user_id' do
10
+ it 'sends the event to Amplitude' do
11
+ event = AmplitudeAPI::Event.new(
12
+ user_id: 123,
13
+ event_type: 'clicked on sign up'
14
+ )
15
+ body = {
16
+ api_key: described_class.api_key,
17
+ event: JSON.generate([event.to_hash])
18
+ }
17
19
 
18
- expect(Typhoeus).to receive(:post).with(AmplitudeAPI::TRACK_URI_STRING, body: body)
20
+ expect(Typhoeus).to receive(:post).with(AmplitudeAPI::TRACK_URI_STRING, body: body)
21
+
22
+ described_class.track(event)
23
+ end
24
+ end
25
+ context 'with only device_id' do
26
+ it 'sends the event to Amplitude' do
27
+ event = AmplitudeAPI::Event.new(
28
+ device_id: device_id,
29
+ event_type: 'clicked on sign up'
30
+ )
31
+ body = {
32
+ api_key: described_class.api_key,
33
+ event: JSON.generate([event.to_hash])
34
+ }
35
+
36
+ expect(Typhoeus).to receive(:post).with(AmplitudeAPI::TRACK_URI_STRING, body: body)
19
37
 
20
- described_class.track(event)
38
+ described_class.track(event)
39
+ end
40
+ end
41
+ context 'with both user_id and device_id' do
42
+ it 'sends the event to Amplitude' do
43
+ event = AmplitudeAPI::Event.new(
44
+ user_id: 123,
45
+ device_id: device_id,
46
+ event_type: 'clicked on sign up'
47
+ )
48
+ body = {
49
+ api_key: described_class.api_key,
50
+ event: JSON.generate([event.to_hash])
51
+ }
52
+
53
+ expect(Typhoeus).to receive(:post).with(AmplitudeAPI::TRACK_URI_STRING, body: body)
54
+
55
+ described_class.track(event)
56
+ end
21
57
  end
22
58
  end
23
59
 
@@ -45,22 +81,63 @@ describe AmplitudeAPI do
45
81
 
46
82
  describe '.identify' do
47
83
  context 'with a single identification' do
48
- it 'sends the identification to Amplitude' do
49
- identification = AmplitudeAPI::Identification.new(
50
- user_id: 123,
51
- user_properties: {
52
- first_name: 'John',
53
- last_name: 'Doe'
84
+ context 'with only user_id' do
85
+ it 'sends the identification to Amplitude' do
86
+ identification = AmplitudeAPI::Identification.new(
87
+ user_id: 123,
88
+ user_properties: {
89
+ first_name: 'John',
90
+ last_name: 'Doe'
91
+ }
92
+ )
93
+ body = {
94
+ api_key: described_class.api_key,
95
+ identification: JSON.generate([identification.to_hash])
54
96
  }
55
- )
56
- body = {
57
- api_key: described_class.api_key,
58
- identification: JSON.generate([identification.to_hash])
59
- }
60
97
 
61
- expect(Typhoeus).to receive(:post).with(AmplitudeAPI::IDENTIFY_URI_STRING, body: body)
98
+ expect(Typhoeus).to receive(:post).with(AmplitudeAPI::IDENTIFY_URI_STRING, body: body)
99
+
100
+ described_class.identify(identification)
101
+ end
102
+ end
103
+ context 'with only device_id' do
104
+ it 'sends the identification to Amplitude' do
105
+ identification = AmplitudeAPI::Identification.new(
106
+ device_id: device_id,
107
+ user_properties: {
108
+ first_name: 'John',
109
+ last_name: 'Doe'
110
+ }
111
+ )
112
+ body = {
113
+ api_key: described_class.api_key,
114
+ identification: JSON.generate([identification.to_hash])
115
+ }
116
+
117
+ expect(Typhoeus).to receive(:post).with(AmplitudeAPI::IDENTIFY_URI_STRING, body: body)
118
+
119
+ described_class.identify(identification)
120
+ end
121
+ end
122
+ context 'with both user_id and device_id' do
123
+ it 'sends the identification to Amplitude' do
124
+ identification = AmplitudeAPI::Identification.new(
125
+ user_id: 123,
126
+ device_id: device_id,
127
+ user_properties: {
128
+ first_name: 'John',
129
+ last_name: 'Doe'
130
+ }
131
+ )
132
+ body = {
133
+ api_key: described_class.api_key,
134
+ identification: JSON.generate([identification.to_hash])
135
+ }
136
+
137
+ expect(Typhoeus).to receive(:post).with(AmplitudeAPI::IDENTIFY_URI_STRING, body: body)
62
138
 
63
- described_class.identify(identification)
139
+ described_class.identify(identification)
140
+ end
64
141
  end
65
142
  end
66
143
 
@@ -74,7 +151,7 @@ describe AmplitudeAPI do
74
151
  }
75
152
  )
76
153
  identification2 = AmplitudeAPI::Identification.new(
77
- user_id: 456,
154
+ device_id: 456,
78
155
  user_properties: {
79
156
  first_name: 'John',
80
157
  last_name: 'Doe'
@@ -121,82 +198,120 @@ describe AmplitudeAPI do
121
198
  ip: '8.8.8.8'
122
199
  )
123
200
  end
124
- end
125
-
126
- describe '.send_event' do
127
- it 'sends an event to AmplitudeAPI' do
201
+ it 'initializes event with parameter including device_id' do
128
202
  event = AmplitudeAPI::Event.new(
129
- user_id: user,
203
+ user_id: 123,
204
+ device_id: 'abc',
130
205
  event_type: 'test_event',
131
- event_properties: { test_property: 1 }
206
+ event_properties: {
207
+ test_property: 1
208
+ },
209
+ ip: '8.8.8.8'
210
+ )
211
+ expect(event.to_hash).to eq(
212
+ event_type: 'test_event',
213
+ user_id: 123,
214
+ device_id: 'abc',
215
+ event_properties: { test_property: 1 },
216
+ user_properties: {},
217
+ ip: '8.8.8.8'
132
218
  )
133
- expect(described_class).to receive(:track).with(event)
134
-
135
- described_class.send_event('test_event', user, event_properties: { test_property: 1 })
136
219
  end
220
+ end
137
221
 
138
- context 'the user is nil' do
139
- it 'sends an event with the no account user' do
222
+ describe '.send_event' do
223
+ context 'with only user_id' do
224
+ it 'sends an event to AmplitudeAPI' do
140
225
  event = AmplitudeAPI::Event.new(
141
- user_id: nil,
226
+ user_id: user,
142
227
  event_type: 'test_event',
143
228
  event_properties: { test_property: 1 }
144
229
  )
145
230
  expect(described_class).to receive(:track).with(event)
146
231
 
147
- described_class.send_event('test_event', nil, event_properties: { test_property: 1 })
232
+ described_class.send_event('test_event', user, nil, event_properties: { test_property: 1 })
148
233
  end
149
- end
150
234
 
151
- context 'the user is a user_id' do
152
- it 'sends an event to AmplitudeAPI' do
153
- event = AmplitudeAPI::Event.new(
154
- user_id: 123,
155
- event_type: 'test_event',
156
- event_properties: { test_property: 1 }
157
- )
158
- expect(described_class).to receive(:track).with(event)
235
+ context 'the user is nil' do
236
+ it 'sends an event with the no account user' do
237
+ event = AmplitudeAPI::Event.new(
238
+ user_id: nil,
239
+ event_type: 'test_event',
240
+ event_properties: { test_property: 1 }
241
+ )
242
+ expect(described_class).to receive(:track).with(event)
159
243
 
160
- described_class.send_event('test_event', user.id, event_properties: { test_property: 1 })
244
+ described_class.send_event('test_event', nil, nil, event_properties: { test_property: 1 })
245
+ end
161
246
  end
162
247
 
163
- it 'sends arbitrary user_properties to AmplitudeAPI' do
164
- event = AmplitudeAPI::Event.new(
165
- user_id: 123,
166
- event_type: 'test_event',
167
- event_properties: { test_property: 1 },
168
- user_properties: { test_user_property: 'abc' }
169
- )
170
- expect(described_class).to receive(:track).with(event)
248
+ context 'the user is a user_id' do
249
+ it 'sends an event to AmplitudeAPI' do
250
+ event = AmplitudeAPI::Event.new(
251
+ user_id: 123,
252
+ event_type: 'test_event',
253
+ event_properties: { test_property: 1 }
254
+ )
255
+ expect(described_class).to receive(:track).with(event)
171
256
 
172
- described_class.send_event(
173
- 'test_event',
174
- user.id,
175
- event_properties: { test_property: 1 },
176
- user_properties: { test_user_property: 'abc' }
177
- )
257
+ described_class.send_event('test_event', user.id, nil, event_properties: { test_property: 1 })
258
+ end
259
+
260
+ it 'sends arbitrary user_properties to AmplitudeAPI' do
261
+ event = AmplitudeAPI::Event.new(
262
+ user_id: 123,
263
+ event_type: 'test_event',
264
+ event_properties: { test_property: 1 },
265
+ user_properties: { test_user_property: 'abc' }
266
+ )
267
+ expect(described_class).to receive(:track).with(event)
268
+
269
+ described_class.send_event(
270
+ 'test_event',
271
+ user.id,
272
+ nil,
273
+ event_properties: { test_property: 1 },
274
+ user_properties: { test_user_property: 'abc' }
275
+ )
276
+ end
178
277
  end
179
278
  end
180
- end
279
+ context 'with device_id' do
280
+ context 'the user is not nil' do
281
+ it 'sends an event to AmplitudeAPI' do
282
+ event = AmplitudeAPI::Event.new(
283
+ user_id: user,
284
+ device_id: device_id,
285
+ event_type: 'test_event',
286
+ event_properties: { test_property: 1 }
287
+ )
288
+ expect(described_class).to receive(:track).with(event)
181
289
 
182
- describe '.send_identify' do
183
- it 'sends an identify to AmplitudeAPI' do
184
- identification = AmplitudeAPI::Identification.new(
185
- user_id: user,
186
- user_properties: {
187
- first_name: 'John',
188
- last_name: 'Doe'
189
- }
190
- )
191
- expect(described_class).to receive(:identify).with(identification)
290
+ described_class.send_event('test_event', user, device_id, event_properties: { test_property: 1 })
291
+ end
292
+ end
293
+
294
+ context 'the user is nil' do
295
+ it 'sends an event with the no account user' do
296
+ event = AmplitudeAPI::Event.new(
297
+ user_id: nil,
298
+ device_id: device_id,
299
+ event_type: 'test_event',
300
+ event_properties: { test_property: 1 }
301
+ )
302
+ expect(described_class).to receive(:track).with(event)
192
303
 
193
- described_class.send_identify(user, first_name: 'John', last_name: 'Doe')
304
+ described_class.send_event('test_event', nil, device_id, event_properties: { test_property: 1 })
305
+ end
306
+ end
194
307
  end
308
+ end
195
309
 
196
- context 'the user is nil' do
197
- it 'sends an identify with the no account user' do
310
+ describe '.send_identify' do
311
+ context 'with no device_id' do
312
+ it 'sends an identify to AmplitudeAPI' do
198
313
  identification = AmplitudeAPI::Identification.new(
199
- user_id: nil,
314
+ user_id: user,
200
315
  user_properties: {
201
316
  first_name: 'John',
202
317
  last_name: 'Doe'
@@ -204,14 +319,44 @@ describe AmplitudeAPI do
204
319
  )
205
320
  expect(described_class).to receive(:identify).with(identification)
206
321
 
207
- described_class.send_identify(nil, first_name: 'John', last_name: 'Doe')
322
+ described_class.send_identify(user, nil, first_name: 'John', last_name: 'Doe')
323
+ end
324
+
325
+ context 'the user is nil' do
326
+ it 'sends an identify with the no account user' do
327
+ identification = AmplitudeAPI::Identification.new(
328
+ user_id: nil,
329
+ user_properties: {
330
+ first_name: 'John',
331
+ last_name: 'Doe'
332
+ }
333
+ )
334
+ expect(described_class).to receive(:identify).with(identification)
335
+
336
+ described_class.send_identify(nil, nil, first_name: 'John', last_name: 'Doe')
337
+ end
208
338
  end
209
- end
210
339
 
211
- context 'the user is a user_id' do
340
+ context 'the user is a user_id' do
341
+ it 'sends an identify to AmplitudeAPI' do
342
+ identification = AmplitudeAPI::Identification.new(
343
+ user_id: 123,
344
+ user_properties: {
345
+ first_name: 'John',
346
+ last_name: 'Doe'
347
+ }
348
+ )
349
+ expect(described_class).to receive(:identify).with(identification)
350
+
351
+ described_class.send_identify(user.id, nil, first_name: 'John', last_name: 'Doe')
352
+ end
353
+ end
354
+ end
355
+ context 'with a device_id' do
212
356
  it 'sends an identify to AmplitudeAPI' do
213
357
  identification = AmplitudeAPI::Identification.new(
214
- user_id: 123,
358
+ user_id: user,
359
+ device_id: 'abc',
215
360
  user_properties: {
216
361
  first_name: 'John',
217
362
  last_name: 'Doe'
@@ -219,7 +364,7 @@ describe AmplitudeAPI do
219
364
  )
220
365
  expect(described_class).to receive(:identify).with(identification)
221
366
 
222
- described_class.send_identify(user.id, first_name: 'John', last_name: 'Doe')
367
+ described_class.send_identify(user, 'abc', first_name: 'John', last_name: 'Doe')
223
368
  end
224
369
  end
225
370
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amplitude-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rakoczy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-21 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.5.1
128
+ rubygems_version: 2.6.6
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Send events to the Amplitude API