Class: Cloudfuji::Event
- Inherits:
-
Object
- Object
- Cloudfuji::Event
- Defined in:
- lib/cloudfuji/event.rb
Overview
Cloudfuji::Event lists all the events from the Cloudfuji server. All events are hashes with the following keys:
-
category
-
name
-
data
Data will hold the arbitrary data for the type of event signalled
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .event_url(event_ido_id) ⇒ Object
- .events_url ⇒ Object
-
.find(event_ido_id) ⇒ Object
Find an event by its ido_id Be careful not to abuse this - an app can be throttled if requesting too many events too quickly, which will cause errors and a bad user experience for the end user.
- .publish(options = {}) ⇒ Object
-
.publish_locally(options) ⇒ Object
During development, allow developers to configure a list of local ports & keys to post Cloudfuji events e.g.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(options = {}) ⇒ Event
Returns a new instance of Event.
71 72 73 74 75 |
# File 'lib/cloudfuji/event.rb', line 71 def initialize(={}) @category = ["category"] @name = ["name"] @data = ["data"] end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
9 10 11 |
# File 'lib/cloudfuji/event.rb', line 9 def category @category end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/cloudfuji/event.rb', line 9 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/cloudfuji/event.rb', line 9 def name @name end |
Class Method Details
.event_url(event_ido_id) ⇒ Object
16 17 18 |
# File 'lib/cloudfuji/event.rb', line 16 def event_url(event_ido_id) "#{Cloudfuji::Platform.host}/apps/#{Cloudfuji::Platform.name}/events/#{event_ido_id}.json" end |
.events_url ⇒ Object
12 13 14 |
# File 'lib/cloudfuji/event.rb', line 12 def events_url "#{Cloudfuji::Platform.host}/apps/#{Cloudfuji::Platform.name}/events.json" end |
.find(event_ido_id) ⇒ Object
Find an event by its ido_id Be careful not to abuse this - an app can be throttled if requesting too many events too quickly, which will cause errors and a bad user experience for the end user
24 25 26 |
# File 'lib/cloudfuji/event.rb', line 24 def find(event_ido_id) Cloudfuji::Command.get_command(event_url(event_ido_id)) end |
.publish(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cloudfuji/event.rb', line 28 def publish(={}) # Enforce standard format on client side so that any errors # can be more quickly caught for the developer return StandardError("Cloudfuji::Event format incorrect, please make sure you're using the correct structure for sending events") unless ![:name].nil? && ![:category].nil? && ![:data].nil? publish_locally() and return if ENV['CLOUDFUJI_LOCAL_APPS'].present? payload = { :category => [:category], :name => [:name], :data => [:data] } # Baby-steps to multi-tenancy payload[:user_ido_id] = [:user_ido_id] if [:user_ido_id] payload[:target_id] = [:target_id] if [:target_id] Cloudfuji::Command.post_command(events_url, payload) end |
.publish_locally(options) ⇒ Object
During development, allow developers to configure a list of local ports & keys to post Cloudfuji events e.g. CLOUDFUJI_LOCAL_APPS=3000:abcdef,3001:abcdef
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cloudfuji/event.rb', line 51 def publish_locally() payload = { :category => [:category], :event => [:name], # Cloudfuji client uses :event key :data => [:data], 'auth_token' => '' # Cloudfuji client uses 'key' instead of 'auth_token' } ENV['CLOUDFUJI_LOCAL_APPS'].split(',').each do |app| port, key = app.split(":") unless port && key raise "ENV['CLOUDFUJI_LOCAL_APPS'] not formatted correctly, expecting: CLOUDFUJI_LOCAL_APPS=3000:abcdef,3001:abcdef" end payload[:key] = key url = "localhost:#{port.strip}/cloudfuji/data" Cloudfuji::Command.post_command(url, payload) end end |