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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481d091552b42dfbe151aa5e58e50dedf2436d38
4
- data.tar.gz: 8b391658f981b64f12d0fd683f1cc996a215dd36
3
+ metadata.gz: f625e998fbbf49741c6d66627ec9d3bd1f8b5579
4
+ data.tar.gz: 454dbcd32d0e2a7bd613b6dac4e85c30e3700f12
5
5
  SHA512:
6
- metadata.gz: 6418d071d74f61e23b996c32a04929f70efe45a9df7ffd194f956214a855ab4a3033f90a43dd1726096b382833abf8bea45c4d319dca20fea6da621ebd0e24a4
7
- data.tar.gz: 8b1324f82be861baf1e40e90e3e5ed861fffc5fbeac7fecc1b515849a7f240cdac8fc3491bf7159e660f9c9b5ae1ecbfb846236e96eeb0c1a2eee4b812dbf43e
6
+ metadata.gz: 03fb85419fa8ad2aeeb03fd66a7fa1b42c47ba91bc60ea06fe7f5dbd1394b8df292a39e2f01cb2bfb34997cf219a0752319192c15a360312d9f2b67e1a06c46f
7
+ data.tar.gz: 72bce071dc1cb54dc7f1b6fa3a3766f8ee089565758bf743044608ad318b155cd325c6e6ea00be93f250795ab932ee2f468960a95032332b7db8c2d64f975a69
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~> 10.0", '>= 10.0'
23
23
  spec.add_development_dependency "pry", "~> 0.9.12.6"
24
24
  spec.add_dependency "typhoeus", "~> 0.7.1"
25
+ spec.required_ruby_version = '~> 2.0'
25
26
  end
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
  require 'bundler/setup'
3
- Bundler.require(:default)
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
@@ -1,7 +1,20 @@
1
1
  class AmplitudeAPI
2
2
  class Event
3
- attr_accessor :user_id, :event_type, :event_properties
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
@@ -1,3 +1,3 @@
1
1
  class AmplitudeAPI
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/readme.md CHANGED
@@ -1,2 +1,38 @@
1
1
  # Amplitude API
2
2
  [![Build Status](https://travis-ci.org/toothrot/amplitude-api.svg?branch=master)](https://travis-ci.org/toothrot/amplitude-api)
3
+ [![Gem Version](https://badge.fury.io/rb/amplitude-api.svg)](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.1
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-05-28 00:00:00.000000000 Z
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: