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

def initialize(o)
    @id = nil
    @settings_name = nil
    @cattype = nil
    @flavor = nil
    @image = nil
    @catorder = nil
    @url = nil
    @envs = []
    @options = []
    @plans = nil
    @created_at = nil
    super(o)
end

Class Method Details

.create(params) ⇒ Object



201
202
203
204
# File 'lib/megam/core/marketplace.rb', line 201

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

.from_hash(o) ⇒ Object



180
181
182
183
184
# File 'lib/megam/core/marketplace.rb', line 180

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

.json_create(o) ⇒ Object



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

def self.json_create(o)
    app = new({})
    app.id(o['id']) if o.key?('id')
    app.settings_name(o['settings_name']) if o.key?('settings_name')
    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
end

.list(params) ⇒ Object



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

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

.show(params) ⇒ Object

Load a account by email_p



212
213
214
215
# File 'lib/megam/core/marketplace.rb', line 212

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

Instance Method Details

#catorder(arg = nil) ⇒ Object



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

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

#cattype(arg = nil) ⇒ Object



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

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

#createObject

Create the marketplace app via the REST API



207
208
209
# File 'lib/megam/core/marketplace.rb', line 207

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



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

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

#error?Boolean

Returns:

  • (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

#flavor(arg = nil) ⇒ Object



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

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

#for_jsonObject



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

def for_json
    result = {
        'id' => id,
        'settings_name' => settings_name,
        'cattype' => cattype,
        'flavor' => flavor,
        'image' => image,
        'catorder' => catorder,
        'url' => url,
        'envs' => envs,
        'options' => options,
        'plans' => plans,
        'created_at' => created_at
    }
    result
end

#from_hash(o) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/megam/core/marketplace.rb', line 186

def from_hash(o)
    @settings_name  = o['settings_name'] if o.key?('settings_name')
    @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')
    self
end

#id(arg = nil) ⇒ Object



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

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

#image(arg = nil) ⇒ Object



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

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

#market_placeObject



18
19
20
# File 'lib/megam/core/marketplace.rb', line 18

def market_place
    self
end

#options(arg = []) ⇒ Object



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

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

#plans(arg = nil) ⇒ Object



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

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

#settings_name(arg = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/megam/core/marketplace.rb', line 22

def settings_name(arg = nil)
    if !arg.nil?
        @settings_name = arg
    else
        @settings_name
    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
137
138
# 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['settings_name'] = settings_name
    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
end

#to_json(*a) ⇒ Object

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



142
143
144
# File 'lib/megam/core/marketplace.rb', line 142

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

#to_sObject



222
223
224
225
# File 'lib/megam/core/marketplace.rb', line 222

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

#url(arg = nil) ⇒ Object



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

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