Class: Megam::BoltRequest

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

Returns a new instance of BoltRequest.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/megam/core/bolt_request.rb', line 18

def initialize(email=nil, api_key=nil)
  @id = nil
  @req_type = nil
  @boltdefns_id = nil
  @node_name = nil
  @lc_apply = nil
  @lc_additional = nil
  @lc_when = nil
  @created_at = nil
  @some_msg = {}
  super(email, api_key)
end

Class Method Details

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



204
205
206
207
# File 'lib/megam/core/bolt_request.rb', line 204

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

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



186
187
188
189
190
# File 'lib/megam/core/bolt_request.rb', line 186

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

.json_create(o) ⇒ Object

Create a Megam::Node from NodeResult-JSON

[{ “id”:“NOD362212018897289216”, “accounts_id”:“ACT362211962353876992”, “json_claz”:“Megam::Node”, “request”:{ “req_id”:“NOD362212018897289216”, “command”:“commands” }, “predefs”:{ “name”:“”, “scm”:“”, “war”:“”, “db”:“”, “queue”:“” } }]



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/megam/core/bolt_request.rb', line 167

def self.json_create(o)
  boltreqs = new
  boltreqs.id(o["id"]) if o.has_key?("id")
  boltreqs.req_type(o["req_type"]) if o.has_key?("req_type")
  boltreqs.boltdefns_id(o["boltdefns_id"]) if o.has_key?("boltdefns_id")
  boltreqs.node_name(o["node_name"]) if o.has_key?("node_name")
  boltreqs.lc_apply(o["lc_apply"]) if o.has_key?("lc_apply")
  boltreqs.lc_additional(o["lc_additional"]) if o.has_key?("lc_additional")
  boltreqs.lc_when(o["lc_when"]) if o.has_key?("lc_when")
  boltreqs.created_at(o["created_at"]) if o.has_key?("created_at")

  boltreqs.some_msg[:code] = o["code"] if o.has_key?("code")
  boltreqs.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  boltreqs.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  boltreqs.some_msg[:links] = o["links"] if o.has_key?("links")

  boltreqs
end

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

Load a account by email_p



215
216
217
218
# File 'lib/megam/core/bolt_request.rb', line 215

def self.list(node_name,tmp_email=nil, tmp_api_key=nil)
  boltreq = self.new(tmp_email, tmp_api_key)
  boltreq.megam_rest.get_boltreq(node_name)
end

Instance Method Details

#boltdefns_id(arg = nil) ⇒ Object



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

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

#boltreqsObject



31
32
33
# File 'lib/megam/core/bolt_request.rb', line 31

def boltreqs
  self
end

#createObject

Create the node via the REST API



210
211
212
# File 'lib/megam/core/bolt_request.rb', line 210

def create
  megam_rest.post_boltreq(to_hash)
end

#created_at(arg = nil) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/megam/core/bolt_request.rb', line 92

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

#error?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/megam/core/bolt_request.rb', line 108

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

#for_jsonObject



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/megam/core/bolt_request.rb', line 134

def for_json
  result = {
    "id" => id,
    "req_type" => req_type,
    "boltdefns_id" => boltdefns_id,
    "node_name" => node_name,
    "lc_apply" => lc_apply,
    "lc_additional" => lc_additional,
    "lc_when" => lc_when,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/megam/core/bolt_request.rb', line 192

def from_hash(o)
  @id        = o["id"] if o.has_key?("id")
  @req_type        = o["req_type"] if o.has_key?("req_type")
  @boltdefns_id    = o["boltdefns_id"] if o.has_key?("boltdefns_id")
  @node_name = o["node_name"] if o.has_key?("node_name")
  @lc_apply   = o["lc_apply"] if o.has_key?("lc_apply")
  @lc_additional   = o["lc_additional"] if o.has_key?("lc_additional")
  @lc_when   = o["lc_when"] if o.has_key?("lc_when")
  @created_at        = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/megam/core/bolt_request.rb', line 36

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

#lc_additional(arg = nil) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/megam/core/bolt_request.rb', line 76

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

#lc_apply(arg = nil) ⇒ Object



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

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

#lc_when(arg = nil) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/megam/core/bolt_request.rb', line 84

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

#node_name(arg = nil) ⇒ Object



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

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

#req_type(arg = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/megam/core/bolt_request.rb', line 44

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

#some_msg(arg = nil) ⇒ Object



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

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



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/megam/core/bolt_request.rb', line 113

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["req_type"] = req_type
  index_hash["boltdefns_id"] = boltdefns_id
  index_hash["node_name"] = node_name
  index_hash["lc_apply"] = lc_apply
  index_hash["lc_additional"] = lc_additional
  index_hash["lc_when"] = lc_when
  index_hash["created_at"] = created_at
  index_hash["some_msg"] = some_msg
  index_hash
end

#to_json(*a) ⇒ Object

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



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

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

#to_sObject



220
221
222
# File 'lib/megam/core/bolt_request.rb', line 220

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