Class: Megam::AppRequest
- Defined in:
- lib/megam/core/app_request.rb
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
- .json_create(o) ⇒ Object
Instance Method Summary collapse
- #action(arg = nil) ⇒ Object
- #app_id(arg = nil) ⇒ Object
- #app_name(arg = nil) ⇒ Object
- #app_request ⇒ 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) ⇒ AppRequest
constructor
A new instance of AppRequest.
- #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) ⇒ AppRequest
Returns a new instance of AppRequest.
18 19 20 21 22 23 24 25 26 |
# File 'lib/megam/core/app_request.rb', line 18 def initialize(email=nil, api_key=nil) @id = nil @app_id = nil @app_name = nil @action = nil @some_msg = {} @created_at = nil super(email, api_key) end |
Class Method Details
.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
147 148 149 150 |
# File 'lib/megam/core/app_request.rb', line 147 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
131 132 133 134 135 |
# File 'lib/megam/core/app_request.rb', line 131 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/megam/core/app_request.rb', line 116 def self.json_create(o) node = new node.id(o["id"]) if o.has_key?("id") node.app_id(o["app_id"]) if o.has_key?("app_id") node.app_name(o["app_name"]) if o.has_key?("app_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
57 58 59 60 61 62 63 |
# File 'lib/megam/core/app_request.rb', line 57 def action(arg=nil) if arg != nil @action = arg else @action end end |
#app_id(arg = nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/megam/core/app_request.rb', line 41 def app_id(arg=nil) if arg != nil @app_id = arg else @app_id end end |
#app_name(arg = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/megam/core/app_request.rb', line 49 def app_name(arg=nil) if arg != nil @app_name = arg else @app_name end end |
#app_request ⇒ Object
28 29 30 |
# File 'lib/megam/core/app_request.rb', line 28 def app_request self end |
#create ⇒ Object
Create the node via the REST API
153 154 155 |
# File 'lib/megam/core/app_request.rb', line 153 def create megam_rest.post_apprequest(to_hash) end |
#created_at(arg = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/megam/core/app_request.rb', line 66 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
82 83 84 |
# File 'lib/megam/core/app_request.rb', line 82 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/megam/core/app_request.rb', line 104 def for_json result = { "id" => id, "app_id" => app_id, "app_name" => app_name, "action" => action, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/megam/core/app_request.rb', line 137 def from_hash(o) @id = o[:id] if o.has_key?(:id) @app_id = o[:app_id] if o.has_key?(:app_id) @app_name = o[:app_name] if o.has_key?(:app_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
33 34 35 36 37 38 39 |
# File 'lib/megam/core/app_request.rb', line 33 def id(arg=nil) if arg != nil @id = arg else @id end end |
#some_msg(arg = nil) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/megam/core/app_request.rb', line 74 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
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/megam/core/app_request.rb', line 87 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["app_id"] = app_id index_hash["app_name"] = app_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.
100 101 102 |
# File 'lib/megam/core/app_request.rb', line 100 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
158 159 160 161 |
# File 'lib/megam/core/app_request.rb', line 158 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |