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 +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +4 -3
- data/Changelog.md +12 -0
- data/lib/amplitude-api.rb +2 -2
- data/lib/amplitude_api.rb +33 -21
- data/lib/amplitude_api/version.rb +1 -1
- data/readme.md +4 -3
- data/spec/lib/amplitude_api_spec.rb +46 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf75d44cb2ccfb90961a3aa3875a245a8231edbb68d941325b6980ea10cf63d2
|
4
|
+
data.tar.gz: 7da5804bd41daa7c6dee8839119ad5640725b241ef8170f37919f5109f566855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4979e1f81be283bf3324de9269ce36131ce16f3bd3dbb6bd257eb98d7f8e0e30e669bfb8cc6738eed1e29f2543eddf34b19448fb379814c63fb273ab25726863
|
7
|
+
data.tar.gz: 4301bb508042b66a85b4754e352bca971a3acb0cdee00b81ce6b1bb9359f1120770f70c16e59c71a9e4279d38b32ac5904108b8a4ddf2fe69767fea77ad0fd87
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -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)).
|
data/lib/amplitude-api.rb
CHANGED
data/lib/amplitude_api.rb
CHANGED
@@ -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
|
-
# @
|
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
|
-
# @
|
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 ]
|
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
|
-
# @
|
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
|
-
# @
|
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
|
-
# @
|
149
|
-
# @
|
150
|
-
# @
|
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
|
-
#
|
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 [
|
171
|
+
# @param [ Array<String> ] (optional) the user_ids to delete
|
173
172
|
# based on your database
|
174
|
-
# @param [
|
173
|
+
# @param [ Array<Integer> ] (optional) the amplitude_ids to delete
|
175
174
|
# based on the amplitude database
|
176
|
-
# @param [
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
data/readme.md
CHANGED
@@ -31,7 +31,7 @@ event = AmplitudeAPI::Event.new({
|
|
31
31
|
AmplitudeAPI.track(event)
|
32
32
|
```
|
33
33
|
|
34
|
-
##
|
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@
|
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
|
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
|
-
|
400
|
-
|
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(
|
443
|
-
|
444
|
-
|
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'
|