Class: Arcticelvis::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/arcticelvis/event.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#created_at, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #parse_timestamps, #set_attributes

Constructor Details

This class inherits a constructor from Arcticelvis::Base

Instance Attribute Details

#event_messagesObject

Returns the value of attribute event_messages.



3
4
5
# File 'lib/arcticelvis/event.rb', line 3

def event_messages
  @event_messages
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/arcticelvis/event.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/arcticelvis/event.rb', line 3

def name
  @name
end

Class Method Details

.find(id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/arcticelvis/event.rb', line 6

def find(id)
  response, status = Arcticelvis.request(:get, "events/#{id}", {})
  raise RecordNotFoundError if status == 404

  event_messages = response["event"]["event_messages"]
  response["event"].delete("event_messages")
  event = self.new(response["event"])

  if event_messages
    res = []
    event_messages.each do |event_message|
      res << Arcticelvis::EventMessage.new(event_message)
    end
  end
  event.event_messages = res if res
  event
end

Instance Method Details

#trigger(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/arcticelvis/event.rb', line 25

def trigger(options={})
  raise InvalidOptionsError.new("no email given") unless options[:to]
  response, status = Arcticelvis.request(:post, "events/#{id}/trigger", options)
  raise RecordNotFoundError if status == 404
  if status == 201
    set_attributes(response["event_instance"]["event"])
    return self
  end
end