Class: Bushido::Event

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @category = options["category"]
  @name     = options["name"]
  @data     = options["data"]
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



15
16
17
# File 'lib/bushido/event.rb', line 15

def category
  @category
end

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/bushido/event.rb', line 15

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/bushido/event.rb', line 15

def name
  @name
end

Class Method Details

.allObject

Lists all events



23
24
25
# File 'lib/bushido/event.rb', line 23

def all
  @@events.collect{ |e| Event.new(e) }
end

.events_urlObject



18
19
20
# File 'lib/bushido/event.rb', line 18

def events_url
  "#{Bushido::Platform.host}/apps/#{Bushido::Platform.name}/events.json"
end

.firstObject

Lists the first (oldest) event



28
29
30
# File 'lib/bushido/event.rb', line 28

def first
  Event.new(@@events.first)
end

.lastObject

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(options={})
  # 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 !options[:name].nil? && !options[:category].nil? && !options[:data].nil?

  payload            = {}
  payload[:category] = options[:category]
  payload[:name]     = options[:name]
  payload[:data]     = options[:data]

  Bushido::Command.post_command(events_url, payload)
end

.refreshObject

NOOP right now



38
39
40
# File 'lib/bushido/event.rb', line 38

def refresh
  @@events = Bushido::Command.get_command(events_url)
end