virtengine_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +10 -0
- data/lib/megam/api.rb +329 -0
- data/lib/megam/api/accounts.rb +96 -0
- data/lib/megam/api/addons.rb +27 -0
- data/lib/megam/api/assemblies.rb +49 -0
- data/lib/megam/api/assembly.rb +56 -0
- data/lib/megam/api/backups.rb +57 -0
- data/lib/megam/api/balances.rb +45 -0
- data/lib/megam/api/billedhistories.rb +35 -0
- data/lib/megam/api/billingtransactions.rb +25 -0
- data/lib/megam/api/components.rb +24 -0
- data/lib/megam/api/credits.rb +34 -0
- data/lib/megam/api/disks.rb +44 -0
- data/lib/megam/api/domains.rb +25 -0
- data/lib/megam/api/errors.rb +29 -0
- data/lib/megam/api/eventsall.rb +36 -0
- data/lib/megam/api/eventsbilling.rb +35 -0
- data/lib/megam/api/eventscontainer.rb +35 -0
- data/lib/megam/api/eventsmarketplace.rb +35 -0
- data/lib/megam/api/eventsstorage.rb +24 -0
- data/lib/megam/api/eventsvm.rb +35 -0
- data/lib/megam/api/flavors.rb +56 -0
- data/lib/megam/api/license.rb +26 -0
- data/lib/megam/api/marketplaces.rb +68 -0
- data/lib/megam/api/organizations.rb +50 -0
- data/lib/megam/api/promos.rb +18 -0
- data/lib/megam/api/quotas.rb +47 -0
- data/lib/megam/api/rawimages.rb +36 -0
- data/lib/megam/api/reports.rb +24 -0
- data/lib/megam/api/requests.rb +36 -0
- data/lib/megam/api/sensors.rb +35 -0
- data/lib/megam/api/snapshots.rb +46 -0
- data/lib/megam/api/sshkeys.rb +35 -0
- data/lib/megam/api/subscriptions.rb +26 -0
- data/lib/megam/api/version.rb +6 -0
- data/lib/megam/core/account.rb +245 -0
- data/lib/megam/core/account_collection.rb +122 -0
- data/lib/megam/core/addons.rb +169 -0
- data/lib/megam/core/addons_collection.rb +121 -0
- data/lib/megam/core/assemblies.rb +191 -0
- data/lib/megam/core/assemblies_collection.rb +122 -0
- data/lib/megam/core/assembly.rb +226 -0
- data/lib/megam/core/assembly_collection.rb +122 -0
- data/lib/megam/core/backups.rb +259 -0
- data/lib/megam/core/backups_collection.rb +122 -0
- data/lib/megam/core/balances.rb +187 -0
- data/lib/megam/core/balances_collection.rb +121 -0
- data/lib/megam/core/billedhistories.rb +190 -0
- data/lib/megam/core/billedhistories_collection.rb +121 -0
- data/lib/megam/core/billingtransactions.rb +214 -0
- data/lib/megam/core/billingtransactions_collection.rb +122 -0
- data/lib/megam/core/components.rb +326 -0
- data/lib/megam/core/components_collection.rb +123 -0
- data/lib/megam/core/credits.rb +146 -0
- data/lib/megam/core/credits_collection.rb +121 -0
- data/lib/megam/core/disks.rb +199 -0
- data/lib/megam/core/disks_collection.rb +122 -0
- data/lib/megam/core/domain_collection.rb +122 -0
- data/lib/megam/core/domains.rb +118 -0
- data/lib/megam/core/error.rb +70 -0
- data/lib/megam/core/eventsall.rb +186 -0
- data/lib/megam/core/eventsall_collection.rb +122 -0
- data/lib/megam/core/eventsbilling.rb +174 -0
- data/lib/megam/core/eventsbilling_collection.rb +122 -0
- data/lib/megam/core/eventscontainer.rb +187 -0
- data/lib/megam/core/eventscontainer_collection.rb +122 -0
- data/lib/megam/core/eventsmarketplace.rb +187 -0
- data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
- data/lib/megam/core/eventsstorage.rb +156 -0
- data/lib/megam/core/eventsstorage_collection.rb +122 -0
- data/lib/megam/core/eventsvm.rb +187 -0
- data/lib/megam/core/eventsvm_collection.rb +122 -0
- data/lib/megam/core/flavors.rb +294 -0
- data/lib/megam/core/flavors_collection.rb +121 -0
- data/lib/megam/core/json_compat.rb +289 -0
- data/lib/megam/core/konipai.rb +42 -0
- data/lib/megam/core/license.rb +101 -0
- data/lib/megam/core/license_collection.rb +122 -0
- data/lib/megam/core/log.rb +19 -0
- data/lib/megam/core/marketplace.rb +308 -0
- data/lib/megam/core/marketplace_collection.rb +123 -0
- data/lib/megam/core/monologger.rb +89 -0
- data/lib/megam/core/organizations.rb +142 -0
- data/lib/megam/core/organizations_collection.rb +121 -0
- data/lib/megam/core/promos.rb +145 -0
- data/lib/megam/core/quotas.rb +215 -0
- data/lib/megam/core/quotas_collection.rb +121 -0
- data/lib/megam/core/rawimages.rb +194 -0
- data/lib/megam/core/rawimages_collection.rb +121 -0
- data/lib/megam/core/reports.rb +176 -0
- data/lib/megam/core/reports_collection.rb +121 -0
- data/lib/megam/core/request.rb +197 -0
- data/lib/megam/core/request_collection.rb +121 -0
- data/lib/megam/core/rest_adapter.rb +44 -0
- data/lib/megam/core/sensors.rb +141 -0
- data/lib/megam/core/sensors_collection.rb +121 -0
- data/lib/megam/core/snapshots.rb +268 -0
- data/lib/megam/core/snapshots_collection.rb +122 -0
- data/lib/megam/core/sshkey.rb +173 -0
- data/lib/megam/core/sshkey_collection.rb +122 -0
- data/lib/megam/core/stuff.rb +22 -0
- data/lib/megam/core/subscriptions.rb +167 -0
- data/lib/megam/core/subscriptions_collection.rb +121 -0
- data/lib/megam/core/text.rb +87 -0
- data/lib/megam/core/text_formatter.rb +64 -0
- data/lib/megam/mixins/assemblies.rb +16 -0
- data/lib/megam/mixins/assembly.rb +59 -0
- data/lib/megam/mixins/common_deployable.rb +78 -0
- data/lib/megam/mixins/components.rb +182 -0
- data/lib/megam/mixins/megam_attributes.rb +30 -0
- data/lib/megam/mixins/outputs.rb +23 -0
- data/lib/megam/mixins/policies.rb +27 -0
- data/lib/megam_api.rb +1 -0
- data/megam_api.gemspec +26 -0
- data/test/mixins/test_assemblies.rb +113 -0
- data/test/mixins/test_assembly.rb +74 -0
- data/test/mixins/test_component.rb +19 -0
- data/test/test_accounts.rb +127 -0
- data/test/test_addons.rb +26 -0
- data/test/test_assemblies.rb +88 -0
- data/test/test_assembly.rb +37 -0
- data/test/test_backups.rb +29 -0
- data/test/test_balances.rb +38 -0
- data/test/test_billedhistories.rb +30 -0
- data/test/test_billingtranscations.rb +35 -0
- data/test/test_components.rb +42 -0
- data/test/test_credits.rb +28 -0
- data/test/test_disks.rb +25 -0
- data/test/test_domains.rb +29 -0
- data/test/test_eventsbilling.rb +30 -0
- data/test/test_eventscontainer.rb +26 -0
- data/test/test_eventsstorage.rb +12 -0
- data/test/test_eventsvm.rb +26 -0
- data/test/test_helper.rb +77 -0
- data/test/test_marketplaces.rb +38 -0
- data/test/test_organizations.rb +45 -0
- data/test/test_promos.rb +11 -0
- data/test/test_quotas.rb +33 -0
- data/test/test_reports.rb +32 -0
- data/test/test_requests.rb +95 -0
- data/test/test_sensors.rb +50 -0
- data/test/test_snapshots.rb +30 -0
- data/test/test_sshkeys.rb +50 -0
- data/test/test_subscriptions.rb +22 -0
- metadata +325 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class FlavorsCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@flavors = Array.new
|
|
8
|
+
@flavors_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_flavors
|
|
13
|
+
@flavors
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@flavors[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_flavors(arg)
|
|
22
|
+
@flavors[index] = arg
|
|
23
|
+
@flavors_by_name[arg.account_id] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_flavors(a)
|
|
29
|
+
@flavors << a
|
|
30
|
+
@flavors_by_name[a.account_id] = @flavors.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(flavors)
|
|
39
|
+
is_megam_flavors(flavors)
|
|
40
|
+
if @insert_after_idx
|
|
41
|
+
# in the middle of executing a run, so any nodes inserted now should
|
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
|
43
|
+
# node
|
|
44
|
+
@flavors.insert(@insert_after_idx + 1, flavors)
|
|
45
|
+
# update name -> location mappings and register new node
|
|
46
|
+
@flavors_by_name.each_key do |key|
|
|
47
|
+
@flavors_by_name[key] += 1 if @flavors_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@flavors_by_name[flavors.account_id] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@flavors << flavors
|
|
53
|
+
@flavors_by_name[flavors.account_id] = @flavors.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@flavors.each do |flavors|
|
|
59
|
+
yield flavors
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@flavors.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@flavors.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(flavors)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if events.kind_of?(Megam::Flavors)
|
|
76
|
+
lookup_by = flavors.account_id
|
|
77
|
+
elsif flavors.kind_of?(String)
|
|
78
|
+
lookup_by = flavors
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::Flavors or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res = @flavors_by_name[lookup_by]
|
|
83
|
+
unless res
|
|
84
|
+
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
|
85
|
+
end
|
|
86
|
+
@flavors[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@flavors.join(", ")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def for_json
|
|
94
|
+
to_a.map { |item| item.to_s }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def to_json(*a)
|
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def self.json_create(o)
|
|
102
|
+
collection = self.new()
|
|
103
|
+
o["results"].each do |flavors_list|
|
|
104
|
+
flavors_array = flavors_list.kind_of?(Array) ? flavors_list : [ flavors_list ]
|
|
105
|
+
flavors_array.each do |flavors|
|
|
106
|
+
collection.insert(flavors)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
collection
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def is_megam_flavors(arg)
|
|
115
|
+
unless arg.kind_of?(Megam::Flavors)
|
|
116
|
+
raise ArgumentError, "Members must be Megam::Flavors's"
|
|
117
|
+
end
|
|
118
|
+
true
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
|
|
2
|
+
# Wrapper class for interacting with JSON.
|
|
3
|
+
require "ffi_yajl"
|
|
4
|
+
# We're requiring this to prevent breaking consumers using Hash.to_json
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
module Megam
|
|
8
|
+
class JSONCompat
|
|
9
|
+
|
|
10
|
+
JSON_MAX_NESTING = 1000
|
|
11
|
+
|
|
12
|
+
JSON_CLAZ = 'json_claz'.freeze
|
|
13
|
+
|
|
14
|
+
MEGAM_ACCOUNT = 'Megam::Account'.freeze
|
|
15
|
+
MEGAM_ACCOUNTCOLLECTION = 'Megam::AccountCollection'.freeze
|
|
16
|
+
MEGAM_ASSEMBLIES = 'Megam::Assemblies'.freeze
|
|
17
|
+
MEGAM_ASSEMBLIESCOLLECTION = 'Megam::AssembliesCollection'.freeze
|
|
18
|
+
MEGAM_ASSEMBLY = 'Megam::Assembly'.freeze
|
|
19
|
+
MEGAM_ASSEMBLYCOLLECTION = 'Megam::AssemblyCollection'.freeze
|
|
20
|
+
MEGAM_BALANCES = 'Megam::Balances'.freeze
|
|
21
|
+
MEGAM_BALANCESCOLLECTION = 'Megam::BalancesCollection'.freeze
|
|
22
|
+
MEGAM_CREDITS = 'Megam::Credits'.freeze
|
|
23
|
+
MEGAM_CREDITSCOLLECTION = 'Megam::CreditsCollection'.freeze
|
|
24
|
+
MEGAM_BILLEDHISTORIES = 'Megam::Billedhistories'.freeze
|
|
25
|
+
MEGAM_BILLEDHISTORIESCOLLECTION = 'Megam::BilledhistoriesCollection'.freeze
|
|
26
|
+
MEGAM_BILLINGTRANSACTIONS = 'Megam::BillingTransactions'.freeze
|
|
27
|
+
MEGAM_BILLINGTRANSACTIONSCOLLECTION = 'Megam::BillingTransactionsCollection'.freeze
|
|
28
|
+
MEGAM_COMPONENTS = 'Megam::Components'.freeze
|
|
29
|
+
MEGAM_COMPONENTSCOLLECTION = 'Megam::ComponentsCollection'.freeze
|
|
30
|
+
MEGAM_DOMAIN = 'Megam::Domains'.freeze
|
|
31
|
+
MEGAM_DOMAINCOLLECTION = 'Megam::DomainsCollection'.freeze
|
|
32
|
+
MEGAM_ERROR = 'Megam::Error'.freeze
|
|
33
|
+
MEGAM_MARKETPLACE = 'Megam::MarketPlace'.freeze
|
|
34
|
+
MEGAM_MARKETPLACECOLLECTION = 'Megam::MarketPlaceCollection'.freeze
|
|
35
|
+
MEGAM_ORGANIZATION = 'Megam::Organizations'.freeze
|
|
36
|
+
MEGAM_ORGANIZATIONSCOLLECTION = 'Megam::OrganizationsCollection'.freeze
|
|
37
|
+
MEGAM_REQUEST = 'Megam::Request'.freeze
|
|
38
|
+
MEGAM_REQUESTCOLLECTION = 'Megam::RequestCollection'.freeze
|
|
39
|
+
MEGAM_SENSORS = 'Megam::Sensors'.freeze
|
|
40
|
+
MEGAM_SENSORSCOLLECTION = 'Megam::SensorsCollection'.freeze
|
|
41
|
+
MEGAM_SNAPSHOTS = 'Megam::Snapshots'.freeze
|
|
42
|
+
MEGAM_SNAPSHOTSCOLLECTION = 'Megam::SnapshotsCollection'.freeze
|
|
43
|
+
MEGAM_BACKUPS = 'Megam::Backups'.freeze
|
|
44
|
+
MEGAM_BACKUPSCOLLECTION = 'Megam::BackupsCollection'.freeze
|
|
45
|
+
MEGAM_DISKS = 'Megam::Disks'.freeze
|
|
46
|
+
MEGAM_DISKSCOLLECTION = 'Megam::DisksCollection'.freeze
|
|
47
|
+
MEGAM_LICENSE = 'Megam::License'.freeze
|
|
48
|
+
MEGAM_LICENSECOLLECTION = 'Megam::LicenseCollection'.freeze
|
|
49
|
+
MEGAM_SSHKEY = 'Megam::SshKey'.freeze
|
|
50
|
+
MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
|
|
51
|
+
MEGAM_EVENTSALL = 'Megam::EventsAll'.freeze
|
|
52
|
+
MEGAM_EVENTSALLCOLLECTION = 'Megam::EventsAllCollection'.freeze
|
|
53
|
+
MEGAM_EVENTSVM = 'Megam::EventsVm'.freeze
|
|
54
|
+
MEGAM_EVENTSVMCOLLECTION = 'Megam::EventsVmCollection'.freeze
|
|
55
|
+
MEGAM_EVENTSCONTAINER = 'Megam::EventsContainer'.freeze
|
|
56
|
+
MEGAM_EVENTSCONTAINERCOLLECTION = 'Megam::EventsContainerCollection'.freeze
|
|
57
|
+
MEGAM_EVENTSMARKETPLACE = 'Megam::EventsMarketplace'.freeze
|
|
58
|
+
MEGAM_EventsMarketplaceCollection = 'Megam::EventsMarketplaceCollection'.freeze
|
|
59
|
+
MEGAM_EVENTSBILLING = 'Megam::EventsBilling'.freeze
|
|
60
|
+
MEGAM_EVENTSBILLINGCOLLECTION = 'Megam::EventsBillingCollection'.freeze
|
|
61
|
+
MEGAM_EVENTSSTORAGE = 'Megam::EventsStorage'.freeze
|
|
62
|
+
MEGAM_EVENTSSTORAGECOLLECTION = 'Megam::EventsStorageCollection'.freeze
|
|
63
|
+
MEGAM_SUBSCRIPTIONS = 'Megam::Subscriptions'.freeze
|
|
64
|
+
MEGAM_SUBSCRIPTIONSCOLLECTION = 'Megam::SubscriptionsCollection'.freeze
|
|
65
|
+
MEGAM_ADDONS = 'Megam::Addons'.freeze
|
|
66
|
+
MEGAM_ADDONSCOLLECTION = 'Megam::AddonsCollection'.freeze
|
|
67
|
+
MEGAM_REPORTS = 'Megam::Reports'.freeze
|
|
68
|
+
MEGAM_REPORTSCOLLECTION = 'Megam::ReportsCollection'.freeze
|
|
69
|
+
MEGAM_QUOTAS = 'Megam::Quotas'.freeze
|
|
70
|
+
MEGAM_QUOTASCOLLECTION = 'Megam::QuotasCollection'.freeze
|
|
71
|
+
MEGAM_FLAVORS = 'Megam::Flavors'.freeze
|
|
72
|
+
MEGAM_FLAVORSCOLLECTION = 'Megam::FlavorsCollection'.freeze
|
|
73
|
+
MEGAM_RAWIMAGES = 'Megam::Rawimages'.freeze
|
|
74
|
+
MEGAM_RAWIMAGESCOLLECTION = 'Megam::RawimagesCollection'.freeze
|
|
75
|
+
MEGAM_PROMOS = 'Megam::Promos'.freeze
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class << self
|
|
79
|
+
# API to use to avoid create_addtions
|
|
80
|
+
def parse(source, opts = {})
|
|
81
|
+
begin
|
|
82
|
+
FFI_Yajl::Parser.parse(source, opts)
|
|
83
|
+
rescue FFI_Yajl::ParseError => e
|
|
84
|
+
raise StandardError, e.message
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Just call the JSON gem's parse method with a modified :max_nesting field
|
|
89
|
+
def from_json(source, opts = {})
|
|
90
|
+
obj = parse(source, opts)
|
|
91
|
+
|
|
92
|
+
# JSON gem requires top level object to be a Hash or Array (otherwise
|
|
93
|
+
# you get the "must contain two octets" error). Yajl doesn't impose the
|
|
94
|
+
# same limitation. For compatibility, we re-impose this condition.
|
|
95
|
+
unless obj.kind_of?(Hash) || obj.kind_of?(Array)
|
|
96
|
+
raise JSON::ParseError, "Top level JSON object must be a Hash or Array. (actual: #{obj.class})"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# The old default in the json gem (which we are mimicing because we
|
|
100
|
+
# sadly rely on this misfeature) is to "create additions" i.e., convert
|
|
101
|
+
# JSON objects into ruby objects. Explicit :create_additions => false
|
|
102
|
+
# is required to turn it off.
|
|
103
|
+
if opts[:create_additions].nil? || opts[:create_additions]
|
|
104
|
+
map_to_rb_obj(obj)
|
|
105
|
+
else
|
|
106
|
+
obj
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Look at an object that's a basic type (from json parse) and convert it
|
|
111
|
+
# to an instance of Chef classes if desired.
|
|
112
|
+
def map_to_rb_obj(json_obj)
|
|
113
|
+
case json_obj
|
|
114
|
+
when Hash
|
|
115
|
+
mapped_hash = map_hash_to_rb_obj(json_obj)
|
|
116
|
+
if json_obj.has_key?(JSON_CLAZ) && (class_to_inflate = class_for_json_class(json_obj[JSON_CLAZ]))
|
|
117
|
+
class_to_inflate.json_create(mapped_hash)
|
|
118
|
+
else
|
|
119
|
+
mapped_hash
|
|
120
|
+
end
|
|
121
|
+
when Array
|
|
122
|
+
json_obj.map { |e| map_to_rb_obj(e) }
|
|
123
|
+
else
|
|
124
|
+
json_obj
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def map_hash_to_rb_obj(json_hash)
|
|
129
|
+
json_hash.each do |key, value|
|
|
130
|
+
json_hash[key] = map_to_rb_obj(value)
|
|
131
|
+
end
|
|
132
|
+
json_hash
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def to_json(obj, opts = nil)
|
|
136
|
+
begin
|
|
137
|
+
FFI_Yajl::Encoder.encode(obj, opts)
|
|
138
|
+
rescue FFI_Yajl::EncodeError => e
|
|
139
|
+
raise JSON::GeneratorError, e.message
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def to_json_pretty(obj, opts = nil)
|
|
145
|
+
opts ||= {}
|
|
146
|
+
options_map = {}
|
|
147
|
+
options_map[:pretty] = true
|
|
148
|
+
options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
|
|
149
|
+
to_json(obj, options_map).chomp
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# Map +JSON_CLAZ+ to a Class object. We use a +case+ instead of a Hash
|
|
154
|
+
# assigned to a constant because otherwise this file could not be loaded
|
|
155
|
+
# until all the constants were defined, which means you'd have to load
|
|
156
|
+
# the world to get json.
|
|
157
|
+
def class_for_json_class(json_class)
|
|
158
|
+
case json_class
|
|
159
|
+
when MEGAM_ERROR
|
|
160
|
+
Megam::Error
|
|
161
|
+
when MEGAM_ACCOUNT
|
|
162
|
+
Megam::Account
|
|
163
|
+
when MEGAM_ACCOUNTCOLLECTION
|
|
164
|
+
Megam::AccountCollection
|
|
165
|
+
when MEGAM_ASSEMBLIES
|
|
166
|
+
Megam::Assemblies
|
|
167
|
+
when MEGAM_ASSEMBLIESCOLLECTION
|
|
168
|
+
Megam::AssembliesCollection
|
|
169
|
+
when MEGAM_ASSEMBLY
|
|
170
|
+
Megam::Assembly
|
|
171
|
+
when MEGAM_ASSEMBLYCOLLECTION
|
|
172
|
+
Megam::AssemblyCollection
|
|
173
|
+
when MEGAM_COMPONENTS
|
|
174
|
+
Megam::Components
|
|
175
|
+
when MEGAM_COMPONENTSCOLLECTION
|
|
176
|
+
Megam::ComponentsCollection
|
|
177
|
+
when MEGAM_REQUEST
|
|
178
|
+
Megam::Request
|
|
179
|
+
when MEGAM_REQUESTCOLLECTION
|
|
180
|
+
Megam::RequestCollection
|
|
181
|
+
when MEGAM_SSHKEY
|
|
182
|
+
Megam::SshKey
|
|
183
|
+
when MEGAM_SSHKEYCOLLECTION
|
|
184
|
+
Megam::SshKeyCollection
|
|
185
|
+
when MEGAM_EVENTSVM
|
|
186
|
+
Megam::EventsVm
|
|
187
|
+
when MEGAM_EVENTSVMCOLLECTION
|
|
188
|
+
Megam::EventsVmCollection
|
|
189
|
+
when MEGAM_EVENTSMARKETPLACE
|
|
190
|
+
Megam::EventsMarketplace
|
|
191
|
+
when MEGAM_EventsMarketplaceCollection
|
|
192
|
+
Megam::EventsMarketplaceCollection
|
|
193
|
+
when MEGAM_LICENSE
|
|
194
|
+
Megam::License
|
|
195
|
+
when MEGAM_LICENSECOLLECTION
|
|
196
|
+
Megam::LicenseCollection
|
|
197
|
+
when MEGAM_FLAVORS
|
|
198
|
+
Megam::Flavors
|
|
199
|
+
when MEGAM_FLAVORSCOLLECTION
|
|
200
|
+
Megam::FlavorsCollection
|
|
201
|
+
when MEGAM_EVENTSALL
|
|
202
|
+
Megam::EventsAll
|
|
203
|
+
when MEGAM_EVENTSALLCOLLECTION
|
|
204
|
+
Megam::EventsAllCollection
|
|
205
|
+
when MEGAM_EVENTSCONTAINER
|
|
206
|
+
Megam::EventsContainer
|
|
207
|
+
when MEGAM_EVENTSCONTAINERCOLLECTION
|
|
208
|
+
Megam::EventsContainerCollection
|
|
209
|
+
when MEGAM_EVENTSBILLING
|
|
210
|
+
Megam::EventsBilling
|
|
211
|
+
when MEGAM_EVENTSBILLINGCOLLECTION
|
|
212
|
+
Megam::EventsBillingCollection
|
|
213
|
+
when MEGAM_EVENTSSTORAGE
|
|
214
|
+
Megam::EventsStorage
|
|
215
|
+
when MEGAM_EVENTSSTORAGECOLLECTION
|
|
216
|
+
Megam::EventsStorageCollection
|
|
217
|
+
when MEGAM_MARKETPLACE
|
|
218
|
+
Megam::MarketPlace
|
|
219
|
+
when MEGAM_MARKETPLACECOLLECTION
|
|
220
|
+
Megam::MarketPlaceCollection
|
|
221
|
+
when MEGAM_ORGANIZATION
|
|
222
|
+
Megam::Organizations
|
|
223
|
+
when MEGAM_ORGANIZATIONSCOLLECTION
|
|
224
|
+
Megam::OrganizationsCollection
|
|
225
|
+
when MEGAM_DOMAIN
|
|
226
|
+
Megam::Domains
|
|
227
|
+
when MEGAM_DOMAINCOLLECTION
|
|
228
|
+
Megam::DomainsCollection
|
|
229
|
+
when MEGAM_SENSORS
|
|
230
|
+
Megam::Sensors
|
|
231
|
+
when MEGAM_SENSORSCOLLECTION
|
|
232
|
+
Megam::SensorsCollection
|
|
233
|
+
when MEGAM_SNAPSHOTS
|
|
234
|
+
Megam::Snapshots
|
|
235
|
+
when MEGAM_SNAPSHOTSCOLLECTION
|
|
236
|
+
Megam::SnapshotsCollection
|
|
237
|
+
when MEGAM_BACKUPS
|
|
238
|
+
Megam::Backups
|
|
239
|
+
when MEGAM_BACKUPSCOLLECTION
|
|
240
|
+
Megam::BackupsCollection
|
|
241
|
+
when MEGAM_BALANCES
|
|
242
|
+
Megam::Balances
|
|
243
|
+
when MEGAM_BALANCESCOLLECTION
|
|
244
|
+
Megam::BalancesCollection
|
|
245
|
+
when MEGAM_CREDITS
|
|
246
|
+
Megam::Credits
|
|
247
|
+
when MEGAM_CREDITSCOLLECTION
|
|
248
|
+
Megam::CreditsCollection
|
|
249
|
+
when MEGAM_BILLEDHISTORIES
|
|
250
|
+
Megam::Billedhistories
|
|
251
|
+
when MEGAM_BILLEDHISTORIESCOLLECTION
|
|
252
|
+
Megam::BilledhistoriesCollection
|
|
253
|
+
when MEGAM_BILLINGTRANSACTIONS
|
|
254
|
+
Megam::Billingtransactions
|
|
255
|
+
when MEGAM_BILLINGTRANSACTIONSCOLLECTION
|
|
256
|
+
Megam::BillingtransactionsCollection
|
|
257
|
+
when MEGAM_SUBSCRIPTIONS
|
|
258
|
+
Megam::Subscriptions
|
|
259
|
+
when MEGAM_SUBSCRIPTIONSCOLLECTION
|
|
260
|
+
Megam::SubscriptionsCollection
|
|
261
|
+
when MEGAM_DISKS
|
|
262
|
+
Megam::Disks
|
|
263
|
+
when MEGAM_DISKSCOLLECTION
|
|
264
|
+
Megam::DisksCollection
|
|
265
|
+
when MEGAM_ADDONS
|
|
266
|
+
Megam::Addons
|
|
267
|
+
when MEGAM_ADDONSCOLLECTION
|
|
268
|
+
Megam::AddonsCollection
|
|
269
|
+
when MEGAM_REPORTS
|
|
270
|
+
Megam::Reports
|
|
271
|
+
when MEGAM_REPORTSCOLLECTION
|
|
272
|
+
Megam::ReportsCollection
|
|
273
|
+
when MEGAM_QUOTAS
|
|
274
|
+
Megam::Quotas
|
|
275
|
+
when MEGAM_QUOTASCOLLECTION
|
|
276
|
+
Megam::QuotasCollection
|
|
277
|
+
when MEGAM_RAWIMAGES
|
|
278
|
+
Megam::Rawimages
|
|
279
|
+
when MEGAM_RAWIMAGESCOLLECTION
|
|
280
|
+
Megam::RawimagesCollection
|
|
281
|
+
when MEGAM_PROMOS
|
|
282
|
+
Megam::Promos
|
|
283
|
+
else
|
|
284
|
+
fail JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class KoniPai
|
|
3
|
+
|
|
4
|
+
def initialize()
|
|
5
|
+
@koni = nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def konipai
|
|
9
|
+
self
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def koni(arg=nil)
|
|
13
|
+
if arg != nil
|
|
14
|
+
@koni = arg
|
|
15
|
+
else
|
|
16
|
+
@koni
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Transform the ruby obj -> to a Hash
|
|
22
|
+
def to_hash
|
|
23
|
+
index_hash = Hash.new
|
|
24
|
+
index_hash["json_claz"] = self.class.name
|
|
25
|
+
index_hash["koni"] = koni
|
|
26
|
+
index_hash
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def self.json_create(o)
|
|
31
|
+
kp = new
|
|
32
|
+
kp.koni(o) if o != null
|
|
33
|
+
kp
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def to_s
|
|
38
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|