Class: Bushido::Event
- Inherits:
-
Object
- Object
- Bushido::Event
- Defined in:
- lib/bushido/event.rb
Overview
Bushido::Event lists all the events from the Bushido 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
-
.all ⇒ Object
Lists all events.
- .events_url ⇒ Object
-
.first ⇒ Object
Lists the first (oldest) event.
-
.last ⇒ Object
Lists the last (newest) event.
- .publish(options = {}) ⇒ Object
-
.refresh ⇒ Object
NOOP right now.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(options = {}) ⇒ Event
Returns a new instance of Event.
56 57 58 59 60 |
# File 'lib/bushido/event.rb', line 56 def initialize(={}) @category = ["category"] @name = ["name"] @data = ["data"] end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
15 16 17 |
# File 'lib/bushido/event.rb', line 15 def category @category end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/bushido/event.rb', line 15 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/bushido/event.rb', line 15 def name @name end |
Class Method Details
.all ⇒ Object
Lists all events
23 24 25 |
# File 'lib/bushido/event.rb', line 23 def all @@events.collect{ |e| Event.new(e) } end |
.events_url ⇒ Object
18 19 20 |
# File 'lib/bushido/event.rb', line 18 def events_url "#{Bushido::Platform.host}/apps/#{Bushido::Platform.name}/events.json" end |
.first ⇒ Object
Lists the first (oldest) event
28 29 30 |
# File 'lib/bushido/event.rb', line 28 def first Event.new(@@events.first) end |
.last ⇒ Object
Lists the last (newest) event
33 34 35 |
# File 'lib/bushido/event.rb', line 33 def last Event.new(@@events.last) end |
.publish(options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bushido/event.rb', line 42 def publish(={}) # Enforce standard format on client side so that any errors # can be more quickly caught for the developer return StandardError("Bushido::Event format incorrect, please make sure you're using the correct structure for sending events") unless ![:name].nil? && ![:category].nil? && ![:data].nil? payload = {} payload[:category] = [:category] payload[:name] = [:name] payload[:data] = [:data] Bushido::Command.post_command(events_url, payload) end |
.refresh ⇒ Object
NOOP right now
38 39 40 |
# File 'lib/bushido/event.rb', line 38 def refresh @@events = Bushido::Command.get_command(events_url) end |