megam_api 0.100 → 1.5.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -69
- data/lib/megam/api.rb +15 -37
- data/lib/megam/api/errors.rb +19 -19
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/account.rb +1 -1
- data/lib/megam/core/assemblies.rb +1 -1
- data/lib/megam/core/assemblies_collection.rb +7 -15
- data/lib/megam/core/assembly.rb +1 -1
- data/lib/megam/core/assembly_collection.rb +7 -15
- data/lib/megam/core/balances.rb +1 -1
- data/lib/megam/core/balances_collection.rb +8 -16
- data/lib/megam/core/billedhistories.rb +1 -1
- data/lib/megam/core/billedhistories_collection.rb +7 -15
- data/lib/megam/core/components.rb +1 -1
- data/lib/megam/core/components_collection.rb +103 -110
- data/lib/megam/core/domain_collection.rb +102 -109
- data/lib/megam/core/domains.rb +1 -1
- data/lib/megam/core/error.rb +1 -15
- data/lib/megam/core/json_compat.rb +170 -208
- data/lib/megam/core/marketplace.rb +1 -1
- data/lib/megam/core/marketplace_collection.rb +7 -16
- data/lib/megam/core/organizations.rb +1 -1
- data/lib/megam/core/organizations_collection.rb +8 -40
- data/lib/megam/core/promos.rb +1 -1
- data/lib/megam/core/request.rb +1 -1
- data/lib/megam/core/request_collection.rb +7 -16
- data/lib/megam/core/rest_adapter.rb +54 -0
- data/lib/megam/core/sensors.rb +1 -1
- data/lib/megam/core/sensors_collection.rb +7 -14
- data/lib/megam/core/sshkey.rb +1 -1
- data/lib/megam/core/sshkey_collection.rb +103 -110
- data/lib/megam/core/stuff.rb +2 -34
- data/lib/megam/core/text.rb +1 -0
- data/lib/megam/core/text_formatter.rb +2 -1
- data/megam_api.gemspec +2 -2
- metadata +10 -56
- data/lib/megam/api/availableunits.rb +0 -50
- data/lib/megam/api/billings.rb +0 -50
- data/lib/megam/api/credithistories.rb +0 -50
- data/lib/megam/api/csars.rb +0 -75
- data/lib/megam/api/discounts.rb +0 -50
- data/lib/megam/api/invoices.rb +0 -50
- data/lib/megam/api/login.rb +0 -29
- data/lib/megam/api/subscriptions.rb +0 -50
- data/lib/megam/core/auth.rb +0 -91
- data/lib/megam/core/availableunits.rb +0 -182
- data/lib/megam/core/availableunits_collection.rb +0 -144
- data/lib/megam/core/billings.rb +0 -242
- data/lib/megam/core/billings_collection.rb +0 -144
- data/lib/megam/core/config.rb +0 -41
- data/lib/megam/core/credithistories.rb +0 -191
- data/lib/megam/core/credithistories_collection.rb +0 -144
- data/lib/megam/core/csar.rb +0 -179
- data/lib/megam/core/csar_collection.rb +0 -148
- data/lib/megam/core/discounts.rb +0 -204
- data/lib/megam/core/discounts_collection.rb +0 -164
- data/lib/megam/core/invoices.rb +0 -231
- data/lib/megam/core/invoices_collection.rb +0 -144
- data/lib/megam/core/server_api.rb +0 -52
- data/lib/megam/core/subscriptions.rb +0 -191
- data/lib/megam/core/subscriptions_collection.rb +0 -144
- data/test/test_availableunits.rb +0 -28
- data/test/test_billings.rb +0 -33
- data/test/test_cat_requests.rb +0 -20
- data/test/test_credithistories.rb +0 -29
- data/test/test_csars.rb +0 -22
- data/test/test_discounts.rb +0 -31
- data/test/test_invoices.rb +0 -31
- data/test/test_login.rb +0 -10
- data/test/test_marketplaceaddons.rb +0 -46
- data/test/test_predefclouds.rb +0 -80
- data/test/test_subscriptions.rb +0 -29
data/lib/megam/api/discounts.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Megam
|
17
|
-
class API
|
18
|
-
def get_discounts
|
19
|
-
@options = {:path => '/discounts',:body => ""}.merge(@options)
|
20
|
-
request(
|
21
|
-
:expects => 200,
|
22
|
-
:method => :get,
|
23
|
-
:body => @options[:body]
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
def post_discounts(new_discount)
|
28
|
-
@options = {:path => '/discounts/content',
|
29
|
-
:body => Megam::JSONCompat.to_json(new_discount)}.merge(@options)
|
30
|
-
|
31
|
-
request(
|
32
|
-
:expects => 201,
|
33
|
-
:method => :post,
|
34
|
-
:body => @options[:body]
|
35
|
-
)
|
36
|
-
end
|
37
|
-
def update_discounts(update_discount)
|
38
|
-
@options = {:path => '/discounts/update',
|
39
|
-
:body => Megam::JSONCompat.to_json(update_discount)}.merge(@options)
|
40
|
-
|
41
|
-
request(
|
42
|
-
:expects => 201,
|
43
|
-
:method => :post,
|
44
|
-
:body => @options[:body]
|
45
|
-
)
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/lib/megam/api/invoices.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Megam
|
17
|
-
class API
|
18
|
-
def get_invoices
|
19
|
-
@options = {:path => '/invoices',:body => ""}.merge(@options)
|
20
|
-
|
21
|
-
request(
|
22
|
-
:expects => 200,
|
23
|
-
:method => :get,
|
24
|
-
:body => @options[:body]
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_invoice(id)
|
29
|
-
@options = {:path => "/invoices/#{id}",:body => ""}.merge(@options)
|
30
|
-
|
31
|
-
request(
|
32
|
-
:expects => 200,
|
33
|
-
:method => :get,
|
34
|
-
:body => @options[:body]
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
def post_invoices(new_invoices)
|
39
|
-
@options = {:path => '/invoices/content',
|
40
|
-
:body => Megam::JSONCompat.to_json(new_invoices)}.merge(@options)
|
41
|
-
|
42
|
-
request(
|
43
|
-
:expects => 201,
|
44
|
-
:method => :post,
|
45
|
-
:body => @options[:body]
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/lib/megam/api/login.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Megam
|
17
|
-
class API
|
18
|
-
def post_auth
|
19
|
-
@options = {:path => '/auth', :body => ""}.merge(@options)
|
20
|
-
|
21
|
-
request(
|
22
|
-
:expects => 200,
|
23
|
-
:method => :post,
|
24
|
-
:body => @options[:body]
|
25
|
-
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Megam
|
17
|
-
class API
|
18
|
-
def get_subscriptions
|
19
|
-
@options = {:path => '/subscriptions',:body => ""}.merge(@options)
|
20
|
-
|
21
|
-
request(
|
22
|
-
:expects => 200,
|
23
|
-
:method => :get,
|
24
|
-
:body => @options[:body]
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_subscriptions(id)
|
29
|
-
@options = {:path => "/subscriptions/#{id}",:body => ""}.merge(@options)
|
30
|
-
|
31
|
-
request(
|
32
|
-
:expects => 200,
|
33
|
-
:method => :get,
|
34
|
-
:body => @options[:body]
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
def post_subscriptions(new_subscription)
|
39
|
-
@options = {:path => '/subscriptions/content',
|
40
|
-
:body => Megam::JSONCompat.to_json(new_subscription)}.merge(@options)
|
41
|
-
|
42
|
-
request(
|
43
|
-
:expects => 201,
|
44
|
-
:method => :post,
|
45
|
-
:body => @options[:body]
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/lib/megam/core/auth.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 Megam Systems, Inc.
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Megam
|
17
|
-
class Auth
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@some_msg = {}
|
21
|
-
end
|
22
|
-
|
23
|
-
#used by resque workers and any other background job
|
24
|
-
def auth
|
25
|
-
self
|
26
|
-
end
|
27
|
-
|
28
|
-
def megam_rest
|
29
|
-
Megam::API.new(Megam::Config[:email], Megam::Config[:api_key], Megam::Config[:host])
|
30
|
-
end
|
31
|
-
|
32
|
-
def some_msg(arg=nil)
|
33
|
-
if arg != nil
|
34
|
-
@some_msg = arg
|
35
|
-
else
|
36
|
-
@some_msg
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def error?
|
41
|
-
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
42
|
-
end
|
43
|
-
|
44
|
-
# Transform the ruby obj -> to a Hash
|
45
|
-
def to_hash
|
46
|
-
index_hash = Hash.new
|
47
|
-
index_hash["json_claz"] = self.class.name
|
48
|
-
index_hash["some_msg"] = some_msg
|
49
|
-
index_hash
|
50
|
-
end
|
51
|
-
|
52
|
-
# Serialize this object as a hash: called from JsonCompat.
|
53
|
-
# Verify if this called from JsonCompat during testing.
|
54
|
-
def to_json(*a)
|
55
|
-
for_json.to_json(*a)
|
56
|
-
end
|
57
|
-
|
58
|
-
def for_json
|
59
|
-
result = { }
|
60
|
-
result
|
61
|
-
end
|
62
|
-
|
63
|
-
# Create a Megam::Account from JSON (used by the backgroud job workers)
|
64
|
-
def self.json_create(o)
|
65
|
-
acct = new
|
66
|
-
acct.some_msg[:code] = o["code"] if o.has_key?("code")
|
67
|
-
acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
68
|
-
acct.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
69
|
-
acct.some_msg[:links] = o["links"] if o.has_key?("links")
|
70
|
-
acct
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.from_hash(o)
|
74
|
-
acct = self.new()
|
75
|
-
acct.from_hash(o)
|
76
|
-
acct
|
77
|
-
end
|
78
|
-
|
79
|
-
# just an auth
|
80
|
-
def self.auth
|
81
|
-
megam_rest.post_auth
|
82
|
-
self
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
def to_s
|
87
|
-
Megam::Stuff.styled_hash(to_hash)
|
88
|
-
#"---> Megam::Account:[error=#{error?}]\n"+
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## Copyright 2013-2016 Megam Systems
|
3
|
-
##
|
4
|
-
## Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
## you may not use this file except in compliance with the License.
|
6
|
-
## You may obtain a copy of the License at
|
7
|
-
##
|
8
|
-
## http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
##
|
10
|
-
## Unless required by applicable law or agreed to in writing, software
|
11
|
-
## distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
## See the License for the specific language governing permissions and
|
14
|
-
## limitations under the License.
|
15
|
-
##
|
16
|
-
module Megam
|
17
|
-
class Availableunits < Megam::ServerAPI
|
18
|
-
def initialize(email=nil, api_key=nil, host=nil)
|
19
|
-
@id = nil
|
20
|
-
@name = nil
|
21
|
-
@duration = nil
|
22
|
-
@charges_per_duration = nil
|
23
|
-
@created_at = nil
|
24
|
-
@some_msg = {}
|
25
|
-
super(email, api_key, host)
|
26
|
-
end
|
27
|
-
|
28
|
-
def availableunits
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def id(arg=nil)
|
34
|
-
if arg != nil
|
35
|
-
@id = arg
|
36
|
-
else
|
37
|
-
@id
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def name(arg=nil)
|
42
|
-
if arg != nil
|
43
|
-
@name = arg
|
44
|
-
else
|
45
|
-
@name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def duration(arg=nil)
|
50
|
-
if arg != nil
|
51
|
-
@duration= arg
|
52
|
-
else
|
53
|
-
@duration
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def charges_per_duration(arg=nil)
|
58
|
-
if arg != nil
|
59
|
-
@charges_per_duration = arg
|
60
|
-
else
|
61
|
-
@charges_per_duration
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def created_at(arg=nil)
|
66
|
-
if arg != nil
|
67
|
-
@created_at = arg
|
68
|
-
else
|
69
|
-
@created_at
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def some_msg(arg=nil)
|
74
|
-
if arg != nil
|
75
|
-
@some_msg = arg
|
76
|
-
else
|
77
|
-
@some_msg
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def error?
|
82
|
-
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
83
|
-
end
|
84
|
-
|
85
|
-
# Transform the ruby obj -> to a Hash
|
86
|
-
def to_hash
|
87
|
-
index_hash = Hash.new
|
88
|
-
index_hash["json_claz"] = self.class.name
|
89
|
-
index_hash["id"] = id
|
90
|
-
index_hash["name"] = name
|
91
|
-
index_hash["duration"] = duration
|
92
|
-
index_hash["charges_per_duration"] = charges_per_duration
|
93
|
-
index_hash["created_at"] = created_at
|
94
|
-
index_hash
|
95
|
-
end
|
96
|
-
|
97
|
-
# Serialize this object as a hash: called from JsonCompat.
|
98
|
-
# Verify if this called from JsonCompat during testing.
|
99
|
-
def to_json(*a)
|
100
|
-
for_json.to_json(*a)
|
101
|
-
end
|
102
|
-
|
103
|
-
def for_json
|
104
|
-
result = {
|
105
|
-
"id" => id,
|
106
|
-
"name" => name,
|
107
|
-
"duration" => duration,
|
108
|
-
"charges_per_duration" => charges_per_duration,
|
109
|
-
"created_at" => created_at
|
110
|
-
}
|
111
|
-
result
|
112
|
-
end
|
113
|
-
|
114
|
-
#
|
115
|
-
def self.json_create(o)
|
116
|
-
aunit = new({})
|
117
|
-
aunit.id(o["id"]) if o.has_key?("id")
|
118
|
-
aunit.name(o["name"]) if o.has_key?("name")
|
119
|
-
aunit.duration(o["duration"]) if o.has_key?("duration")
|
120
|
-
aunit.charges_per_duration(o["charges_per_duration"]) if o.has_key?("charges_per_duration")
|
121
|
-
aunit.created_at(o["created_at"]) if o.has_key?("created_at")
|
122
|
-
#success or error
|
123
|
-
aunit.some_msg[:code] = o["code"] if o.has_key?("code")
|
124
|
-
aunit.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
125
|
-
aunit.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
126
|
-
aunit.some_msg[:links] = o["links"] if o.has_key?("links")
|
127
|
-
aunit
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
131
|
-
aunit = self.new(tmp_email, tmp_api_key, tmp_host)
|
132
|
-
aunit.from_hash(o)
|
133
|
-
aunit
|
134
|
-
end
|
135
|
-
|
136
|
-
def from_hash(o)
|
137
|
-
@id = o[:id] if o.has_key?(:id)
|
138
|
-
@name = o[:name] if o.has_key?(:name)
|
139
|
-
@duration = o[:duration] if o.has_key?(:duration)
|
140
|
-
@charges_per_duration = o[:charges_per_duration] if o.has_key?(:charges_per_duration)
|
141
|
-
@created_at = o[:created_at] if o.has_key?(:created_at)
|
142
|
-
self
|
143
|
-
end
|
144
|
-
|
145
|
-
def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host)
|
146
|
-
acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
|
147
|
-
acct.create
|
148
|
-
end
|
149
|
-
|
150
|
-
# Create the predef via the REST API
|
151
|
-
def create
|
152
|
-
megam_rest.post_availableunits(to_hash)
|
153
|
-
end
|
154
|
-
|
155
|
-
# Load all available units -
|
156
|
-
# returns a AvailableUnitsCollection
|
157
|
-
# don't return self. check if the Megam::AvailableUnitsCollection is returned.
|
158
|
-
def self.list(tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
159
|
-
aunit = self.new(tmp_email,tmp_api_key,tmp_host)
|
160
|
-
aunit.megam_rest.get_availableunits
|
161
|
-
end
|
162
|
-
|
163
|
-
# Show a particular available units by name,
|
164
|
-
# Megam::Availables
|
165
|
-
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
166
|
-
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
167
|
-
pre.megam_rest.get_availableunit(p_name)
|
168
|
-
end
|
169
|
-
|
170
|
-
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
171
|
-
pre = self.new(tmp_email,tmp_api_key,tmp_host)
|
172
|
-
pre.megam_rest.delete_availableunit(p_name)
|
173
|
-
end
|
174
|
-
|
175
|
-
def to_s
|
176
|
-
Megam::Stuff.styled_hash(to_hash)
|
177
|
-
#"---> Megam::Account:[error=#{error?}]\n"+
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|