Class: Megam::CSAR

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/csar.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) ⇒ CSAR

Returns a new instance of CSAR.



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

def initialize(email=nil, api_key=nil)
  @id = nil
  @desc = nil
  @link = {}
  @some_msg = {}
  @created_at = nil
  super(email, api_key)
end

Class Method Details

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

This won’t work, as the body just needs the yaml string.



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

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

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



121
122
123
124
125
# File 'lib/megam/core/csar.rb', line 121

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

.json_create(o) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/megam/core/csar.rb', line 106

def self.json_create(o)
  csarjslf = new
  csarjslf.id(o["id"]) if o.has_key?("id")
  csarjslf.desc(o["desc"]) if o.has_key?("desc")
  csarjslf.link(o["link"]) if o.has_key?("link")

  #success or error
  csarjslf.some_msg[:code] = o["code"] if o.has_key?("code")
  csarjslf.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  csarjslf.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  csarjslf.some_msg[:links] = o["links"] if o.has_key?("links")

  csarjslf
end

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

list all csars (links)



154
155
156
157
# File 'lib/megam/core/csar.rb', line 154

def self.list(tmp_email=nil, tmp_api_key=nil)
  csarslf = self.new(tmp_email, tmp_api_key)
  csarslf.megam_rest.get_csars
end

.show(tmp_email = nil, tmp_api_key = nil, csarlink_name) ⇒ Object

Load the yaml back from the link



148
149
150
151
# File 'lib/megam/core/csar.rb', line 148

def self.show(tmp_email=nil, tmp_api_key=nil, csarlink_name)
  csarslf = self.new(tmp_email, tmp_api_key)
  csarslf.megam_rest.get_csar(csarlink_name)
end

Instance Method Details

#createObject

Create the csar yaml This won’t work, as the body just needs the yaml string.



143
144
145
# File 'lib/megam/core/csar.rb', line 143

def create
  megam_rest.post_csar(to_hash)
end

#created_at(arg = nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/megam/core/csar.rb', line 58

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

#csarObject



28
29
30
# File 'lib/megam/core/csar.rb', line 28

def csar
  self
end

#desc(arg = nil) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/megam/core/csar.rb', line 74

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

#for_jsonObject



96
97
98
99
100
101
102
103
104
# File 'lib/megam/core/csar.rb', line 96

def for_json
  result = {
    "id" => id,
    "desc" => desc,
    "link" => link,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/megam/core/csar.rb', line 127

def from_hash(o)
  @id        = o["id"] if o.has_key?("id")
  @desc      = o["desc"] if o.has_key?("desc")
  @link      = o["link"] if o.has_key?("link")
  @created_at = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



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

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


49
50
51
52
53
54
55
# File 'lib/megam/core/csar.rb', line 49

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

#some_msg(arg = nil) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/megam/core/csar.rb', line 66

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

#to_hashObject

Transform the ruby obj -> to a Hash



79
80
81
82
83
84
85
86
87
88
# File 'lib/megam/core/csar.rb', line 79

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["desc"] = desc
  index_hash["link"] = link
  index_hash["some_msg"] = some_msg
  index_hash["created_at"] = created_at
  index_hash
end

#to_json(*a) ⇒ Object

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



92
93
94
# File 'lib/megam/core/csar.rb', line 92

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

#to_sObject



159
160
161
# File 'lib/megam/core/csar.rb', line 159

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