amplitude-api 0.1.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b743d15865f804837f6f3abb9557fa35aa6a32ae360fae0edfeaab0e7905b81
4
- data.tar.gz: 8c58bd5c4a21a36394cca7ce58da56b1e4135fc4ac574001e31350bda5cf3d69
3
+ metadata.gz: bf75d44cb2ccfb90961a3aa3875a245a8231edbb68d941325b6980ea10cf63d2
4
+ data.tar.gz: 7da5804bd41daa7c6dee8839119ad5640725b241ef8170f37919f5109f566855
5
5
  SHA512:
6
- metadata.gz: 3bf4707b9fe9905e95fdeee4c66044dfce02a2f4bae7fe939cffc343957ff4b2eb3d0dcf41d9c9dc958048f14fc8039c5d4e5c375103b7aeec4260e5a5a5c2d5
7
- data.tar.gz: 6cb4d59c569e8ccb3d8fc1f52920baba4ae6fa1da605115e6ed393a05119d1b275e58d00d18349cb840dd84b11b58416f3639e31eb95e4fb6c88eac55a378084
6
+ metadata.gz: 4979e1f81be283bf3324de9269ce36131ce16f3bd3dbb6bd257eb98d7f8e0e30e669bfb8cc6738eed1e29f2543eddf34b19448fb379814c63fb273ab25726863
7
+ data.tar.gz: 4301bb508042b66a85b4754e352bca971a3acb0cdee00b81ce6b1bb9359f1120770f70c16e59c71a9e4279d38b32ac5904108b8a4ddf2fe69767fea77ad0fd87
data/.gitignore CHANGED
@@ -34,4 +34,5 @@ build/
34
34
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
35
  .rvmrc
36
36
 
37
- .idea
37
+ .idea
38
+ amplitude-api.iml
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.3.1
5
- - 2.2.2
6
- - 2.1.6
4
+ - 2.6.1
5
+ - 2.4.6
6
+ - 2.3.8
7
+ - 2.2.10
@@ -3,6 +3,18 @@
3
3
  We would like to think our many [contributors](https://github.com/toothrot/amplitude-api/graphs/contributors) for
4
4
  suggestions, ideas and improvements to Amplitude API.
5
5
 
6
+ ## 0.1.1 (2019-01-01)
7
+
8
+ * Fix #41 - Delete API now correctly handles Arrays of IDs.
9
+
10
+ ## 0.1.0 (2019-01-01)
11
+
12
+ * Update Gem dependencies (thanks @kolorahl, @itamar, @krettan)
13
+ * Minimum ruby version is now 2.2
14
+ * Support Delete API (thanks @samjohn)
15
+ * Fix bundle Inline (thanks @jonduarte)
16
+ * Many fixes from @kolorahl
17
+
6
18
  ## 0.0.10 (2017-09-13)
7
19
 
8
20
  * Allow to use "Event Segmentation" via API ([#23](https://github.com/toothrot/amplitude-api/pull/23)).
@@ -1,4 +1,4 @@
1
- # rubocop:disable Style/FileName
1
+ # rubocop:disable Naming/FileName
2
2
  require_relative 'amplitude_api'
3
- # rubocop:enable Style/FileName
3
+ # rubocop:enable Naming/FileName
4
4
  # Whoops.
@@ -38,9 +38,9 @@ class AmplitudeAPI
38
38
  # @param [ String ] event_name a string that describes the event, e.g. "clicked on Home"
39
39
  # @param [ String ] user a string or integer that uniquely identifies a user.
40
40
  # @param [ String ] device a string that uniquely identifies the device.
41
- # @param [ Hash ] event_properties a hash that is serialized to JSON,
41
+ # @option options [ Hash ] event_properties a hash that is serialized to JSON,
42
42
  # and can contain any other property to be stored on the Event
43
- # @param [ Hash ] user_properties a hash that is serialized to JSON,
43
+ # @option options [ Hash ] user_properties a hash that is serialized to JSON,
44
44
  # and contains user properties to be associated with the user
45
45
  #
46
46
  # @return [ Typhoeus::Response ]
@@ -134,20 +134,20 @@ class AmplitudeAPI
134
134
 
135
135
  # Get metrics for an event with segmentation.
136
136
  #
137
- # @param [ Hash ] e a hash that defines event.
137
+ # @param [ Hash ] event a hash that defines event.
138
138
  # @param [ Time ] start_time a start time.
139
139
  # @param [ Time ] end_time a end time.
140
- # @param [ String ] m a string that defines aggregate function.
140
+ # @option options [ String ] m a string that defines aggregate function.
141
141
  # For non-property metrics: "uniques", "totals", "pct_dau", or "average" (default: "uniques").
142
142
  # For property metrics: "histogram", "sums", or "value_avg"
143
143
  # (note: a valid "group_by" value is required in parameter e).
144
- # @param [ Integer ] i an integer that defines segmentation interval.
144
+ # @option options [ Integer ] i an integer that defines segmentation interval.
145
145
  # Set to -300000, -3600000, 1, 7, or 30 for realtime, hourly, daily, weekly,
146
146
  # and monthly counts, respectively (default: 1). Realtime segmentation is capped at 2 days,
147
147
  # hourly segmentation is capped at 7 days, and daily at 365 days.
148
- # @param [ Array ] s an array that defines segment definitions.
149
- # @param [ String ] g a string that defines property to group by.
150
- # @param [ Integer ] limit an integer that defines number of Group By values
148
+ # @option options [ Array ] s an array that defines segment definitions.
149
+ # @option options [ String ] g a string that defines property to group by.
150
+ # @option options [ Integer ] limit an integer that defines number of Group By values
151
151
  # returned (default: 100). The maximum limit is 1000.
152
152
  #
153
153
  # @return [ Typhoeus::Response ]
@@ -164,27 +164,39 @@ class AmplitudeAPI
164
164
  }.delete_if { |_, value| value.nil? }
165
165
  end
166
166
 
167
- # ==== GDPR compliance methods
168
-
169
- # Delete a user from amplitude when they request it to comply with GDPR
167
+ # Delete a user from amplitude
168
+ #
170
169
  # You must pass in either an array of user_ids or an array of amplitude_ids
171
170
  #
172
- # @param [ user_ids ] (optional) the user_ids to delete
171
+ # @param [ Array<String> ] (optional) the user_ids to delete
173
172
  # based on your database
174
- # @param [ amplitude_ids ] (optional) the amplitude_ids to delete
173
+ # @param [ Array<Integer> ] (optional) the amplitude_ids to delete
175
174
  # based on the amplitude database
176
- # @param [ requester ] the email address of the person who
175
+ # @param [ String ] requester the email address of the person who
177
176
  # is requesting the deletion, optional but useful for reporting
178
177
  #
179
178
  # @return [ Typhoeus::Response ]
180
179
  def delete(user_ids: nil, amplitude_ids: nil, requester: nil)
181
- Typhoeus.post DELETION_URI_STRING,
182
- userpwd: "#{api_key}:#{config.secret_key}",
183
- body: {
184
- amplitude_ids: amplitude_ids,
185
- user_ids: user_ids,
186
- requester: requester
187
- }.delete_if { |_, value| value.nil? }
180
+ user_ids = Array(user_ids)
181
+ amplitude_ids = Array(amplitude_ids)
182
+ Typhoeus.post(
183
+ DELETION_URI_STRING,
184
+ userpwd: "#{api_key}:#{config.secret_key}",
185
+ body: delete_body(user_ids, amplitude_ids, requester),
186
+ headers: { 'Content-Type': 'application/json' }
187
+ )
188
+ end
189
+
190
+ private
191
+
192
+ def delete_body(user_ids, amplitude_ids, requester)
193
+ JSON.generate(
194
+ {
195
+ amplitude_ids: amplitude_ids,
196
+ user_ids: user_ids,
197
+ requester: requester
198
+ }.delete_if { |_, value| value.nil? || value.empty? }
199
+ )
188
200
  end
189
201
  end
190
202
  end
@@ -1,3 +1,3 @@
1
1
  class AmplitudeAPI
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/readme.md CHANGED
@@ -31,7 +31,7 @@ event = AmplitudeAPI::Event.new({
31
31
  AmplitudeAPI.track(event)
32
32
  ```
33
33
 
34
- ## GDPR Compliance
34
+ ## User Privacy APIs
35
35
 
36
36
  The following code snippet will delete a user from amplitude
37
37
 
@@ -43,11 +43,12 @@ AmplitudeAPI.config.api_key = "abcdef123456"
43
43
  AmplitudeAPI.config.secret_key = "secretMcSecret"
44
44
 
45
45
  AmplitudeAPI.delete(user_ids: [233],
46
- requester: "privacy@mycompany.com"
46
+ requester: "privacy@example.com"
47
47
  )
48
48
  ```
49
49
 
50
- Currently, we are using this in Rails and using ActiveJob to dispatch events asynchronously. I plan on moving background/asynchronous support into this gem.
50
+ Currently, we are using this in Rails and using ActiveJob to dispatch events asynchronously. I plan on moving
51
+ background/asynchronous support into this gem.
51
52
 
52
53
  ## What's Next
53
54
 
@@ -376,6 +376,22 @@ describe AmplitudeAPI do
376
376
  end
377
377
 
378
378
  describe '.delete' do
379
+ context 'a single user_id' do
380
+ it 'correctly formats the response' do
381
+ body = {
382
+ user_ids: ['123']
383
+ }
384
+
385
+ expect(Typhoeus).to receive(:post).with(
386
+ AmplitudeAPI::DELETION_URI_STRING,
387
+ userpwd: "#{described_class.api_key}:#{described_class.config.secret_key}",
388
+ body: JSON.generate(body),
389
+ headers: { 'Content-Type': 'application/json' }
390
+ )
391
+ described_class.delete(user_ids: '123')
392
+ end
393
+ end
394
+
379
395
  context 'with user_ids' do
380
396
  it 'sends the deletion to Amplitude' do
381
397
  user_ids = [123, 456, 555]
@@ -386,7 +402,8 @@ describe AmplitudeAPI do
386
402
  expect(Typhoeus).to receive(:post).with(
387
403
  AmplitudeAPI::DELETION_URI_STRING,
388
404
  userpwd: "#{described_class.api_key}:#{described_class.config.secret_key}",
389
- body: body
405
+ body: JSON.generate(body),
406
+ headers: { 'Content-Type': 'application/json' }
390
407
  )
391
408
  described_class.delete(user_ids: user_ids)
392
409
  end
@@ -396,14 +413,15 @@ describe AmplitudeAPI do
396
413
  user_ids = [123, 456, 555]
397
414
  amplitude_ids = [122, 456]
398
415
  body = {
399
- user_ids: user_ids,
400
- amplitude_ids: amplitude_ids
416
+ amplitude_ids: amplitude_ids,
417
+ user_ids: user_ids
401
418
  }
402
419
 
403
420
  expect(Typhoeus).to receive(:post).with(
404
421
  AmplitudeAPI::DELETION_URI_STRING,
405
422
  userpwd: "#{described_class.api_key}:#{described_class.config.secret_key}",
406
- body: body
423
+ body: JSON.generate(body),
424
+ headers: { 'Content-Type': 'application/json' }
407
425
  )
408
426
  described_class.delete(
409
427
  amplitude_ids: amplitude_ids,
@@ -423,12 +441,29 @@ describe AmplitudeAPI do
423
441
  expect(Typhoeus).to receive(:post).with(
424
442
  AmplitudeAPI::DELETION_URI_STRING,
425
443
  userpwd: "#{described_class.api_key}:#{described_class.config.secret_key}",
426
- body: body
444
+ body: JSON.generate(body),
445
+ headers: { 'Content-Type': 'application/json' }
427
446
  )
428
447
  described_class.delete(amplitude_ids: amplitude_ids)
429
448
  end
430
449
  end
431
450
 
451
+ context 'a single amplitude_id' do
452
+ it 'correctly formats the response' do
453
+ body = {
454
+ amplitude_ids: [122]
455
+ }
456
+
457
+ expect(Typhoeus).to receive(:post).with(
458
+ AmplitudeAPI::DELETION_URI_STRING,
459
+ userpwd: "#{described_class.api_key}:#{described_class.config.secret_key}",
460
+ body: JSON.generate(body),
461
+ headers: { 'Content-Type': 'application/json' }
462
+ )
463
+ described_class.delete(amplitude_ids: 122)
464
+ end
465
+ end
466
+
432
467
  context 'with requester' do
433
468
  it 'sends the deletion to Amplitude' do
434
469
  amplitude_ids = [122, 456]
@@ -439,9 +474,12 @@ describe AmplitudeAPI do
439
474
  }
440
475
  userpwd = "#{described_class.api_key}:#{described_class.config.secret_key}"
441
476
 
442
- expect(Typhoeus).to receive(:post).with(AmplitudeAPI::DELETION_URI_STRING,
443
- userpwd: userpwd,
444
- body: body)
477
+ expect(Typhoeus).to receive(:post).with(
478
+ AmplitudeAPI::DELETION_URI_STRING,
479
+ userpwd: userpwd,
480
+ body: JSON.generate(body),
481
+ headers: { 'Content-Type': 'application/json' }
482
+ )
445
483
  described_class.delete(
446
484
  amplitude_ids: amplitude_ids,
447
485
  requester: 'privacy@gethopscotch.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amplitude-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rakoczy