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
# File 'lib/megam/core/marketplace.rb', line 20

def initialize(email=nil, api_key=nil)
  @id = nil
  @name = nil
  @appdetails = {}
  @features={}
  @plans=nil
  @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



238
239
240
241
# File 'lib/megam/core/marketplace.rb', line 238

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



218
219
220
221
222
# File 'lib/megam/core/marketplace.rb', line 218

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



172
173
174
175
176
177
178
179
180
181
182
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
# File 'lib/megam/core/marketplace.rb', line 172

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.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")
  app.plans(o["plans"]) if o.has_key?("plans")
  #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[: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



254
255
256
257
# File 'lib/megam/core/marketplace.rb', line 254

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



249
250
251
252
# File 'lib/megam/core/marketplace.rb', line 249

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



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

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


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

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

#approved(arg = nil) ⇒ Object



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

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

#attach(arg = nil) ⇒ Object



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

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

#createObject

Create the marketplace app via the REST API



244
245
246
# File 'lib/megam/core/marketplace.rb', line 244

def create
  megam_rest.post_marketplaceapp(to_hash)
end

#created_at(arg = nil) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/megam/core/marketplace.rb', line 128

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

#features(arg = nil) ⇒ Object



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

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

#for_jsonObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/megam/core/marketplace.rb', line 156

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

#from_hash(o) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/megam/core/marketplace.rb', line 224

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")
  @features    = o["features"] if o.has_key?("features")
  @plans   = o["plans"] if o.has_key?("plans")
  @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



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

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

#market_placeObject



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

def market_place
  self
end

#name(arg = nil) ⇒ Object



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

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

#plans(arg = nil) ⇒ Object



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

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

#predefnode(arg = nil) ⇒ Object



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

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

#some_msg(arg = nil) ⇒ Object



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

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



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/megam/core/marketplace.rb', line 133

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["features"] = features
  index_hash["plans"] = plans
  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.



152
153
154
# File 'lib/megam/core/marketplace.rb', line 152

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

#to_sObject



259
260
261
262
# File 'lib/megam/core/marketplace.rb', line 259

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