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 ReportsCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@reports = Array.new
|
|
8
|
+
@reports_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_reports
|
|
13
|
+
@reports
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@reports[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_reports(arg)
|
|
22
|
+
@reports[index] = arg
|
|
23
|
+
@reports_by_name[arg.id] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_events(a)
|
|
29
|
+
@reports << a
|
|
30
|
+
@reports_by_name[a.id] = @reports.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(reports)
|
|
39
|
+
is_megam_reports(reports)
|
|
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
|
+
@reports.insert(@insert_after_idx + 1, reports)
|
|
45
|
+
# update name -> location mappings and register new node
|
|
46
|
+
@reports_by_name.each_key do |key|
|
|
47
|
+
@reports_by_name[key] += 1 if @reports_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@reports_by_name[reports.id] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@reports << reports
|
|
53
|
+
@reports_by_name[reports.id] = @reports.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@reports.each do |reports|
|
|
59
|
+
yield reports
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@reports.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@reports.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(reports)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if events.kind_of?(Megam::Reports)
|
|
76
|
+
lookup_by = reports.id
|
|
77
|
+
elsif reports.kind_of?(String)
|
|
78
|
+
lookup_by = reports
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::Reports or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res = @reports_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
|
+
@reports[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@reports.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 |reports_list|
|
|
104
|
+
reports_array = reports_list.kind_of?(Array) ? reports_list : [ reports_list ]
|
|
105
|
+
reports_array.each do |reports|
|
|
106
|
+
collection.insert(reports)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
collection
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def is_megam_reports(arg)
|
|
115
|
+
unless arg.kind_of?(Megam::Reports)
|
|
116
|
+
raise ArgumentError, "Members must be Megam::Reports's"
|
|
117
|
+
end
|
|
118
|
+
true
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class Request < Megam::RestAdapter
|
|
3
|
+
def initialize(params)
|
|
4
|
+
@id = nil
|
|
5
|
+
@account_id = nil
|
|
6
|
+
@cat_id = nil
|
|
7
|
+
@name = nil
|
|
8
|
+
@cattype = nil
|
|
9
|
+
@action = nil
|
|
10
|
+
@category = nil
|
|
11
|
+
@some_msg = {}
|
|
12
|
+
@created_at = nil
|
|
13
|
+
super(params)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def request
|
|
17
|
+
self
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def id(arg=nil)
|
|
22
|
+
if arg != nil
|
|
23
|
+
@id = arg
|
|
24
|
+
else
|
|
25
|
+
@id
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def account_id(arg=nil)
|
|
30
|
+
if arg != nil
|
|
31
|
+
@account_id = arg
|
|
32
|
+
else
|
|
33
|
+
@account_id
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def cat_id(arg=nil)
|
|
38
|
+
if arg != nil
|
|
39
|
+
@cat_id = arg
|
|
40
|
+
else
|
|
41
|
+
@cat_id
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def name(arg=nil)
|
|
46
|
+
if arg != nil
|
|
47
|
+
@name = arg
|
|
48
|
+
else
|
|
49
|
+
@name
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
def cattype(arg=nil)
|
|
53
|
+
if arg != nil
|
|
54
|
+
@cattype = arg
|
|
55
|
+
else
|
|
56
|
+
@cattype
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def action(arg=nil)
|
|
61
|
+
if arg != nil
|
|
62
|
+
@action = arg
|
|
63
|
+
else
|
|
64
|
+
@action
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def category(arg=nil)
|
|
70
|
+
if arg != nil
|
|
71
|
+
@category = arg
|
|
72
|
+
else
|
|
73
|
+
@category
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def created_at(arg=nil)
|
|
79
|
+
if arg != nil
|
|
80
|
+
@created_at = arg
|
|
81
|
+
else
|
|
82
|
+
@created_at
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def some_msg(arg=nil)
|
|
87
|
+
if arg != nil
|
|
88
|
+
@some_msg = arg
|
|
89
|
+
else
|
|
90
|
+
@some_msg
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def error?
|
|
95
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Transform the ruby obj -> to a Hash
|
|
99
|
+
def to_hash
|
|
100
|
+
index_hash = Hash.new
|
|
101
|
+
index_hash["json_claz"] = self.class.name
|
|
102
|
+
index_hash["id"] = id
|
|
103
|
+
index_hash["account_id"] = account_id
|
|
104
|
+
index_hash["cat_id"] = cat_id
|
|
105
|
+
index_hash["name"] = name
|
|
106
|
+
index_hash["cattype"] = cattype
|
|
107
|
+
index_hash["action"] = action
|
|
108
|
+
index_hash["category"] = category
|
|
109
|
+
index_hash["created_at"] = created_at
|
|
110
|
+
index_hash
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Serialize this object as a hash: called from JsonCompat.
|
|
114
|
+
# Verify if this called from JsonCompat during testing.
|
|
115
|
+
def to_json(*a)
|
|
116
|
+
for_json.to_json(*a)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def for_json
|
|
120
|
+
result = {
|
|
121
|
+
"id" => id,
|
|
122
|
+
"account_id" => account_id,
|
|
123
|
+
"cat_id" => cat_id,
|
|
124
|
+
"name" => name,
|
|
125
|
+
"cattype" => cattype,
|
|
126
|
+
"action" => action,
|
|
127
|
+
"category" => category,
|
|
128
|
+
"created_at" => created_at
|
|
129
|
+
}
|
|
130
|
+
result
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
#
|
|
134
|
+
def self.json_create(o)
|
|
135
|
+
node = new(o)
|
|
136
|
+
node.id(o["id"]) if o.has_key?("id")
|
|
137
|
+
node.account_id(o["account_id"]) if o.has_key?("account_id")
|
|
138
|
+
node.cat_id(o["cat_id"]) if o.has_key?("cat_id")
|
|
139
|
+
node.name(o["name"]) if o.has_key?("name")
|
|
140
|
+
node.cattype(o["cattype"]) if o.has_key?("cattype")
|
|
141
|
+
node.action(o["action"]) if o.has_key?("action")
|
|
142
|
+
node.category(o["category"]) if o.has_key?("category")
|
|
143
|
+
node.created_at(o["created_at"]) if o.has_key?("created_at")
|
|
144
|
+
#success or error
|
|
145
|
+
node.some_msg[:code] = o["code"] if o.has_key?("code")
|
|
146
|
+
node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
|
147
|
+
node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
|
148
|
+
node.some_msg[:links] = o["links"] if o.has_key?("links")
|
|
149
|
+
node
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def self.from_hash(o)
|
|
153
|
+
node = self.new(o)
|
|
154
|
+
node.from_hash(o)
|
|
155
|
+
node
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def from_hash(o)
|
|
159
|
+
@id = o[:id] if o.has_key?(:id)
|
|
160
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
|
161
|
+
@cat_id = o[:cat_id] if o.has_key?(:cat_id)
|
|
162
|
+
@name = o[:name] if o.has_key?(:name)
|
|
163
|
+
@cattype = o[:cattype] if o.has_key?(:cattype)
|
|
164
|
+
@action = o[:action] if o.has_key?(:action)
|
|
165
|
+
@category = o[:category] if o.has_key?(:category)
|
|
166
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
167
|
+
self
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def self.create(params)
|
|
172
|
+
acct = from_hash(params)
|
|
173
|
+
acct.create
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Create the node via the REST API
|
|
177
|
+
def create
|
|
178
|
+
megam_rest.post_request(to_hash)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def self.show(params)
|
|
183
|
+
prede = self.new(params)
|
|
184
|
+
prede.megam_rest.get_requests
|
|
185
|
+
end
|
|
186
|
+
#have to check list
|
|
187
|
+
def self.list(params)
|
|
188
|
+
prede = self.new(params)
|
|
189
|
+
prede.megam_rest.get_request(n_name)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def to_s
|
|
193
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
end
|
|
197
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class RequestCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@requests = Array.new
|
|
8
|
+
@requests_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_requests
|
|
13
|
+
@requests
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@requests[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_request(arg)
|
|
22
|
+
@requests[index] = arg
|
|
23
|
+
@requests_by_name[arg.node_name] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_request(a)
|
|
29
|
+
@requests << a
|
|
30
|
+
@requests_by_name[a.node_name] = @requests.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(request)
|
|
39
|
+
is_megam_request(request)
|
|
40
|
+
if @insert_after_idx
|
|
41
|
+
# in the middle of executing a run, so any requests inserted now should
|
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
|
43
|
+
# request
|
|
44
|
+
@requests.insert(@insert_after_idx + 1, request)
|
|
45
|
+
# update name -> location mappings and register new request
|
|
46
|
+
@requests_by_name.each_key do |key|
|
|
47
|
+
@requests_by_name[key] += 1 if @requests_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@requests_by_name[request.node_name] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@requests << request
|
|
53
|
+
@requests_by_name[request.node_name] = @requests.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@requests.each do |request|
|
|
59
|
+
yield request
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@requests.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@requests.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(request)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if request.kind_of?(Megam::Request)
|
|
76
|
+
lookup_by = request.node_name
|
|
77
|
+
elsif request.kind_of?(String)
|
|
78
|
+
lookup_by = request
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::Request or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res = @requests_by_name[lookup_by]
|
|
83
|
+
unless res
|
|
84
|
+
raise ArgumentError, "Cannot find a request matching #{lookup_by} (did you define it first?)"
|
|
85
|
+
end
|
|
86
|
+
@requests[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@requests.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 |requests_list|
|
|
104
|
+
requests_array = requests_list.kind_of?(Array) ? requests_list : [ requests_list ]
|
|
105
|
+
requests_array.each do |request|
|
|
106
|
+
collection.insert(request)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
collection
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def is_megam_request(arg)
|
|
115
|
+
unless arg.kind_of?(Megam::Request)
|
|
116
|
+
raise ArgumentError, "Members must be Megam::Request's"
|
|
117
|
+
end
|
|
118
|
+
true
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class RestAdapter
|
|
3
|
+
attr_reader :email
|
|
4
|
+
attr_reader :api_key
|
|
5
|
+
attr_reader :host
|
|
6
|
+
# the name :password is used as attr_accessor in accounts,
|
|
7
|
+
# hence we use gpassword
|
|
8
|
+
attr_reader :password_hash
|
|
9
|
+
attr_reader :master_key
|
|
10
|
+
attr_reader :org_id
|
|
11
|
+
attr_reader :headers
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## clean up this module later.
|
|
15
|
+
def initialize(o)
|
|
16
|
+
@email = o[:email]
|
|
17
|
+
@api_key = o[:api_key] || nil
|
|
18
|
+
@master_key = o[:master_key] || nil
|
|
19
|
+
@host = o[:host]
|
|
20
|
+
@password_hash = o[:password_hash] || nil
|
|
21
|
+
@org_id = o[:org_id]
|
|
22
|
+
@headers = o[:headers]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Build a megam api client
|
|
26
|
+
#
|
|
27
|
+
# === Parameters
|
|
28
|
+
# api:: The Megam::API client
|
|
29
|
+
def megam_rest
|
|
30
|
+
options = {
|
|
31
|
+
:email => email,
|
|
32
|
+
:api_key => api_key,
|
|
33
|
+
:org_id => org_id,
|
|
34
|
+
:password_hash => password_hash,
|
|
35
|
+
:master_key => master_key,
|
|
36
|
+
:host => host
|
|
37
|
+
}
|
|
38
|
+
if headers
|
|
39
|
+
options[:headers] = headers
|
|
40
|
+
end
|
|
41
|
+
Megam::API.new(options)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|