Class: Megam::MarketPlace

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/marketplace.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ MarketPlace

Returns a new instance of MarketPlace.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/core/marketplace.rb', line 3

def initialize(o)
    @id = nil
    @provided_by = nil
    @cattype = nil
    @catorder = nil
    @status = nil
    @flavor = nil
    @image = nil
    @url = nil
    @envs = []
    @options = []
    @inputs = []
    @outputs = []
    @acl_policies = []
    @plans = []
    @created_at = nil
    @updated_at = nil
    @some_msg = {}
    super(o)
end

Class Method Details

.create(params) ⇒ Object



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

def self.create(params)
    acct = from_hash(params)
    acct.create
end

.from_hash(o) ⇒ Object



246
247
248
249
250
# File 'lib/megam/core/marketplace.rb', line 246

def self.from_hash(o)
    app = new(o)
    app.from_hash(o)
    app
end

.json_create(o) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/megam/core/marketplace.rb', line 220

def self.json_create(o)
    app = new({})
    app.id(o['id']) if o.key?('id')
    app.provided_by(o['provided_by']) if o.key?('provided_by')
    app.cattype(o['cattype']) if o.key?('cattype')
    app.flavor(o['flavor']) if o.key?('flavor')
    app.image(o['image']) if o.key?('image')
    app.catorder(o['catorder']) if o.key?('catorder')
    app.url(o['url']) if o.key?('url')
    app.envs(o['envs']) if o.key?('envs')
    app.options(o['options']) if o.key?('options')
    app.plans(o['plans']) if o.key?('plans')
    app.created_at(o['created_at']) if o.key?('created_at')
    app.updated_at(o['updated_at']) if o.key?('updated_at')
    app.inputs(o['inputs']) if o.key?('inputs')
    app.outputs(o['outputs']) if o.key?('outputs')
    app.status(o['status']) if o.key?('status')
    app.acl_policies(o['acl_policies']) if o.key?('acl_policies')
    #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



288
289
290
291
# File 'lib/megam/core/marketplace.rb', line 288

def self.list(params)
    app = new(params)
    app.megam_rest.get_marketplaceapps
end

.list_flavor(params) ⇒ Object



298
299
300
301
# File 'lib/megam/core/marketplace.rb', line 298

def self.list_flavor(params)
    app = new(params)
    app.megam_rest.get_marketplaceflavor(params['flavor'])
end

.list_provider(params) ⇒ Object



293
294
295
296
# File 'lib/megam/core/marketplace.rb', line 293

def self.list_provider(params)
    app = new(params)
    app.megam_rest.get_marketplaceprovider(params['provider'])
end

.show(params) ⇒ Object

Load a account by email_p



283
284
285
286
# File 'lib/megam/core/marketplace.rb', line 283

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

Instance Method Details

#acl_policies(arg = []) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/megam/core/marketplace.rb', line 132

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

#catorder(arg = nil) ⇒ Object



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

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

#cattype(arg = nil) ⇒ Object



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

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

#createObject

Create the marketplace app via the REST API



278
279
280
# File 'lib/megam/core/marketplace.rb', line 278

def create
    megam_rest.post_marketplaceapp(to_hash)
end

#created_at(arg = nil) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/megam/core/marketplace.rb', line 140

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

#envs(arg = []) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/megam/core/marketplace.rb', line 164

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

#flavor(arg = nil) ⇒ Object



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

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

#for_jsonObject



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/megam/core/marketplace.rb', line 198

def for_json
    result = {
        'id' => id,
        'provided_by' => provided_by,
        'cattype' => cattype,
        'flavor' => flavor,
        'image' => image,
        'catorder' => catorder,
        'url' => url,
        'envs' => envs,
        'options' => options,
        'plans' => plans,
        'created_at' => created_at,
        'updated_at' => updated_at,
        'status' => status,
        'inputs' => inputs,
        'outputs' => outputs,
        'acl_policies' => acl_policies
    }
    result
end

#from_hash(o) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/megam/core/marketplace.rb', line 252

def from_hash(o)
    @provided_by    = o['provided_by'] if o.key?('provided_by')
    @id             = o['id'] if o.key?('id')
    @cattype        = o['cattype'] if o.key?('cattype')
    @flavor         = o['flavor'] if o.key?('flavor')
    @image          = o['image'] if o.key?('image')
    @catorder       = o['catorder'] if o.key?('catorder')
    @url            = o['url'] if o.key?('url')
    @envs           = o['envs'] if o.key?('envs')
    @options        = o['options'] if o.key?('options')
    @plans          = o['plans'] if o.key?('plans')
    @created_at     = o['created_at'] if o.key?('created_at')
    @updated_at     = o['updated_at'] if o.key?('updated_at')
    @status         = o['status'] if o.key?('status')
    @inputs         = o['inputs'] if o.key?('inputs')
    @outputs        = o['outputs'] if o.key?('outputs')
    @acl_policies   = o['acl_policies'] if o.key?('acl_policies')
    self
end

#id(arg = nil) ⇒ Object



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

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

#image(arg = nil) ⇒ Object



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

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

#inputs(arg = []) ⇒ Object



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

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

#market_placeObject



24
25
26
# File 'lib/megam/core/marketplace.rb', line 24

def market_place
    self
end

#options(arg = []) ⇒ Object



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

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

#outputs(arg = []) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/megam/core/marketplace.rb', line 116

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

#plans(arg = []) ⇒ Object



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

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

#provided_by(arg = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/megam/core/marketplace.rb', line 28

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

#some_msg(arg = nil) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/megam/core/marketplace.rb', line 156

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

#status(arg = []) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/megam/core/marketplace.rb', line 124

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

#to_hashObject

Transform the ruby obj -> to a Hash



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/megam/core/marketplace.rb', line 169

def to_hash
    index_hash = {}
    index_hash['json_claz'] = self.class.name
    index_hash['id'] = id
    index_hash['provided_by'] = provided_by
    index_hash['cattype'] = cattype
    index_hash['flavor'] = flavor
    index_hash['image'] = image
    index_hash['catorder'] = catorder
    index_hash['url'] = url
    index_hash['envs'] = envs
    index_hash['options'] = options
    index_hash['plans'] = plans
    index_hash['created_at'] = created_at
    index_hash['updated_at'] = updated_at
    index_hash['status'] = status
    index_hash['inputs'] = inputs
    index_hash['outputs'] = outputs
    index_hash['acl_policies'] = acl_policies
    index_hash["some_msg"] = some_msg
    index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



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

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

#to_sObject



303
304
305
306
# File 'lib/megam/core/marketplace.rb', line 303

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

#updated_at(arg = nil) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/megam/core/marketplace.rb', line 148

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

#url(arg = nil) ⇒ Object



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

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