Class: Megam::MarketPlace

Inherits:
ServerAPI
  • Object
show all
Defined in:
lib/megam/core/marketplace.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email = nil, api_key = nil, host = nil) ⇒ 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, host = nil)
  @id = nil
  @name = nil
  @cattype = nil
  @order = nil
  @image = nil
  @url = nil
  @envs = []
  @plans = nil
  @created_at = nil
  super(email, api_key, host)
end

Class Method Details

.create(params) ⇒ Object



193
194
195
196
# File 'lib/megam/core/marketplace.rb', line 193

def self.create(params)
  acct = from_hash(params, params['email'], params['api_key'], params['host'])
  acct.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object



174
175
176
177
178
# File 'lib/megam/core/marketplace.rb', line 174

def self.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil)
  app = new(tmp_email, tmp_api_key, tmp_host)
  app.from_hash(o)
  app
end

.json_create(o) ⇒ Object



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

def self.json_create(o)
  app = new
  app.id(o['id']) if o.key?('id')
  app.name(o['name']) if o.key?('name')
  app.cattype(o['cattype']) if o.key?('cattype')
  app.order(o['order']) if o.key?('order')
  app.image(o['image']) if o.key?('image')
  app.url(o['url']) if o.key?('url')
  app.envs(o['envs']) if o.key?('envs')
  app.plans(o['plans']) if o.key?('plans')
  app.created_at(o['created_at']) if o.key?('created_at')

  app
end

.list(params) ⇒ Object



209
210
211
212
# File 'lib/megam/core/marketplace.rb', line 209

def self.list(params)
  app = new(params['email'], params['api_key'], params['host'])
  app.megam_rest.get_marketplaceapps
end

.show(params) ⇒ Object

Load a account by email_p



204
205
206
207
# File 'lib/megam/core/marketplace.rb', line 204

def self.show(params)
  app = new(params['email'], params['api_key'], params['host'])
  app.megam_rest.get_marketplaceapp(params['id'])
end

Instance Method Details

#cattype(arg = nil) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/megam/core/marketplace.rb', line 61

def cattype(arg = nil)
  if !arg.nil?
    @cattype = arg
  else
    @cattype
  end
end

#createObject

Create the marketplace app via the REST API



199
200
201
# File 'lib/megam/core/marketplace.rb', line 199

def create
  megam_rest.post_marketplaceapp(to_hash)
end

#created_at(arg = nil) ⇒ Object



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

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

#envs(arg = []) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/megam/core/marketplace.rb', line 93

def envs(arg = [])
  if arg != []
    @envs = arg
  else
    @envs
  end
end

#error?Boolean



118
119
120
# File 'lib/megam/core/marketplace.rb', line 118

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

#for_jsonObject



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

def for_json
  result = {
    'id' => id,
    'name' => name,
    'cattype' => cattype,
    'order' => order,
    'image' => image,
    'url' => url,
    'envs' => envs,
    'plans' => plans,
    'created_at' => created_at
  }
  result
end

#from_hash(o) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/megam/core/marketplace.rb', line 180

def from_hash(o)
  @name           = o['name'] if o.key?('name')
  @id             = o['id'] if o.key?('id')
  @cattype        = o['cattype'] if o.key?('cattype')
  @order          = o['order'] if o.key?('order')
  @image          = o['image'] if o.key?('image')
  @url            = o['url'] if o.key?('url')
  @envs           = o['envs'] if o.key?('envs')
  @plans          = o['plans'] if o.key?('plans')
  @created_at     = o['created_at'] if o.key?('created_at')
  self
end

#id(arg = nil) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/megam/core/marketplace.rb', line 45

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

#image(arg = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/megam/core/marketplace.rb', line 77

def image(arg = nil)
  if !arg.nil?
    @image = arg
  else
    @image
  end
end

#market_placeObject



33
34
35
# File 'lib/megam/core/marketplace.rb', line 33

def market_place
  self
end

#name(arg = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/megam/core/marketplace.rb', line 37

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

#order(arg = nil) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/megam/core/marketplace.rb', line 69

def order(arg = nil)
  if !arg.nil?
    @order = arg
  else
    @order
  end
end

#plans(arg = nil) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/megam/core/marketplace.rb', line 53

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

#some_msg(arg = nil) ⇒ Object



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

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



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/megam/core/marketplace.rb', line 123

def to_hash
  index_hash = {}
  index_hash['json_claz'] = self.class.name
  index_hash['id'] = id
  index_hash['name'] = name
  index_hash['cattype'] = cattype
  index_hash['order'] = order
  index_hash['image'] = image
  index_hash['url'] = url
  index_hash['envs'] = envs
  index_hash['plans'] = plans
  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.



140
141
142
# File 'lib/megam/core/marketplace.rb', line 140

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

#to_sObject



214
215
216
217
# File 'lib/megam/core/marketplace.rb', line 214

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

#url(arg = nil) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/megam/core/marketplace.rb', line 85

def url(arg = nil)
  if !arg.nil?
    @url = arg
  else
    @url
  end
end