amplitude-api 0.0.1 → 0.0.2
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/amplitude-api.gemspec +1 -0
- data/lib/amplitude-api.rb +29 -1
- data/lib/amplitude-api/event.rb +20 -1
- data/lib/amplitude-api/version.rb +1 -1
- data/readme.md +36 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f625e998fbbf49741c6d66627ec9d3bd1f8b5579
|
4
|
+
data.tar.gz: 454dbcd32d0e2a7bd613b6dac4e85c30e3700f12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03fb85419fa8ad2aeeb03fd66a7fa1b42c47ba91bc60ea06fe7f5dbd1394b8df292a39e2f01cb2bfb34997cf219a0752319192c15a360312d9f2b67e1a06c46f
|
7
|
+
data.tar.gz: 72bce071dc1cb54dc7f1b6fa3a3766f8ee089565758bf743044608ad318b155cd325c6e6ea00be93f250795ab932ee2f468960a95032332b7db8c2d64f975a69
|
data/amplitude-api.gemspec
CHANGED
data/lib/amplitude-api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'bundler/setup'
|
3
|
-
|
3
|
+
require 'typhoeus'
|
4
4
|
require 'amplitude-api/event'
|
5
5
|
|
6
6
|
class AmplitudeAPI
|
@@ -9,13 +9,32 @@ class AmplitudeAPI
|
|
9
9
|
USER_WITH_NO_ACCOUNT = "user who doesn't have an account"
|
10
10
|
|
11
11
|
class << self
|
12
|
+
# @!attribute [ rw ] api_key
|
13
|
+
# @return [ String ] an Amplitude API Key
|
12
14
|
attr_accessor :api_key
|
13
15
|
|
16
|
+
# Send a single event immediately to the AmplitudeAPI
|
17
|
+
#
|
18
|
+
# @param [ String ] event_name a string that describes the event, e.g. "clicked on Home"
|
19
|
+
# @param [ String ] user a string or integer that uniquely identifies a user.
|
20
|
+
# @param [ Hash ] properties a hash that is serialized to JSON, and can contain any other property to be stored on the Event
|
21
|
+
#
|
22
|
+
# @return [ Typhoeus::Response ]
|
14
23
|
def send_event(event_name, user, properties = {})
|
15
24
|
event = AmplitudeAPI::Event.new(user_id: user, event_type: event_name, event_properties: properties)
|
16
25
|
track(event)
|
17
26
|
end
|
18
27
|
|
28
|
+
# @overload body(event)
|
29
|
+
# @param [ AmplitudeAPI::Event ]
|
30
|
+
#
|
31
|
+
# @overload body([events])
|
32
|
+
# @param [ Array<AmplitudeAPI::Event> ]
|
33
|
+
#
|
34
|
+
# @return [ Hash ]
|
35
|
+
#
|
36
|
+
# Converts a series of AmplitudeAPI::Event objects into a body
|
37
|
+
# suitable for the Amplitude API
|
19
38
|
def body(*events)
|
20
39
|
event_body = events.flatten.map do |event|
|
21
40
|
event.to_hash
|
@@ -26,6 +45,15 @@ class AmplitudeAPI
|
|
26
45
|
}
|
27
46
|
end
|
28
47
|
|
48
|
+
# @overload track(event)
|
49
|
+
# @param [ AmplitudeAPI::Event ] Send a single event to the Amplitude API
|
50
|
+
#
|
51
|
+
# @overload track([events])
|
52
|
+
# @param [ Array<AmplitudeAPI::Event> ] Send an array of events in a single request to Amplitude
|
53
|
+
#
|
54
|
+
# @return [ Typhoeus::Response ]
|
55
|
+
#
|
56
|
+
# Send one or more Events to the Amplitude API
|
29
57
|
def track(*events)
|
30
58
|
Typhoeus.post(URI_STRING, body: body(events))
|
31
59
|
end
|
data/lib/amplitude-api/event.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
class AmplitudeAPI
|
2
2
|
class Event
|
3
|
-
|
3
|
+
# @!attribute [ rw ] user_id
|
4
|
+
# @return [ String ] the user_id to be sent to Amplitude
|
5
|
+
attr_accessor :user_id
|
6
|
+
# @!attribute [ rw ] event_type
|
7
|
+
# @return [ String ] the event_type to be sent to Amplitude
|
8
|
+
attr_accessor :event_type
|
9
|
+
# @!attribute [ rw ] event_properties
|
10
|
+
# @return [ String ] the event_properties to be attached to the Amplitude Event
|
11
|
+
attr_accessor :event_properties
|
4
12
|
|
13
|
+
# Create a new Event
|
14
|
+
#
|
15
|
+
# @param [ String ] user_id a user_id to associate with the event
|
16
|
+
# @param [ String ] event_type a name for the event
|
17
|
+
# @param [ Hash ] event_properties various properties to attach to the event
|
5
18
|
def initialize(user_id: , event_type: , event_properties: {})
|
6
19
|
self.user_id = user_id
|
7
20
|
self.event_type = event_type
|
@@ -17,6 +30,9 @@ class AmplitudeAPI
|
|
17
30
|
end
|
18
31
|
end
|
19
32
|
|
33
|
+
# @return [ Hash ] A serialized Event
|
34
|
+
#
|
35
|
+
# Used for serialization and comparison
|
20
36
|
def to_hash
|
21
37
|
{
|
22
38
|
event_type: self.event_type,
|
@@ -25,6 +41,9 @@ class AmplitudeAPI
|
|
25
41
|
}
|
26
42
|
end
|
27
43
|
|
44
|
+
# @return [ true, false ]
|
45
|
+
#
|
46
|
+
# Compares +to_hash+ for equality
|
28
47
|
def ==(other)
|
29
48
|
if other.respond_to?(:to_hash)
|
30
49
|
self.to_hash == other.to_hash
|
data/readme.md
CHANGED
@@ -1,2 +1,38 @@
|
|
1
1
|
# Amplitude API
|
2
2
|
[](https://travis-ci.org/toothrot/amplitude-api)
|
3
|
+
[](http://badge.fury.io/rb/amplitude-api)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install amplitude-api
|
9
|
+
```
|
10
|
+
|
11
|
+
## Basic Usage
|
12
|
+
|
13
|
+
The following code snippet will immediately track an event to the Amplitude API. The time on the event will automatically be the time of the request.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# Configure your Amplitude API key
|
17
|
+
AmplitudeAPI.api_key = "abcdef123456"
|
18
|
+
|
19
|
+
event = AmplitudeAPI::Event.new({
|
20
|
+
user_id: "123",
|
21
|
+
event_type: "clicked on Home",
|
22
|
+
event_properties: {
|
23
|
+
cause: "button",
|
24
|
+
arbitrary: "properties"
|
25
|
+
}
|
26
|
+
})
|
27
|
+
AmplitudeAPI.track(event)
|
28
|
+
```
|
29
|
+
|
30
|
+
## What's Next
|
31
|
+
|
32
|
+
* Thread support for background dispatching in bulk
|
33
|
+
* `device_id` support as an alternative to `user_id`
|
34
|
+
* Configurable default account to use when no `user_id` present
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
I'd love to hear how you're using this. Please check out the [issues](https://github.com/toothrot/amplitude-api/issues).
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rakoczy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -110,9 +110,9 @@ require_paths:
|
|
110
110
|
- lib
|
111
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
|
-
- - "
|
113
|
+
- - "~>"
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: '0'
|
115
|
+
version: '2.0'
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
118
|
- - ">="
|
@@ -128,3 +128,4 @@ test_files:
|
|
128
128
|
- spec/lib/amplitude-api/event_spec.rb
|
129
129
|
- spec/lib/amplitude_api_spec.rb
|
130
130
|
- spec/spec_helper.rb
|
131
|
+
has_rdoc:
|