Class: Megam::MarketPlace
- Defined in:
- lib/megam/core/marketplace.rb
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
- .json_create(o) ⇒ Object
- .list(params) ⇒ Object
-
.show(params) ⇒ Object
Load a account by email_p.
Instance Method Summary collapse
- #catalog(arg = nil) ⇒ Object
- #cattype(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the marketplace app 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) ⇒ MarketPlace
constructor
A new instance of MarketPlace.
- #market_place ⇒ Object
- #name(arg = nil) ⇒ Object
- #plans(arg = nil) ⇒ Object
- #predef(arg = nil) ⇒ Object
- #some_msg(arg = nil) ⇒ Object
- #status(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) ⇒ MarketPlace
Returns a new instance of MarketPlace.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/megam/core/marketplace.rb', line 20 def initialize(email=nil, api_key=nil) @id = nil @name = nil @catalog = {} @plans=nil @cattype =nil @predef =nil @some_msg = {} @status = nil @created_at = nil super(email, api_key) end |
Class Method Details
.create(params) ⇒ Object
195 196 197 198 |
# File 'lib/megam/core/marketplace.rb', line 195 def self.create(params) acct = from_hash(params, params["email"], params["api_key"]) acct.create end |
.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
177 178 179 180 181 |
# File 'lib/megam/core/marketplace.rb', line 177 def self.from_hash(o,tmp_email=nil, tmp_api_key=nil) app = self.new(tmp_email, tmp_api_key) app.from_hash(o) app end |
.json_create(o) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/megam/core/marketplace.rb', line 152 def self.json_create(o) app = new app.id(o["id"]) if o.has_key?("id") app.name(o["name"]) if o.has_key?("name") ct = o["catalog"] app.catalog[:logo] = ct["logo"] if ct && ct.has_key?("logo") app.catalog[:category] = ct["category"] if ct && ct.has_key?("category") app.catalog[:description] = ct["description"] if ct && ct.has_key?("description") app.plans(o["plans"]) if o.has_key?("plans") app.cattype(o["cattype"]) if o.has_key?("cattype") app.predef(o["predef"]) if o.has_key?("predef") app.status(o["status"]) if o.has_key?("status") app.created_at(o["created_at"]) if o.has_key?("created_at") #success or error app.some_msg[:code] = o["code"] if o.has_key?("code") app.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") app.some_msg[:msg]= o["msg"] if o.has_key?("msg") app.some_msg[:links] = o["links"] if o.has_key?("links") app end |
.list(params) ⇒ Object
211 212 213 214 |
# File 'lib/megam/core/marketplace.rb', line 211 def self.list(params) app = self.new(params["email"], params["api_key"]) app.megam_rest.get_marketplaceapps end |
.show(params) ⇒ Object
Load a account by email_p
206 207 208 209 |
# File 'lib/megam/core/marketplace.rb', line 206 def self.show(params) app = self.new(params["email"], params["api_key"]) app.megam_rest.get_marketplaceapp(params["id"]) end |
Instance Method Details
#catalog(arg = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/megam/core/marketplace.rb', line 46 def catalog(arg=nil) if arg != nil @catalog = arg else @catalog end end |
#cattype(arg = nil) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/megam/core/marketplace.rb', line 80 def cattype(arg=nil) if arg != nil @cattype = arg else @cattype end end |
#create ⇒ Object
Create the marketplace app via the REST API
201 202 203 |
# File 'lib/megam/core/marketplace.rb', line 201 def create megam_rest.post_marketplaceapp(to_hash) end |
#created_at(arg = nil) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/megam/core/marketplace.rb', line 96 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
112 113 114 |
# File 'lib/megam/core/marketplace.rb', line 112 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/megam/core/marketplace.rb', line 138 def for_json result = { "id" => id, "name" => name, "catalog" => catalog, "plans" => plans, "cattype" => cattype, "predef" => predef, "status" => status, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/megam/core/marketplace.rb', line 183 def from_hash(o) @name = o["name"] if o.has_key?("name") @id = o["id"] if o.has_key?("id") @catalog = o["catalog"] if o.has_key?("catalog") @plans = o["plans"] if o.has_key?("plans") @cattype = o["cattype"] if o.has_key?("cattype") @predef = o["predef"] if o.has_key?("predef") @status = o["status"] if o.has_key?("status") @created_at = o["created_at"] if o.has_key?("created_at") self end |
#id(arg = nil) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/megam/core/marketplace.rb', line 54 def id(arg=nil) if arg != nil @id = arg else @id end end |
#market_place ⇒ Object
33 34 35 |
# File 'lib/megam/core/marketplace.rb', line 33 def market_place self end |
#name(arg = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/megam/core/marketplace.rb', line 38 def name(arg=nil) if arg != nil @name = arg else @name end end |
#plans(arg = nil) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/megam/core/marketplace.rb', line 63 def plans(arg=nil) if arg != nil @plans = arg else @plans end end |
#predef(arg = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/megam/core/marketplace.rb', line 72 def predef(arg=nil) if arg != nil @predef = arg else @predef end end |
#some_msg(arg = nil) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/megam/core/marketplace.rb', line 104 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#status(arg = nil) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/megam/core/marketplace.rb', line 88 def status(arg=nil) if arg != nil @status = arg else @status end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/megam/core/marketplace.rb', line 117 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["name"] = name index_hash["catalog"] = catalog index_hash["plans"] = plans index_hash["cattype"] = cattype index_hash["predef"] = predef index_hash["status"] = status 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.
134 135 136 |
# File 'lib/megam/core/marketplace.rb', line 134 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
216 217 218 219 |
# File 'lib/megam/core/marketplace.rb', line 216 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |