Class: Megam::MarketPlace

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

Returns a new instance of MarketPlace.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/megam/core/marketplace.rb', line 20

def initialize(email=nil, api_key=nil)
  @id = nil
  @name = nil
  @appdetails = {}      
  @pricetype = nil
  @features={}
  @plan={}
  @applinks={}
  @attach =nil
  @predefnode=nil
  @some_msg = {}      
  @approved = nil      
  @created_at = nil
  super(email, api_key)
end

Class Method Details

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



251
252
253
254
# File 'lib/megam/core/marketplace.rb', line 251

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



230
231
232
233
234
# File 'lib/megam/core/marketplace.rb', line 230

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



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/megam/core/marketplace.rb', line 183

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")
  app.(o["logo"]) if o.has_key?("logo")
  app.catagory(o["catagory"]) if o.has_key?("catagory")
  app.pricetype(o["pricetype"]) if o.has_key?("pricetype")   
  app.attach(o["attach"]) if o.has_key?("attach")
  app.predefnode(o["predefnode"]) if o.has_key?("predefnode")
  app.approved(o["approved"]) if o.has_key?("approved")
  app.created_at(o["created_at"]) if o.has_key?("created_at")
  #requests
  oq = o["features"]
  app.features[:feature1] = oq["feature1"] if oq && oq.has_key?("feature1")
  app.features[:feature2] = oq["feature2"] if oq && oq.has_key?("feature2")
  app.features[:feature3] = oq["feature3"] if oq && oq.has_key?("feature3")
  app.features[:feature4] = oq["feature4"] if oq && oq.has_key?("feature4")

  oa = o["appdetails"]
  app.appdetails[:logo] = oa["logo"] if oa && oa.has_key?("logo")
  app.appdetails[:category] = oa["category"] if oa && oa.has_key?("category")
  app.appdetails[:version] = oa["version"] if oa && oa.has_key?("version")
  app.appdetails[:description] = oa["description"] if oa && oa.has_key?("description")      

  op = o["plan"]
  app.plan[:price] = op["price"] if op && op.has_key?("price")
  app.plan[:description] = op["description"] if op && op.has_key?("description")
  app.plan[:plantype]= op["plantype"] if op && op.has_key?("plantype")    
  
  ol = o["applinks"]
  app.applinks[:free_support] = ol["free_support"] if ol && ol.has_key?("free_support")
  app.applinks[:paid_support] = ol["paid_support"] if ol && ol.has_key?("paid_support")
  app.applinks[:home_link] = ol["home_link"] if ol && ol.has_key?("home_link")
  app.applinks[:info_link] = ol["info_link"] if ol && ol.has_key?("info_link")
  app.applinks[:content_link] = ol["content_link"] if ol && ol.has_key?("content_link")
  app.applinks[:wiki_link] = ol["wiki_link"] if ol && ol.has_key?("wiki_link")
  app.applinks[:source_link] = ol["source_link"] if ol && ol.has_key?("source_link")
  
  #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(tmp_email = nil, tmp_api_key = nil) ⇒ Object



267
268
269
270
# File 'lib/megam/core/marketplace.rb', line 267

def self.list(tmp_email=nil, tmp_api_key=nil)
  app = self.new(tmp_email, tmp_api_key)
  app.megam_rest.get_marketplaceapps
end

.show(tmp_email = nil, tmp_api_key = nil, name) ⇒ Object

Load a account by email_p



262
263
264
265
# File 'lib/megam/core/marketplace.rb', line 262

def self.show(tmp_email=nil, tmp_api_key=nil, name)
  app = self.new(tmp_email, tmp_api_key)
  app.megam_rest.get_marketplaceapp(name)
end

Instance Method Details

#appdetails(arg = nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/megam/core/marketplace.rb', line 49

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


89
90
91
92
93
94
95
# File 'lib/megam/core/marketplace.rb', line 89

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

#approved(arg = nil) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/megam/core/marketplace.rb', line 113

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

#attach(arg = nil) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/megam/core/marketplace.rb', line 105

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

#createObject

Create the marketplace app via the REST API



257
258
259
# File 'lib/megam/core/marketplace.rb', line 257

def create
  megam_rest.post_marketplaceapp(to_hash)
end

#created_at(arg = nil) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/megam/core/marketplace.rb', line 121

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

#error?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/megam/core/marketplace.rb', line 137

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

#features(arg = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/megam/core/marketplace.rb', line 73

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

#for_jsonObject



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

def for_json
  result = {
    "id" => id,
    "name" => name,
    "appdetails" => appdetails,
    "pricetype" => pricetype,
    "features" => features,
    "plan" => plan,
    "applinks" => applinks,
    "attach" => attach,
    "predefnode" => predefnode,
    "approved" => approved,        
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/megam/core/marketplace.rb', line 236

def from_hash(o)
  @name = o["name"] if o.has_key?("name")
  @id        = o["id"] if o.has_key?("id")
  @appdetails    = o["appdetails"] if o.has_key?("appdetails")
  @pricetype    = o["pricetype"] if o.has_key?("pricetype")
  @features    = o["features"] if o.has_key?("features")
  @plan   = o["plan"] if o.has_key?("plan")
  @applinks   = o["applinks"] if o.has_key?("applinks")
  @attach   = o["attach"] if o.has_key?("attach")
  @predefnode   = o["predefnode"] if o.has_key?("predefnode")
  @approved   = o["approved"] if o.has_key?("approved")      
  @created_at        = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/megam/core/marketplace.rb', line 57

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

#market_placeObject



36
37
38
# File 'lib/megam/core/marketplace.rb', line 36

def market_place
  self
end

#name(arg = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/megam/core/marketplace.rb', line 41

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

#plan(arg = nil) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/megam/core/marketplace.rb', line 81

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

#predefnode(arg = nil) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/megam/core/marketplace.rb', line 97

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

#pricetype(arg = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/megam/core/marketplace.rb', line 65

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

#some_msg(arg = nil) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/megam/core/marketplace.rb', line 129

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



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/megam/core/marketplace.rb', line 142

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["appdetails"] = appdetails
  index_hash["pricetype"] = pricetype
  index_hash["features"] = features
  index_hash["plan"] = plan
  index_hash["applinks"] = applinks
  index_hash["attach"] = attach
  index_hash["predefnode"] = predefnode
  index_hash["approved"] = approved      
  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.



162
163
164
# File 'lib/megam/core/marketplace.rb', line 162

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

#to_sObject



272
273
274
275
# File 'lib/megam/core/marketplace.rb', line 272

def to_s
  Megam::Stuff.styled_hash(to_hash)
#"---> Megam::Account:[error=#{error?}]\n"+
end