Class: AmplitudeAPI
- Inherits:
-
Object
- Object
- AmplitudeAPI
- Defined in:
- lib/amplitude-api.rb,
lib/amplitude-api/event.rb,
lib/amplitude-api/version.rb
Defined Under Namespace
Classes: Event
Constant Summary collapse
- URI_STRING =
"https://api.amplitude.com/httpapi"- USER_WITH_NO_ACCOUNT =
"user who doesn't have an account"- VERSION =
'0.0.2'
Class Attribute Summary collapse
-
.api_key ⇒ String
An Amplitude API Key.
Class Method Summary collapse
-
.body(*events) ⇒ Hash
Converts a series of AmplitudeAPI::Event objects into a body suitable for the Amplitude API.
-
.send_event(event_name, user, properties = {}) ⇒ Typhoeus::Response
Send a single event immediately to the AmplitudeAPI.
-
.track(*events) ⇒ Typhoeus::Response
Send one or more Events to the Amplitude API.
Class Attribute Details
.api_key ⇒ String
Returns an Amplitude API Key.
14 15 16 |
# File 'lib/amplitude-api.rb', line 14 def api_key @api_key end |
Class Method Details
.body(event) ⇒ Hash .body([events]) ⇒ Hash
Converts a series of AmplitudeAPI::Event objects into a body suitable for the Amplitude API
38 39 40 41 42 43 44 45 46 |
# File 'lib/amplitude-api.rb', line 38 def body(*events) event_body = events.flatten.map do |event| event.to_hash end post_body = { api_key: self.api_key, event: JSON.generate(event_body) } end |
.send_event(event_name, user, properties = {}) ⇒ Typhoeus::Response
Send a single event immediately to the AmplitudeAPI
23 24 25 26 |
# File 'lib/amplitude-api.rb', line 23 def send_event(event_name, user, properties = {}) event = AmplitudeAPI::Event.new(user_id: user, event_type: event_name, event_properties: properties) track(event) end |
.track(event) ⇒ Typhoeus::Response .track([events]) ⇒ Typhoeus::Response
Send one or more Events to the Amplitude API
57 58 59 |
# File 'lib/amplitude-api.rb', line 57 def track(*events) Typhoeus.post(URI_STRING, body: body(events)) end |