megam_api 0.92 → 0.93

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,7 @@ module Megam
26
26
  end
27
27
 
28
28
  email nil
29
+ password nil
29
30
  api_key nil
30
31
 
31
32
  # Set these to enable SSL authentication / mutual-authentication
@@ -17,28 +17,29 @@ require 'hashie'
17
17
 
18
18
  module Megam
19
19
  class MarketPlace < Megam::ServerAPI
20
- def initialize(email = nil, api_key = nil, host = nil)
20
+ def initialize(o)
21
21
  @id = nil
22
- @name = nil
22
+ @settings_name = nil
23
23
  @cattype = nil
24
- @order = nil
24
+ @flavor = nil
25
25
  @image = nil
26
+ @catorder = nil
26
27
  @url = nil
27
28
  @envs = []
28
29
  @plans = nil
29
30
  @created_at = nil
30
- super(email, api_key, host)
31
+ super(o)
31
32
  end
32
33
 
33
34
  def market_place
34
35
  self
35
36
  end
36
37
 
37
- def name(arg = nil)
38
+ def settings_name(arg = nil)
38
39
  if !arg.nil?
39
- @name = arg
40
+ @settings_name = arg
40
41
  else
41
- @name
42
+ @settings_name
42
43
  end
43
44
  end
44
45
 
@@ -66,11 +67,19 @@ module Megam
66
67
  end
67
68
  end
68
69
 
69
- def order(arg = nil)
70
+ def flavor(arg = nil)
70
71
  if !arg.nil?
71
- @order = arg
72
+ @flavor = arg
72
73
  else
73
- @order
74
+ @flavor
75
+ end
76
+ end
77
+
78
+ def catorder(arg = nil)
79
+ if !arg.nil?
80
+ @catorder = arg
81
+ else
82
+ @catorder
74
83
  end
75
84
  end
76
85
 
@@ -124,10 +133,11 @@ module Megam
124
133
  index_hash = {}
125
134
  index_hash['json_claz'] = self.class.name
126
135
  index_hash['id'] = id
127
- index_hash['name'] = name
136
+ index_hash['settings_name'] = settings_name
128
137
  index_hash['cattype'] = cattype
129
- index_hash['order'] = order
138
+ index_hash['flavor'] = flavor
130
139
  index_hash['image'] = image
140
+ index_hash['catorder'] = catorder
131
141
  index_hash['url'] = url
132
142
  index_hash['envs'] = envs
133
143
  index_hash['plans'] = plans
@@ -144,10 +154,11 @@ module Megam
144
154
  def for_json
145
155
  result = {
146
156
  'id' => id,
147
- 'name' => name,
157
+ 'settings_name' => settings_name,
148
158
  'cattype' => cattype,
149
- 'order' => order,
159
+ 'flavor' => flavor,
150
160
  'image' => image,
161
+ 'catorder' => catorder,
151
162
  'url' => url,
152
163
  'envs' => envs,
153
164
  'plans' => plans,
@@ -157,12 +168,13 @@ module Megam
157
168
  end
158
169
 
159
170
  def self.json_create(o)
160
- app = new
171
+ app = new({})
161
172
  app.id(o['id']) if o.key?('id')
162
- app.name(o['name']) if o.key?('name')
173
+ app.settings_name(o['settings_name']) if o.key?('settings_name')
163
174
  app.cattype(o['cattype']) if o.key?('cattype')
164
- app.order(o['order']) if o.key?('order')
175
+ app.flavor(o['flavor']) if o.key?('flavor')
165
176
  app.image(o['image']) if o.key?('image')
177
+ app.catorder(o['catorder']) if o.key?('catorder')
166
178
  app.url(o['url']) if o.key?('url')
167
179
  app.envs(o['envs']) if o.key?('envs')
168
180
  app.plans(o['plans']) if o.key?('plans')
@@ -171,18 +183,19 @@ module Megam
171
183
  app
172
184
  end
173
185
 
174
- def self.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil)
175
- app = new(tmp_email, tmp_api_key, tmp_host)
186
+ def self.from_hash(o)
187
+ app = new(o)
176
188
  app.from_hash(o)
177
189
  app
178
190
  end
179
191
 
180
192
  def from_hash(o)
181
- @name = o['name'] if o.key?('name')
193
+ @settings_name = o['settings_name'] if o.key?('settings_name')
182
194
  @id = o['id'] if o.key?('id')
183
195
  @cattype = o['cattype'] if o.key?('cattype')
184
- @order = o['order'] if o.key?('order')
196
+ @flavor = o['flavor'] if o.key?('flavor')
185
197
  @image = o['image'] if o.key?('image')
198
+ @catorder = o['catorder'] if o.key?('catorder')
186
199
  @url = o['url'] if o.key?('url')
187
200
  @envs = o['envs'] if o.key?('envs')
188
201
  @plans = o['plans'] if o.key?('plans')
@@ -191,7 +204,7 @@ module Megam
191
204
  end
192
205
 
193
206
  def self.create(params)
194
- acct = from_hash(params, params['email'], params['api_key'], params['host'])
207
+ acct = from_hash(params)
195
208
  acct.create
196
209
  end
197
210
 
@@ -202,12 +215,12 @@ module Megam
202
215
 
203
216
  # Load a account by email_p
204
217
  def self.show(params)
205
- app = new(params['email'], params['api_key'], params['host'])
218
+ app = new(params)
206
219
  app.megam_rest.get_marketplaceapp(params['id'])
207
220
  end
208
221
 
209
222
  def self.list(params)
210
- app = new(params['email'], params['api_key'], params['host'])
223
+ app = new(params)
211
224
  app.megam_rest.get_marketplaceapps
212
225
  end
213
226
 
@@ -17,7 +17,6 @@ module Megam
17
17
  class MarketPlaceCollection
18
18
  include Enumerable
19
19
 
20
-
21
20
  attr_reader :iterator
22
21
  def initialize
23
22
  @apps = Array.new
@@ -36,14 +35,14 @@ module Megam
36
35
  def []=(index, arg)
37
36
  is_megam_app(arg)
38
37
  @apps[index] = arg
39
- @apps_by_name[arg.name] = index
38
+ @apps_by_name[arg.flavor] = index
40
39
  end
41
40
 
42
41
  def <<(*args)
43
42
  args.flatten.each do |a|
44
43
  is_megam_app(a)
45
44
  @apps << a
46
- @apps_by_name[a.name] = @apps.length - 1
45
+ @apps_by_name[a.flavor] = @apps.length - 1
47
46
  end
48
47
  self
49
48
  end
@@ -62,11 +61,11 @@ module Megam
62
61
  @apps_by_name.each_key do |key|
63
62
  @apps_by_name[key] += 1 if @apps_by_name[key] > @insert_after_idx
64
63
  end
65
- @apps_by_name[app.name] = @insert_after_idx + 1
64
+ @apps_by_name[app.flavor] = @insert_after_idx + 1
66
65
  @insert_after_idx += 1
67
66
  else
68
67
  @apps << app
69
- @apps_by_name[app.name] = @apps.length - 1
68
+ @apps_by_name[app.flavor] = @apps.length - 1
70
69
  end
71
70
  end
72
71
 
@@ -89,7 +88,7 @@ module Megam
89
88
  def lookup(app)
90
89
  lookup_by = nil
91
90
  if app.kind_of?(Megam::MarketPlace)
92
- lookup_by = app.name
91
+ lookup_by = app.flavor
93
92
  elsif app.kind_of?(String)
94
93
  lookup_by = app
95
94
  else
@@ -101,12 +100,12 @@ module Megam
101
100
  end
102
101
  @apps[res]
103
102
  end
104
-
103
+
105
104
  # Transform the ruby obj -> to a Hash
106
105
  def to_hash
107
106
  index_hash = Hash.new
108
107
  self.each do |app|
109
- index_hash[app.name] = app.to_s
108
+ index_hash[app.flavor] = app.to_s
110
109
  end
111
110
  index_hash
112
111
  end
@@ -131,8 +130,8 @@ module Megam
131
130
 
132
131
  private
133
132
 
134
-
135
-
133
+
134
+
136
135
  def is_megam_app(arg)
137
136
  unless arg.kind_of?(Megam::MarketPlace)
138
137
  raise ArgumentError, "Members must be Megam::MarketPlace's"
@@ -16,13 +16,13 @@
16
16
 
17
17
  module Megam
18
18
  class Organizations < Megam::ServerAPI
19
- def initialize(email=nil, api_key=nil, host=nil)
19
+ def initialize(o)
20
20
  @id = nil
21
21
  @name = nil
22
22
  @accounts_id = nil
23
23
  @related_orgs = []
24
24
  @created_at = nil
25
- super(email, api_key, host)
25
+ super(o)
26
26
  end
27
27
 
28
28
  def organization
@@ -53,14 +53,13 @@ module Megam
53
53
  end
54
54
  end
55
55
 
56
-
57
- def related_orgs(arg=[])
58
- if arg != []
59
- @related_orgs = arg
60
- else
61
- @related_orgs
62
- end
63
- end
56
+ def related_orgs(arg=[])
57
+ if arg != []
58
+ @related_orgs = arg
59
+ else
60
+ @related_orgs
61
+ end
62
+ end
64
63
 
65
64
  def created_at(arg=nil)
66
65
  if arg != nil
@@ -99,7 +98,7 @@ module Megam
99
98
 
100
99
  # Create a Megam::Organization from JSON (used by the backgroud job workers)
101
100
  def self.json_create(o)
102
- org = new
101
+ org = new({})
103
102
  org.id(o["id"]) if o.has_key?("id")
104
103
  org.name(o["name"]) if o.has_key?("name")
105
104
  org.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
@@ -109,7 +108,7 @@ module Megam
109
108
  end
110
109
 
111
110
  def self.from_hash(o)
112
- org = self.new(o[:email], o[:api_key], o[:host])
111
+ org = self.new(o)
113
112
  org.from_hash(o)
114
113
  org
115
114
  end
@@ -135,15 +134,14 @@ module Megam
135
134
  end
136
135
 
137
136
  def self.update(o)
138
- org = from_hash(o)
139
- org.update
140
- end
141
-
142
- # Create the node via the REST API
143
- def update
144
- megam_rest.update_organization(to_hash)
145
- end
137
+ org = from_hash(o)
138
+ org.update
139
+ end
146
140
 
141
+ # Create the node via the REST API
142
+ def update
143
+ megam_rest.update_organization(to_hash)
144
+ end
147
145
 
148
146
  def self.list(o)
149
147
  org = from_hash(o)
@@ -22,16 +22,19 @@ module Megam
22
22
  attr_reader :email
23
23
  attr_reader :api_key
24
24
  attr_reader :host
25
-
25
+ attr_reader :password
26
+ attr_reader :org_id
26
27
 
27
28
  # Create a Megam REST object. The supplied email and api_key is used as the base for
28
29
  # all subsequent requests. For example, when initialized with an email, api_key url
29
30
  # https://api.megam.io, a call to +get+ with 'accounts' will make an
30
31
  # HTTP GET request to https://api.megam.io/accounts using the email, api_key
31
- def initialize(email=nil, api_key=nil, host=nil)
32
- @email = email
33
- @api_key = api_key
34
- @host = host
32
+ def initialize(o)
33
+ @email = o[:email]
34
+ @api_key = o[:api_key] || nil
35
+ @host = o[:host]
36
+ @password = o[:password] || nil
37
+ @org_id = o[:org_id]
35
38
  end
36
39
 
37
40
  # Build a megam api client
@@ -39,7 +42,7 @@ module Megam
39
42
  # === Parameters
40
43
  # api:: The Megam::API client
41
44
  def megam_rest
42
- options = { :email =>email || Megam::Config[:email], :api_key => api_key || Megam::Config[:api_key], :host => host || Megam::Config[:host]}
45
+ options = { :email => email || Megam::Config[:email], :api_key => api_key || Megam::Config[:api_key], :org_id => org_id || Megam::Config[:org_id], :password => password || Megam::Config[:password], :host => host || Megam::Config[:host]}
43
46
  Megam::API.new(options)
44
47
  end
45
48
 
@@ -15,14 +15,15 @@
15
15
  #
16
16
  module Megam
17
17
  class SshKey < Megam::ServerAPI
18
- def initialize(email=nil, api_key=nil, host=nil)
18
+ def initialize(o)
19
19
  @id = nil
20
20
  @name = nil
21
- @accounts_id = nil
22
- @path=nil
21
+ @org_id = nil
22
+ @privatekey=nil
23
+ @publickey=nil
23
24
  @created_at = nil
24
25
  @some_msg = {}
25
- super(email, api_key, host)
26
+ super(o)
26
27
  end
27
28
 
28
29
  def sshkey
@@ -45,22 +46,31 @@ module Megam
45
46
  end
46
47
  end
47
48
 
48
- def accounts_id(arg=nil)
49
+ def org_id(arg=nil)
49
50
  if arg != nil
50
- @accounts_id= arg
51
+ @org_id= arg
51
52
  else
52
- @accounts_id
53
+ @org_id
53
54
  end
54
55
  end
55
56
 
56
- def path(arg=nil)
57
+ def privatekey(arg=nil)
57
58
  if arg != nil
58
- @path= arg
59
+ @privatekey = arg
59
60
  else
60
- @path
61
+ @privatekey
61
62
  end
62
63
  end
63
64
 
65
+ def publickey(arg=nil)
66
+ if arg != nil
67
+ @publickey = arg
68
+ else
69
+ @publikey
70
+ end
71
+ end
72
+
73
+
64
74
  def created_at(arg=nil)
65
75
  if arg != nil
66
76
  @created_at = arg
@@ -87,8 +97,9 @@ module Megam
87
97
  index_hash["json_claz"] = self.class.name
88
98
  index_hash["id"] = id
89
99
  index_hash["name"] = name
90
- index_hash["accounts_id"] = accounts_id
91
- index_hash["path"] = path
100
+ index_hash["org_id"] = org_id
101
+ index_hash["privatekey"] = privatekey
102
+ index_hash["publickey"] = publickey
92
103
  index_hash["created_at"] = created_at
93
104
  index_hash
94
105
  end
@@ -103,8 +114,9 @@ module Megam
103
114
  result = {
104
115
  "id" => id,
105
116
  "name" => name,
106
- "accounts_id" => accounts_id,
107
- "path" => path,
117
+ "org_id" => org_id,
118
+ "privatekey" => privatekey,
119
+ "publickey" => publickey,
108
120
  "created_at" => created_at
109
121
  }
110
122
  result
@@ -112,10 +124,11 @@ module Megam
112
124
 
113
125
  #
114
126
  def self.json_create(o)
115
- sshKey = new
127
+ sshKey = new({})
116
128
  sshKey.id(o["id"]) if o.has_key?("id")
117
129
  sshKey.name(o["name"]) if o.has_key?("name")
118
- sshKey.path(o["path"]) if o.has_key?("path")
130
+ sshKey.privatekey(o["privatekey"]) if o.has_key?("privatekey")
131
+ sshKey.publickey(o["publickey"]) if o.has_key?("publickey")
119
132
  sshKey.created_at(o["created_at"]) if o.has_key?("created_at")
120
133
  #success or error
121
134
  sshKey.some_msg[:code] = o["code"] if o.has_key?("code")
@@ -125,8 +138,8 @@ module Megam
125
138
  sshKey
126
139
  end
127
140
 
128
- def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
129
- sshKey = self.new(tmp_email, tmp_api_key, tmp_host)
141
+ def self.from_hash(o)
142
+ sshKey = self.new(o)
130
143
  sshKey.from_hash(o)
131
144
  sshKey
132
145
  end
@@ -134,13 +147,15 @@ module Megam
134
147
  def from_hash(o)
135
148
  @id = o[:id] if o.has_key?(:id)
136
149
  @name = o[:name] if o.has_key?(:name)
137
- @path = o[:path] if o.has_key?(:path)
150
+ @org_id = o[:org_id] if o.has_key?(:org_id)
151
+ @privatekey = o[:privatekey] if o.has_key?(:privatekey)
152
+ @publickey = o[:publickey] if o.has_key?(:publickey)
138
153
  @created_at = o[:created_at] if o.has_key?(:created_at)
139
154
  self
140
155
  end
141
156
 
142
157
  def self.create(params)
143
- acct = from_hash(params, params["email"], params["api_key"], params["host"])
158
+ acct = from_hash(params)
144
159
  acct.create
145
160
  end
146
161
 
@@ -153,14 +168,14 @@ module Megam
153
168
  # returns a sshkeysCollection
154
169
  # don't return self. check if the Megam::SshKeyCollection is returned.
155
170
  def self.list(params)
156
- sshKey = self.new(params["email"], params["api_key"], params["host"])
171
+ sshKey = self.new(params)
157
172
  sshKey.megam_rest.get_sshkeys
158
173
  end
159
174
 
160
175
  # Show a particular sshKey by name,
161
176
  # Megam::SshKey
162
177
  def self.show(params)
163
- pre = self.new(params["email"], params["api_key"], params["host"])
178
+ pre = self.new(params)
164
179
  pre.megam_rest.get_sshkey(params["name"])
165
180
  end
166
181