azure_mgmt_billing 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,466 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator.
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::ARM::Billing
7
+ #
8
+ # Billing client provides access to billing resources for Azure Web-Direct
9
+ # subscriptions. Other subscription types which were not purchased directly
10
+ # through the Azure web portal are not supported through this preview API.
11
+ #
12
+ class Invoices
13
+ include MsRestAzure
14
+
15
+ #
16
+ # Creates and initializes a new instance of the Invoices class.
17
+ # @param client service class for accessing basic functionality.
18
+ #
19
+ def initialize(client)
20
+ @client = client
21
+ end
22
+
23
+ # @return [BillingManagementClient] reference to the BillingManagementClient
24
+ attr_reader :client
25
+
26
+ #
27
+ # Lists the available invoices for a subscription in reverse chronological
28
+ # order beginning with the most recent invoice. In preview, invoices are
29
+ # available via this API only for invoice periods which end December 1, 2016 or
30
+ # later.
31
+ #
32
+ # @param expand [String] May be used to expand the downloadUrl property within
33
+ # a list of invoices. This enables download links to be generated for multiple
34
+ # invoices at once. By default, downloadURLs are not included when listing
35
+ # invoices.
36
+ # @param filter [String] May be used to filter invoices by
37
+ # invoicePeriodEndDate. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and
38
+ # 'and'. It does not currently support 'ne', 'or', or 'not'.
39
+ # @param skiptoken [String] Skiptoken is only used if a previous operation
40
+ # returned a partial result. If a previous response contains a nextLink
41
+ # element, the value of the nextLink element will include a skiptoken parameter
42
+ # that specifies a starting point to use for subsequent calls.
43
+ # @param top [Integer] May be used to limit the number of results to the most
44
+ # recent N invoices.
45
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
46
+ # will be added to the HTTP request.
47
+ #
48
+ # @return [Array<Invoice>] operation results.
49
+ #
50
+ def list(expand = nil, filter = nil, skiptoken = nil, top = nil, custom_headers = nil)
51
+ first_page = list_as_lazy(expand, filter, skiptoken, top, custom_headers)
52
+ first_page.get_all_items
53
+ end
54
+
55
+ #
56
+ # Lists the available invoices for a subscription in reverse chronological
57
+ # order beginning with the most recent invoice. In preview, invoices are
58
+ # available via this API only for invoice periods which end December 1, 2016 or
59
+ # later.
60
+ #
61
+ # @param expand [String] May be used to expand the downloadUrl property within
62
+ # a list of invoices. This enables download links to be generated for multiple
63
+ # invoices at once. By default, downloadURLs are not included when listing
64
+ # invoices.
65
+ # @param filter [String] May be used to filter invoices by
66
+ # invoicePeriodEndDate. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and
67
+ # 'and'. It does not currently support 'ne', 'or', or 'not'.
68
+ # @param skiptoken [String] Skiptoken is only used if a previous operation
69
+ # returned a partial result. If a previous response contains a nextLink
70
+ # element, the value of the nextLink element will include a skiptoken parameter
71
+ # that specifies a starting point to use for subsequent calls.
72
+ # @param top [Integer] May be used to limit the number of results to the most
73
+ # recent N invoices.
74
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
75
+ # will be added to the HTTP request.
76
+ #
77
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
78
+ #
79
+ def list_with_http_info(expand = nil, filter = nil, skiptoken = nil, top = nil, custom_headers = nil)
80
+ list_async(expand, filter, skiptoken, top, custom_headers).value!
81
+ end
82
+
83
+ #
84
+ # Lists the available invoices for a subscription in reverse chronological
85
+ # order beginning with the most recent invoice. In preview, invoices are
86
+ # available via this API only for invoice periods which end December 1, 2016 or
87
+ # later.
88
+ #
89
+ # @param expand [String] May be used to expand the downloadUrl property within
90
+ # a list of invoices. This enables download links to be generated for multiple
91
+ # invoices at once. By default, downloadURLs are not included when listing
92
+ # invoices.
93
+ # @param filter [String] May be used to filter invoices by
94
+ # invoicePeriodEndDate. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and
95
+ # 'and'. It does not currently support 'ne', 'or', or 'not'.
96
+ # @param skiptoken [String] Skiptoken is only used if a previous operation
97
+ # returned a partial result. If a previous response contains a nextLink
98
+ # element, the value of the nextLink element will include a skiptoken parameter
99
+ # that specifies a starting point to use for subsequent calls.
100
+ # @param top [Integer] May be used to limit the number of results to the most
101
+ # recent N invoices.
102
+ # @param [Hash{String => String}] A hash of custom headers that will be added
103
+ # to the HTTP request.
104
+ #
105
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
106
+ #
107
+ def list_async(expand = nil, filter = nil, skiptoken = nil, top = nil, custom_headers = nil)
108
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
109
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
110
+
111
+
112
+ request_headers = {}
113
+
114
+ # Set Headers
115
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
116
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
117
+ path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Billing/invoices'
118
+
119
+ request_url = @base_url || @client.base_url
120
+
121
+ options = {
122
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
123
+ path_params: {'subscriptionId' => @client.subscription_id},
124
+ query_params: {'api-version' => @client.api_version,'$expand' => expand,'$filter' => filter,'$skiptoken' => skiptoken,'$top' => top},
125
+ headers: request_headers.merge(custom_headers || {}),
126
+ base_url: request_url
127
+ }
128
+ promise = @client.make_request_async(:get, path_template, options)
129
+
130
+ promise = promise.then do |result|
131
+ http_response = result.response
132
+ status_code = http_response.status
133
+ response_content = http_response.body
134
+ unless status_code == 200
135
+ error_model = JSON.load(response_content)
136
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
137
+ end
138
+
139
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
140
+ # Deserialize Response
141
+ if status_code == 200
142
+ begin
143
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
144
+ result_mapper = Azure::ARM::Billing::Models::InvoicesListResult.mapper()
145
+ result.body = @client.deserialize(result_mapper, parsed_response)
146
+ rescue Exception => e
147
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
148
+ end
149
+ end
150
+
151
+ result
152
+ end
153
+
154
+ promise.execute
155
+ end
156
+
157
+ #
158
+ # Gets a named invoice resource. When getting a single invoice, the downloadUrl
159
+ # property is expanded automatically.
160
+ #
161
+ # @param invoice_name [String] The name of an invoice resource.
162
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
163
+ # will be added to the HTTP request.
164
+ #
165
+ # @return [Invoice] operation results.
166
+ #
167
+ def get(invoice_name, custom_headers = nil)
168
+ response = get_async(invoice_name, custom_headers).value!
169
+ response.body unless response.nil?
170
+ end
171
+
172
+ #
173
+ # Gets a named invoice resource. When getting a single invoice, the downloadUrl
174
+ # property is expanded automatically.
175
+ #
176
+ # @param invoice_name [String] The name of an invoice resource.
177
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
178
+ # will be added to the HTTP request.
179
+ #
180
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
181
+ #
182
+ def get_with_http_info(invoice_name, custom_headers = nil)
183
+ get_async(invoice_name, custom_headers).value!
184
+ end
185
+
186
+ #
187
+ # Gets a named invoice resource. When getting a single invoice, the downloadUrl
188
+ # property is expanded automatically.
189
+ #
190
+ # @param invoice_name [String] The name of an invoice resource.
191
+ # @param [Hash{String => String}] A hash of custom headers that will be added
192
+ # to the HTTP request.
193
+ #
194
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
195
+ #
196
+ def get_async(invoice_name, custom_headers = nil)
197
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
198
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
199
+ fail ArgumentError, 'invoice_name is nil' if invoice_name.nil?
200
+
201
+
202
+ request_headers = {}
203
+
204
+ # Set Headers
205
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
206
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
207
+ path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Billing/invoices/{invoiceName}'
208
+
209
+ request_url = @base_url || @client.base_url
210
+
211
+ options = {
212
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
213
+ path_params: {'subscriptionId' => @client.subscription_id,'invoiceName' => invoice_name},
214
+ query_params: {'api-version' => @client.api_version},
215
+ headers: request_headers.merge(custom_headers || {}),
216
+ base_url: request_url
217
+ }
218
+ promise = @client.make_request_async(:get, path_template, options)
219
+
220
+ promise = promise.then do |result|
221
+ http_response = result.response
222
+ status_code = http_response.status
223
+ response_content = http_response.body
224
+ unless status_code == 200
225
+ error_model = JSON.load(response_content)
226
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
227
+ end
228
+
229
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
230
+ # Deserialize Response
231
+ if status_code == 200
232
+ begin
233
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
234
+ result_mapper = Azure::ARM::Billing::Models::Invoice.mapper()
235
+ result.body = @client.deserialize(result_mapper, parsed_response)
236
+ rescue Exception => e
237
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
238
+ end
239
+ end
240
+
241
+ result
242
+ end
243
+
244
+ promise.execute
245
+ end
246
+
247
+ #
248
+ # Gets the most recent invoice. When getting a single invoice, the downloadUrl
249
+ # property is expanded automatically.
250
+ #
251
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
252
+ # will be added to the HTTP request.
253
+ #
254
+ # @return [Invoice] operation results.
255
+ #
256
+ def get_latest(custom_headers = nil)
257
+ response = get_latest_async(custom_headers).value!
258
+ response.body unless response.nil?
259
+ end
260
+
261
+ #
262
+ # Gets the most recent invoice. When getting a single invoice, the downloadUrl
263
+ # property is expanded automatically.
264
+ #
265
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
266
+ # will be added to the HTTP request.
267
+ #
268
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
269
+ #
270
+ def get_latest_with_http_info(custom_headers = nil)
271
+ get_latest_async(custom_headers).value!
272
+ end
273
+
274
+ #
275
+ # Gets the most recent invoice. When getting a single invoice, the downloadUrl
276
+ # property is expanded automatically.
277
+ #
278
+ # @param [Hash{String => String}] A hash of custom headers that will be added
279
+ # to the HTTP request.
280
+ #
281
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
282
+ #
283
+ def get_latest_async(custom_headers = nil)
284
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
285
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
286
+
287
+
288
+ request_headers = {}
289
+
290
+ # Set Headers
291
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
292
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
293
+ path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Billing/invoices/latest'
294
+
295
+ request_url = @base_url || @client.base_url
296
+
297
+ options = {
298
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
299
+ path_params: {'subscriptionId' => @client.subscription_id},
300
+ query_params: {'api-version' => @client.api_version},
301
+ headers: request_headers.merge(custom_headers || {}),
302
+ base_url: request_url
303
+ }
304
+ promise = @client.make_request_async(:get, path_template, options)
305
+
306
+ promise = promise.then do |result|
307
+ http_response = result.response
308
+ status_code = http_response.status
309
+ response_content = http_response.body
310
+ unless status_code == 200
311
+ error_model = JSON.load(response_content)
312
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
313
+ end
314
+
315
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
316
+ # Deserialize Response
317
+ if status_code == 200
318
+ begin
319
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
320
+ result_mapper = Azure::ARM::Billing::Models::Invoice.mapper()
321
+ result.body = @client.deserialize(result_mapper, parsed_response)
322
+ rescue Exception => e
323
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
324
+ end
325
+ end
326
+
327
+ result
328
+ end
329
+
330
+ promise.execute
331
+ end
332
+
333
+ #
334
+ # Lists the available invoices for a subscription in reverse chronological
335
+ # order beginning with the most recent invoice. In preview, invoices are
336
+ # available via this API only for invoice periods which end December 1, 2016 or
337
+ # later.
338
+ #
339
+ # @param next_page_link [String] The NextLink from the previous successful call
340
+ # to List operation.
341
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
342
+ # will be added to the HTTP request.
343
+ #
344
+ # @return [InvoicesListResult] operation results.
345
+ #
346
+ def list_next(next_page_link, custom_headers = nil)
347
+ response = list_next_async(next_page_link, custom_headers).value!
348
+ response.body unless response.nil?
349
+ end
350
+
351
+ #
352
+ # Lists the available invoices for a subscription in reverse chronological
353
+ # order beginning with the most recent invoice. In preview, invoices are
354
+ # available via this API only for invoice periods which end December 1, 2016 or
355
+ # later.
356
+ #
357
+ # @param next_page_link [String] The NextLink from the previous successful call
358
+ # to List operation.
359
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
360
+ # will be added to the HTTP request.
361
+ #
362
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
363
+ #
364
+ def list_next_with_http_info(next_page_link, custom_headers = nil)
365
+ list_next_async(next_page_link, custom_headers).value!
366
+ end
367
+
368
+ #
369
+ # Lists the available invoices for a subscription in reverse chronological
370
+ # order beginning with the most recent invoice. In preview, invoices are
371
+ # available via this API only for invoice periods which end December 1, 2016 or
372
+ # later.
373
+ #
374
+ # @param next_page_link [String] The NextLink from the previous successful call
375
+ # to List operation.
376
+ # @param [Hash{String => String}] A hash of custom headers that will be added
377
+ # to the HTTP request.
378
+ #
379
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
380
+ #
381
+ def list_next_async(next_page_link, custom_headers = nil)
382
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
383
+
384
+
385
+ request_headers = {}
386
+
387
+ # Set Headers
388
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
389
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
390
+ path_template = '{nextLink}'
391
+
392
+ request_url = @base_url || @client.base_url
393
+
394
+ options = {
395
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
396
+ skip_encoding_path_params: {'nextLink' => next_page_link},
397
+ headers: request_headers.merge(custom_headers || {}),
398
+ base_url: request_url
399
+ }
400
+ promise = @client.make_request_async(:get, path_template, options)
401
+
402
+ promise = promise.then do |result|
403
+ http_response = result.response
404
+ status_code = http_response.status
405
+ response_content = http_response.body
406
+ unless status_code == 200
407
+ error_model = JSON.load(response_content)
408
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
409
+ end
410
+
411
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
412
+ # Deserialize Response
413
+ if status_code == 200
414
+ begin
415
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
416
+ result_mapper = Azure::ARM::Billing::Models::InvoicesListResult.mapper()
417
+ result.body = @client.deserialize(result_mapper, parsed_response)
418
+ rescue Exception => e
419
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
420
+ end
421
+ end
422
+
423
+ result
424
+ end
425
+
426
+ promise.execute
427
+ end
428
+
429
+ #
430
+ # Lists the available invoices for a subscription in reverse chronological
431
+ # order beginning with the most recent invoice. In preview, invoices are
432
+ # available via this API only for invoice periods which end December 1, 2016 or
433
+ # later.
434
+ #
435
+ # @param expand [String] May be used to expand the downloadUrl property within
436
+ # a list of invoices. This enables download links to be generated for multiple
437
+ # invoices at once. By default, downloadURLs are not included when listing
438
+ # invoices.
439
+ # @param filter [String] May be used to filter invoices by
440
+ # invoicePeriodEndDate. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and
441
+ # 'and'. It does not currently support 'ne', 'or', or 'not'.
442
+ # @param skiptoken [String] Skiptoken is only used if a previous operation
443
+ # returned a partial result. If a previous response contains a nextLink
444
+ # element, the value of the nextLink element will include a skiptoken parameter
445
+ # that specifies a starting point to use for subsequent calls.
446
+ # @param top [Integer] May be used to limit the number of results to the most
447
+ # recent N invoices.
448
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
449
+ # will be added to the HTTP request.
450
+ #
451
+ # @return [InvoicesListResult] which provide lazy access to pages of the
452
+ # response.
453
+ #
454
+ def list_as_lazy(expand = nil, filter = nil, skiptoken = nil, top = nil, custom_headers = nil)
455
+ response = list_async(expand, filter, skiptoken, top, custom_headers).value!
456
+ unless response.nil?
457
+ page = response.body
458
+ page.next_method = Proc.new do |next_page_link|
459
+ list_next_async(next_page_link, custom_headers)
460
+ end
461
+ page
462
+ end
463
+ end
464
+
465
+ end
466
+ end