Class: Megam::Request
Instance Attribute Summary
Attributes inherited from RestAdapter
#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from RestAdapter
#megam_rest
Constructor Details
#initialize(params) ⇒ Request
Returns a new instance of Request.
3
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/megam/core/request.rb', line 3
def initialize(params)
@id = nil
@cat_id = nil
@name = nil
@cattype = nil
@action = nil
@category = nil
@some_msg = {}
@created_at = nil
super(params)
end
|
Class Method Details
.create(params) ⇒ Object
158
159
160
161
|
# File 'lib/megam/core/request.rb', line 158
def self.create(params)
acct = from_hash(params)
acct.create
end
|
.from_hash(o) ⇒ Object
140
141
142
143
144
|
# File 'lib/megam/core/request.rb', line 140
def self.from_hash(o)
node = self.new(o)
node.from_hash(o)
node
end
|
.json_create(o) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/megam/core/request.rb', line 123
def self.json_create(o)
node = new(o)
node.id(o["id"]) if o.has_key?("id")
node.cat_id(o["cat_id"]) if o.has_key?("cat_id")
node.name(o["name"]) if o.has_key?("name")
node.cattype(o["cattype"]) if o.has_key?("cattype")
node.action(o["action"]) if o.has_key?("action")
node.category(o["category"]) if o.has_key?("category")
node.created_at(o["created_at"]) if o.has_key?("created_at")
node.some_msg[:code] = o["code"] if o.has_key?("code")
node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
node.some_msg[:links] = o["links"] if o.has_key?("links")
node
end
|
.list(params) ⇒ Object
174
175
176
177
|
# File 'lib/megam/core/request.rb', line 174
def self.list(params)
prede = self.new(params)
prede.megam_rest.get_request(n_name)
end
|
.show(params) ⇒ Object
169
170
171
172
|
# File 'lib/megam/core/request.rb', line 169
def self.show(params)
prede = self.new(params)
prede.megam_rest.get_requests
end
|
Instance Method Details
#action(arg = nil) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/megam/core/request.rb', line 51
def action(arg=nil)
if arg != nil
@action = arg
else
@action
end
end
|
#cat_id(arg = nil) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/megam/core/request.rb', line 28
def cat_id(arg=nil)
if arg != nil
@cat_id = arg
else
@cat_id
end
end
|
#category(arg = nil) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/megam/core/request.rb', line 60
def category(arg=nil)
if arg != nil
@category = arg
else
@category
end
end
|
#cattype(arg = nil) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/megam/core/request.rb', line 43
def cattype(arg=nil)
if arg != nil
@cattype = arg
else
@cattype
end
end
|
#create ⇒ Object
Create the node via the REST API
164
165
166
|
# File 'lib/megam/core/request.rb', line 164
def create
megam_rest.post_request(to_hash)
end
|
#created_at(arg = nil) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/megam/core/request.rb', line 69
def created_at(arg=nil)
if arg != nil
@created_at = arg
else
@created_at
end
end
|
#error? ⇒ Boolean
85
86
87
|
# File 'lib/megam/core/request.rb', line 85
def error?
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end
|
#for_json ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/megam/core/request.rb', line 109
def for_json
result = {
"id" => id,
"cat_id" => cat_id,
"name" => name,
"cattype" => cattype,
"action" => action,
"category" => category,
"created_at" => created_at
}
result
end
|
#from_hash(o) ⇒ Object
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/megam/core/request.rb', line 146
def from_hash(o)
@id = o[:id] if o.has_key?(:id)
@cat_id = o[:cat_id] if o.has_key?(:cat_id)
@name = o[:name] if o.has_key?(:name)
@cattype = o[:cattype] if o.has_key?(:cattype)
@action = o[:action] if o.has_key?(:action)
@category = o[:category] if o.has_key?(:category)
@created_at = o[:created_at] if o.has_key?(:created_at)
self
end
|
#id(arg = nil) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/megam/core/request.rb', line 20
def id(arg=nil)
if arg != nil
@id = arg
else
@id
end
end
|
#name(arg = nil) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/megam/core/request.rb', line 36
def name(arg=nil)
if arg != nil
@name = arg
else
@name
end
end
|
#request ⇒ Object
15
16
17
|
# File 'lib/megam/core/request.rb', line 15
def request
self
end
|
#some_msg(arg = nil) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/megam/core/request.rb', line 77
def some_msg(arg=nil)
if arg != nil
@some_msg = arg
else
@some_msg
end
end
|
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/megam/core/request.rb', line 90
def to_hash
index_hash = Hash.new
index_hash["json_claz"] = self.class.name
index_hash["id"] = id
index_hash["cat_id"] = cat_id
index_hash["name"] = name
index_hash["cattype"] = cattype
index_hash["action"] = action
index_hash["category"] = category
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.
105
106
107
|
# File 'lib/megam/core/request.rb', line 105
def to_json(*a)
for_json.to_json(*a)
end
|