Class: Megam::CSAR

Inherits:
ServerAPI
  • Object
show all
Defined in:
lib/megam/core/csar.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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



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

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.



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

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



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

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



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

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)



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

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



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

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.



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

def create
  megam_rest.post_csar(to_hash)
end

#created_at(arg = nil) ⇒ Object



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

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

#csarObject



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

def csar
  self
end

#desc(arg = nil) ⇒ Object



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

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

#error?Boolean



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

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

#for_jsonObject



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

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

#from_hash(o) ⇒ Object



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

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



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

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


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

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

#some_msg(arg = nil) ⇒ Object



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

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



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

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.



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

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

#to_sObject



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

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