Class: Megam::Event

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/event.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ Event

Returns a new instance of Event.



19
20
21
22
23
24
25
# File 'lib/megam/core/event.rb', line 19

def initialize(email=nil, api_key=nil)
  @a_id = nil
  @a_name = nil
  @command = nil
  @launch_type = nil
  super(email, api_key)
end

Class Method Details

.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



123
124
125
126
127
# File 'lib/megam/core/event.rb', line 123

def self.create(o,tmp_email=nil, tmp_api_key=nil)
 
  event = from_hash(o, tmp_email, tmp_api_key)
  event.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



108
109
110
111
112
# File 'lib/megam/core/event.rb', line 108

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  event = self.new(tmp_email, tmp_api_key)
  event.from_hash(o)
  event
end

.json_create(o) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/megam/core/event.rb', line 99

def self.json_create(o)
  event = new
  event.a_id(o["a_id"]) if o.has_key?("a_id")
  event.a_name(o["a_name"]) if o.has_key?("a_name")
  event.command(o["command"]) if o.has_key?("command")
  event.launch_type(o["launch_type"]) if o.has_key?("launch_type") #this will be an array? can hash store array?
  event
end

.list(tmp_email = nil, tmp_api_key = nil, inflated = false) ⇒ Object



136
137
138
139
# File 'lib/megam/core/event.rb', line 136

def self.list(tmp_email=nil, tmp_api_key=nil, inflated=false)
  event = self.new(tmp_email, tmp_api_key)
  event.megam_rest.get_events
end

Instance Method Details

#a_id(arg = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/megam/core/event.rb', line 32

def a_id(arg=nil)
  if arg != nil
    @a_id = arg
  else
  @a_id
  end
end

#a_name(arg = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/megam/core/event.rb', line 41

def a_name(arg=nil)
  if arg != nil
    @a_name = arg
  else
  @a_name
  end
end

#command(arg = nil) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/megam/core/event.rb', line 52

def command(arg=nil)
  if arg != nil
    @command = arg
  else
  @command
  end
end

#createObject

Create the node via the REST API



130
131
132
# File 'lib/megam/core/event.rb', line 130

def create
  megam_rest.post_event(to_hash)
end

#error?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/megam/core/event.rb', line 68

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#eventObject



27
28
29
# File 'lib/megam/core/event.rb', line 27

def event
  self
end

#for_jsonObject



89
90
91
92
93
94
95
96
97
# File 'lib/megam/core/event.rb', line 89

def for_json
  result = {
    "a_id" => a_id,
    "a_name" => a_name,
    "command" => command,
    "launch_type" => launch_type
    }
  result
end

#from_hash(o) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/megam/core/event.rb', line 114

def from_hash(o)
  @a_id                = o[:a_id] if o.has_key?(:a_id)
  @a_name              = o[:a_name] if o.has_key?(:a_name)
  @command      = o[:command] if o.has_key?(:command)
  @launch_type        = o[:launch_type] if o.has_key?(:launch_type)
  
 self
end

#launch_type(arg = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/megam/core/event.rb', line 60

def launch_type(arg=nil)
  if arg != nil
    @launch_type = arg
  else
  @launch_type
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



73
74
75
76
77
78
79
80
81
# File 'lib/megam/core/event.rb', line 73

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["a_id"] = a_id
  index_hash["a_name"] = a_name
  index_hash["command"] = command
  index_hash["launch_type"] = launch_type
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



85
86
87
# File 'lib/megam/core/event.rb', line 85

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



141
142
143
# File 'lib/megam/core/event.rb', line 141

def to_s
  Megam::Stuff.styled_hash(to_hash)
end