Class: Megam::CatRequests
- Defined in:
- lib/megam/core/cat_requests.rb
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(o) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
- .json_create(o) ⇒ Object
Instance Method Summary collapse
- #action(arg = nil) ⇒ Object
- #cat_id(arg = nil) ⇒ Object
- #cat_request ⇒ Object
- #cattype(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the node via the REST API.
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(email = nil, api_key = nil) ⇒ CatRequests
constructor
A new instance of CatRequests.
- #name(arg = nil) ⇒ Object
- #some_msg(arg = nil) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
Methods inherited from ServerAPI
Constructor Details
#initialize(email = nil, api_key = nil) ⇒ CatRequests
Returns a new instance of CatRequests.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/megam/core/cat_requests.rb', line 19 def initialize(email=nil, api_key=nil) @id = nil @cat_id = nil @cattype = nil @name = nil @action = nil @some_msg = {} @created_at = nil super(email, api_key) end |
Class Method Details
.create(o) ⇒ Object
163 164 165 166 |
# File 'lib/megam/core/cat_requests.rb', line 163 def self.create(o) acct = from_hash(o, o["email"], o["api_key"]) acct.create end |
.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
146 147 148 149 150 |
# File 'lib/megam/core/cat_requests.rb', line 146 def self.from_hash(o,tmp_email=nil, tmp_api_key=nil) node = self.new(tmp_email, tmp_api_key) node.from_hash(o) node end |
.json_create(o) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/megam/core/cat_requests.rb', line 130 def self.json_create(o) node = new node.id(o["id"]) if o.has_key?("id") node.cat_id(o["cat_id"]) if o.has_key?("cat_id") node.cattype(o["cattype"]) if o.has_key?("cattype") node.name(o["name"]) if o.has_key?("name") node.action(o["action"]) if o.has_key?("action") node.created_at(o["created_at"]) if o.has_key?("created_at") #success or error 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 |
Instance Method Details
#action(arg = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/megam/core/cat_requests.rb', line 69 def action(arg=nil) if arg != nil @action = arg else @action end end |
#cat_id(arg = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/megam/core/cat_requests.rb', line 43 def cat_id(arg=nil) if arg != nil @cat_id = arg else @cat_id end end |
#cat_request ⇒ Object
30 31 32 |
# File 'lib/megam/core/cat_requests.rb', line 30 def cat_request self end |
#cattype(arg = nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/megam/core/cat_requests.rb', line 52 def cattype(arg=nil) if arg != nil @cattype = arg else @cattype end end |
#create ⇒ Object
Create the node via the REST API
169 170 171 |
# File 'lib/megam/core/cat_requests.rb', line 169 def create megam_rest.post_catrequest(to_hash) end |
#created_at(arg = nil) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/megam/core/cat_requests.rb', line 78 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
94 95 96 |
# File 'lib/megam/core/cat_requests.rb', line 94 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/megam/core/cat_requests.rb', line 117 def for_json result = { "id" => id, "cat_id" => cat_id, "cattype" => cattype, "name" => name, "action" => action, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/megam/core/cat_requests.rb', line 152 def from_hash(o) @id = o[:id] if o.has_key?(:id) @cat_id = o[:cat_id] if o.has_key?(:cat_id) @cattype = o[:cattype] if o.has_key?(:cattype) @name = o[:name] if o.has_key?(:name) @action = o[:action] if o.has_key?(:action) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/megam/core/cat_requests.rb', line 35 def id(arg=nil) if arg != nil @id = arg else @id end end |
#name(arg = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/megam/core/cat_requests.rb', line 61 def name(arg=nil) if arg != nil @name = arg else @name end end |
#some_msg(arg = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/megam/core/cat_requests.rb', line 86 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
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/megam/core/cat_requests.rb', line 99 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["cattype"] = cattype index_hash["name"] = name index_hash["action"] = action 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.
113 114 115 |
# File 'lib/megam/core/cat_requests.rb', line 113 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
174 175 176 |
# File 'lib/megam/core/cat_requests.rb', line 174 def to_s Megam::Stuff.styled_hash(to_hash) end |