oraclebmc 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +82 -0
- data/README.md +220 -0
- data/lib/oraclebmc/api_client.rb +349 -0
- data/lib/oraclebmc/config.rb +80 -0
- data/lib/oraclebmc/config_file_loader.rb +85 -0
- data/lib/oraclebmc/core/blockstorage_client.rb +459 -0
- data/lib/oraclebmc/core/compute_client.rb +1053 -0
- data/lib/oraclebmc/core/core.rb +82 -0
- data/lib/oraclebmc/core/models/attach_i_scsi_volume_details.rb +179 -0
- data/lib/oraclebmc/core/models/attach_volume_details.rb +206 -0
- data/lib/oraclebmc/core/models/capture_console_history_details.rb +162 -0
- data/lib/oraclebmc/core/models/console_history.rb +252 -0
- data/lib/oraclebmc/core/models/cpe.rb +209 -0
- data/lib/oraclebmc/core/models/create_cpe_details.rb +187 -0
- data/lib/oraclebmc/core/models/create_dhcp_details.rb +195 -0
- data/lib/oraclebmc/core/models/create_drg_attachment_details.rb +184 -0
- data/lib/oraclebmc/core/models/create_drg_details.rb +173 -0
- data/lib/oraclebmc/core/models/create_image_details.rb +188 -0
- data/lib/oraclebmc/core/models/create_internet_gateway_details.rb +195 -0
- data/lib/oraclebmc/core/models/create_ip_sec_connection_details.rb +210 -0
- data/lib/oraclebmc/core/models/create_route_table_details.rb +195 -0
- data/lib/oraclebmc/core/models/create_security_list_details.rb +206 -0
- data/lib/oraclebmc/core/models/create_subnet_details.rb +253 -0
- data/lib/oraclebmc/core/models/create_vcn_details.rb +187 -0
- data/lib/oraclebmc/core/models/create_volume_backup_details.rb +173 -0
- data/lib/oraclebmc/core/models/create_volume_details.rb +211 -0
- data/lib/oraclebmc/core/models/dhcp_dns_option.rb +203 -0
- data/lib/oraclebmc/core/models/dhcp_option.rb +171 -0
- data/lib/oraclebmc/core/models/dhcp_options.rb +246 -0
- data/lib/oraclebmc/core/models/drg.rb +224 -0
- data/lib/oraclebmc/core/models/drg_attachment.rb +246 -0
- data/lib/oraclebmc/core/models/egress_security_rule.rb +240 -0
- data/lib/oraclebmc/core/models/i_scsi_volume_attachment.rb +254 -0
- data/lib/oraclebmc/core/models/icmp_options.rb +173 -0
- data/lib/oraclebmc/core/models/image.rb +282 -0
- data/lib/oraclebmc/core/models/ingress_security_rule.rb +240 -0
- data/lib/oraclebmc/core/models/instance.rb +326 -0
- data/lib/oraclebmc/core/models/internet_gateway.rb +248 -0
- data/lib/oraclebmc/core/models/ip_sec_connection.rb +261 -0
- data/lib/oraclebmc/core/models/ip_sec_connection_device_config.rb +195 -0
- data/lib/oraclebmc/core/models/ip_sec_connection_device_status.rb +198 -0
- data/lib/oraclebmc/core/models/launch_instance_details.rb +327 -0
- data/lib/oraclebmc/core/models/port_range.rb +175 -0
- data/lib/oraclebmc/core/models/route_rule.rb +177 -0
- data/lib/oraclebmc/core/models/route_table.rb +246 -0
- data/lib/oraclebmc/core/models/security_list.rb +257 -0
- data/lib/oraclebmc/core/models/shape.rb +164 -0
- data/lib/oraclebmc/core/models/subnet.rb +325 -0
- data/lib/oraclebmc/core/models/tcp_options.rb +177 -0
- data/lib/oraclebmc/core/models/tunnel_config.rb +193 -0
- data/lib/oraclebmc/core/models/tunnel_status.rb +218 -0
- data/lib/oraclebmc/core/models/udp_options.rb +177 -0
- data/lib/oraclebmc/core/models/update_cpe_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_dhcp_details.rb +172 -0
- data/lib/oraclebmc/core/models/update_drg_attachment_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_drg_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_image_details.rb +165 -0
- data/lib/oraclebmc/core/models/update_instance_details.rb +165 -0
- data/lib/oraclebmc/core/models/update_internet_gateway_details.rb +173 -0
- data/lib/oraclebmc/core/models/update_ip_sec_connection_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_route_table_details.rb +173 -0
- data/lib/oraclebmc/core/models/update_security_list_details.rb +184 -0
- data/lib/oraclebmc/core/models/update_subnet_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_vcn_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_volume_backup_details.rb +162 -0
- data/lib/oraclebmc/core/models/update_volume_details.rb +163 -0
- data/lib/oraclebmc/core/models/vcn.rb +272 -0
- data/lib/oraclebmc/core/models/vnic.rb +274 -0
- data/lib/oraclebmc/core/models/vnic_attachment.rb +271 -0
- data/lib/oraclebmc/core/models/volume.rb +249 -0
- data/lib/oraclebmc/core/models/volume_attachment.rb +284 -0
- data/lib/oraclebmc/core/models/volume_backup.rb +273 -0
- data/lib/oraclebmc/core/util.rb +1 -0
- data/lib/oraclebmc/core/virtual_network_client.rb +2263 -0
- data/lib/oraclebmc/errors.rb +62 -0
- data/lib/oraclebmc/global_context.rb +21 -0
- data/lib/oraclebmc/identity/identity.rb +38 -0
- data/lib/oraclebmc/identity/identity_client.rb +1462 -0
- data/lib/oraclebmc/identity/models/add_user_to_group_details.rb +173 -0
- data/lib/oraclebmc/identity/models/api_key.rb +251 -0
- data/lib/oraclebmc/identity/models/availability_domain.rb +173 -0
- data/lib/oraclebmc/identity/models/compartment.rb +251 -0
- data/lib/oraclebmc/identity/models/create_api_key_details.rb +162 -0
- data/lib/oraclebmc/identity/models/create_compartment_details.rb +187 -0
- data/lib/oraclebmc/identity/models/create_group_details.rb +186 -0
- data/lib/oraclebmc/identity/models/create_policy_details.rb +215 -0
- data/lib/oraclebmc/identity/models/create_swift_password_details.rb +163 -0
- data/lib/oraclebmc/identity/models/create_user_details.rb +186 -0
- data/lib/oraclebmc/identity/models/group.rb +251 -0
- data/lib/oraclebmc/identity/models/policy.rb +277 -0
- data/lib/oraclebmc/identity/models/swift_password.rb +266 -0
- data/lib/oraclebmc/identity/models/ui_password.rb +227 -0
- data/lib/oraclebmc/identity/models/update_compartment_details.rb +162 -0
- data/lib/oraclebmc/identity/models/update_group_details.rb +162 -0
- data/lib/oraclebmc/identity/models/update_policy_details.rb +190 -0
- data/lib/oraclebmc/identity/models/update_state_details.rb +163 -0
- data/lib/oraclebmc/identity/models/update_swift_password_details.rb +162 -0
- data/lib/oraclebmc/identity/models/update_user_details.rb +162 -0
- data/lib/oraclebmc/identity/models/user.rb +257 -0
- data/lib/oraclebmc/identity/models/user_group_membership.rb +249 -0
- data/lib/oraclebmc/identity/util.rb +1 -0
- data/lib/oraclebmc/load_balancer/load_balancer.rb +45 -0
- data/lib/oraclebmc/load_balancer/load_balancer_client.rb +1218 -0
- data/lib/oraclebmc/load_balancer/models/backend.rb +262 -0
- data/lib/oraclebmc/load_balancer/models/backend_details.rb +248 -0
- data/lib/oraclebmc/load_balancer/models/backend_set.rb +211 -0
- data/lib/oraclebmc/load_balancer/models/backend_set_details.rb +197 -0
- data/lib/oraclebmc/load_balancer/models/certificate.rb +209 -0
- data/lib/oraclebmc/load_balancer/models/certificate_details.rb +245 -0
- data/lib/oraclebmc/load_balancer/models/create_backend_details.rb +248 -0
- data/lib/oraclebmc/load_balancer/models/create_backend_set_details.rb +210 -0
- data/lib/oraclebmc/load_balancer/models/create_certificate_details.rb +245 -0
- data/lib/oraclebmc/load_balancer/models/create_listener_details.rb +216 -0
- data/lib/oraclebmc/load_balancer/models/create_load_balancer_details.rb +233 -0
- data/lib/oraclebmc/load_balancer/models/health_checker.rb +265 -0
- data/lib/oraclebmc/load_balancer/models/health_checker_details.rb +264 -0
- data/lib/oraclebmc/load_balancer/models/ip_address.rb +165 -0
- data/lib/oraclebmc/load_balancer/models/listener.rb +216 -0
- data/lib/oraclebmc/load_balancer/models/listener_details.rb +202 -0
- data/lib/oraclebmc/load_balancer/models/load_balancer.rb +296 -0
- data/lib/oraclebmc/load_balancer/models/load_balancer_policy.rb +162 -0
- data/lib/oraclebmc/load_balancer/models/load_balancer_protocol.rb +162 -0
- data/lib/oraclebmc/load_balancer/models/load_balancer_shape.rb +162 -0
- data/lib/oraclebmc/load_balancer/models/ssl_configuration.rb +195 -0
- data/lib/oraclebmc/load_balancer/models/ssl_configuration_details.rb +195 -0
- data/lib/oraclebmc/load_balancer/models/update_backend_details.rb +220 -0
- data/lib/oraclebmc/load_balancer/models/update_backend_set_details.rb +197 -0
- data/lib/oraclebmc/load_balancer/models/update_health_checker_details.rb +263 -0
- data/lib/oraclebmc/load_balancer/models/update_listener_details.rb +202 -0
- data/lib/oraclebmc/load_balancer/models/update_load_balancer_details.rb +165 -0
- data/lib/oraclebmc/load_balancer/models/work_request.rb +269 -0
- data/lib/oraclebmc/load_balancer/models/work_request_error.rb +185 -0
- data/lib/oraclebmc/load_balancer/util.rb +55 -0
- data/lib/oraclebmc/regions.rb +41 -0
- data/lib/oraclebmc/response.rb +86 -0
- data/lib/oraclebmc/signer.rb +119 -0
- data/lib/oraclebmc/version.rb +5 -0
- data/lib/oraclebmc/waiter.rb +111 -0
- data/lib/oraclebmc.rb +20 -0
- metadata +265 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eadf1d620781e08138d8a7811b9d24dc4e24578e
|
4
|
+
data.tar.gz: 5b86dc50c09caab8529dd809c0ff926d046e4167
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9716566a50728b903a25557edcdb0c28a730a281a760a6d65ef0c7be5cf1dee3d2e0e54c2c35c50afbc0fc18b0e9e7ffa2873caa9ded1003b5bdd219a757a6eb
|
7
|
+
data.tar.gz: 1ec1a6c768736c6b5103782b7339b191680cddfa37c9d13198dcdda203b04349e4975ca4236a8ac5b6b87ca166b6b6009019cc2f61149221dd887d05c5350ea8
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
2
|
+
|
3
|
+
This software is dual-licensed to you under the Universal Permissive License (UPL) and Apache License 2.0. See below for license terms. You may choose either license, or both.
|
4
|
+
____________________________
|
5
|
+
The Universal Permissive License (UPL), Version 1.0
|
6
|
+
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
7
|
+
|
8
|
+
Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data (collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in both
|
9
|
+
|
10
|
+
(a) the Software, and
|
11
|
+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software (each a "Larger Work" to which the Software is contributed by such licensors),
|
12
|
+
|
13
|
+
without restriction, including without limitation the rights to copy, create derivative works of, display, perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms.
|
14
|
+
|
15
|
+
This license is subject to the following condition:
|
16
|
+
|
17
|
+
The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must be included in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
The Apache Software License, Version 2.0
|
22
|
+
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
23
|
+
|
24
|
+
Licensed under the Apache License, Version 2.0 (the "License"); You may not use this product except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. A copy of the license is also reproduced below. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
25
|
+
|
26
|
+
Apache License
|
27
|
+
|
28
|
+
Version 2.0, January 2004
|
29
|
+
|
30
|
+
http://www.apache.org/licenses/
|
31
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
32
|
+
1. Definitions.
|
33
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
34
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
35
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
36
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
37
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
38
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
39
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
41
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
42
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
43
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
44
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
45
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
46
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
47
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
48
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
49
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
50
|
+
|
51
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
52
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
53
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
54
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
55
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
56
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
57
|
+
END OF TERMS AND CONDITIONS
|
58
|
+
|
59
|
+
APPENDIX: How to apply the Apache License to your work.
|
60
|
+
|
61
|
+
To apply the Apache License to your work, attach the following
|
62
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
63
|
+
replaced with your own identifying information. (Don't include
|
64
|
+
the brackets!) The text should be enclosed in the appropriate
|
65
|
+
comment syntax for the file format. We also recommend that a
|
66
|
+
file or class name and description of purpose be included on the
|
67
|
+
same "printed page" as the copyright notice for easier
|
68
|
+
identification within third-party archives.
|
69
|
+
|
70
|
+
Copyright [yyyy] [name of copyright owner]
|
71
|
+
|
72
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
73
|
+
you may not use this file except in compliance with the License.
|
74
|
+
You may obtain a copy of the License at
|
75
|
+
|
76
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
77
|
+
|
78
|
+
Unless required by applicable law or agreed to in writing, software
|
79
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
80
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
81
|
+
See the License for the specific language governing permissions and
|
82
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
# Oracle Bare Metal Cloud Services Ruby SDK
|
2
|
+
|
3
|
+
This topic describes how to install, configure, and use the Oracle Bare Metal Cloud Services Ruby SDK.
|
4
|
+
|
5
|
+
## SDK Overview
|
6
|
+
Version 1.1.1
|
7
|
+
|
8
|
+
What's new in this version?
|
9
|
+
|
10
|
+
* Added support for stateless security list rules. See the change log in the download for more details.
|
11
|
+
|
12
|
+
The Ruby SDK supports the following services:
|
13
|
+
|
14
|
+
* Core Services (which includes Networking Service, Compute Service, and Block Volume Service)
|
15
|
+
* Identity and Access Management Service
|
16
|
+
* Load Balancing Service
|
17
|
+
|
18
|
+
**Licensing:** This SDK and sample is dual licensed under the Universal Permissive License 1.0 and the Apache License.
|
19
|
+
|
20
|
+
The following table details some of the attributes of the SDK.
|
21
|
+
|
22
|
+
<table>
|
23
|
+
<tbody>
|
24
|
+
<tr>
|
25
|
+
<td>Requests</td>
|
26
|
+
<td>API methods expose required parameters as arguments and optional arguments as a hash (opts = {}). Create and update operations take request objects that mirror the properties of those objects.</td>
|
27
|
+
</tr>
|
28
|
+
<tr>
|
29
|
+
<td>Responses</td>
|
30
|
+
<td>All API methods return a Response object, which contains an HTTP status (200, 204, etc), headers, and data, and also directly exposes some commonly used response headers such as <code>opc-next_page</code>, and <code>opc-request_id</code>.</td>
|
31
|
+
</tr>
|
32
|
+
<tr>
|
33
|
+
<td>Models</td>
|
34
|
+
<td>Get, update, and create operations return first class objects of the corresponding type (such as User, Instance, etc) in Response.data.</td>
|
35
|
+
</tr>
|
36
|
+
<tr>
|
37
|
+
<td>Errors</td>
|
38
|
+
<td>Unsuccessful requests will always raise an exception. {OracleBMC::Errors::ServiceError ServiceError} is raised when the service returns an error, and {OracleBMC::Errors::NetworkError NetworkError} is raised for network issues (such as failed host resolution).</td>
|
39
|
+
</tr>
|
40
|
+
<tr>
|
41
|
+
<td>Signing</td>
|
42
|
+
<td>Requests made through the API classes are automatically signed, but you can also use the {OracleBMC::Signer Signer} directly to sign your own requests if needed.</td>
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<td>Automatic Paging</td>
|
46
|
+
<td>Response objects for lists support {OracleBMC::Response#each page enumeration}. See example code later in this file.</td>
|
47
|
+
</tr>
|
48
|
+
<tr>
|
49
|
+
<td>Waiters</td>
|
50
|
+
<td>Responses for get requests support waiting for a particular states using {OracleBMC::Response#wait_until wait_until}. See example code later in this file.</td>
|
51
|
+
</tr>
|
52
|
+
<tr>
|
53
|
+
<td>HTTP Client</td>
|
54
|
+
<td>The Ruby SDK uses {https://github.com/typhoeus/typhoeus Typhoeus} for HTTP requests, which in turn calls libcurl. Some behaviors may depend on your installation of libcurl. If needed, arbitrary options may be passed to each Typhoeus request by specifying them in {OracleBMC::ApiClient#request_option_overrides ApiClient.request_option_overrides}.</td>
|
55
|
+
</tr>
|
56
|
+
</tbody>
|
57
|
+
</table>
|
58
|
+
|
59
|
+
## Requirements
|
60
|
+
|
61
|
+
To use the Ruby SDK, you must have:
|
62
|
+
|
63
|
+
* An Oracle Bare Metal Cloud Services account.
|
64
|
+
* A user created in that account, in a group with a policy that grants the desired permissions. This can be a user for yourself, or another person/system that needs to call the API. For an example of how to set up a new user, group, compartment, and policy, see [Adding Users](https://docs.us-phoenix-1.oraclecloud.com/Content/GSG/Tasks/addingusers.htm) in the Getting Started Guide. For a list of typical policies you may want to use, see [Common Policies](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Concepts/commonpolicies.htm) in the User Guide.
|
65
|
+
* A keypair used for signing API requests, with the public key uploaded to Oracle. Only the user calling the API should be in possession of the private key. See the configuration information below.
|
66
|
+
* Ruby version 2.2 or later running on Mac or Linux. Windows is not supported at this time.
|
67
|
+
|
68
|
+
## Downloading and Installing the Gem File
|
69
|
+
|
70
|
+
1. Run the following command if you're running one of these operating systems:
|
71
|
+
|
72
|
+
* For Oracle Enterprise Linux (OEL) or Red Hat Enterprise Linux (RHEL): `sudo yum upgrade curl`
|
73
|
+
* For Ubuntu: `sudo apt-get install libcurl3 libcurl3-dev`
|
74
|
+
|
75
|
+
2. [Download the Ruby SDK](https://docs.us-phoenix-1.oraclecloud.com/tools/ruby/latest/download/oracle-bmcs-ruby-sdk.zip). It's a zip archive that contains the gem, documentation, examples, and licensing information.
|
76
|
+
|
77
|
+
3. Install the gem with the following command:
|
78
|
+
|
79
|
+
gem install oraclebmc-1.1.1.gem
|
80
|
+
|
81
|
+
|
82
|
+
### Troubleshooting an Installation
|
83
|
+
If you see "Unable to resolve dependencies”, you can install the dependencies manually:
|
84
|
+
|
85
|
+
gem install typhoeus
|
86
|
+
gem install inifile
|
87
|
+
|
88
|
+
## Configuring the SDK
|
89
|
+
|
90
|
+
To use any of the APIs, you must supply a {OracleBMC::Config Config} object. You can create the object directly in code, or you can create one in a config file. The configuration includes:
|
91
|
+
|
92
|
+
* Required credentials and settings: See [SDK and Tool Configuration](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm) in the User Guide.
|
93
|
+
* Optional SDK-specific settings: See the {OracleBMC::Config Config} object for the full list of config options.
|
94
|
+
|
95
|
+
|
96
|
+
## Writing Your First Ruby Program with the SDK
|
97
|
+
|
98
|
+
require 'oraclebmc'
|
99
|
+
|
100
|
+
# This will load the config file at the default location, and will
|
101
|
+
# use the tenancy from that config as the compartment in the
|
102
|
+
# call to list_users.
|
103
|
+
api = OracleBMC::Identity::IdentityClient.new(region: OracleBMC::Regions::REGION_US_PHOENIX_1)
|
104
|
+
response = api.list_users(OracleBMC.config.tenancy)
|
105
|
+
response.data.each { |user| puts user.name }
|
106
|
+
|
107
|
+
## Loading Alternate Configurations
|
108
|
+
|
109
|
+
You can also load a config file from a different location, and/or specify a different profile from the config file:
|
110
|
+
|
111
|
+
require 'oraclebmc'
|
112
|
+
|
113
|
+
my_config = OracleBMC::ConfigFileLoader.load_config(config_file_location:'my_config', profile_name:'USER_TWO')
|
114
|
+
api = OracleBMC::Identity::IdentityClient.new(config:my_config)
|
115
|
+
response = api.get_user(my_config.user)
|
116
|
+
puts 'User Name: ' + response.data.name
|
117
|
+
|
118
|
+
Or you can create a {OracleBMC::Config Config} programmatically. Note that the global value {OracleBMC#config OracleBMC.config} will always attempt to load the DEFAULT profile from the default config file location (`~/.oraclebmc/config`), unless it has been explicitly set to another value.
|
119
|
+
|
120
|
+
## Examples
|
121
|
+
The example code in this section shows how various parts of the Ruby SDK work. More examples can be found in the SDK download.
|
122
|
+
|
123
|
+
### Identity Operations
|
124
|
+
The following example runs create, read, update, and delete (CRUD) operations on users.
|
125
|
+
|
126
|
+
require 'oraclebmc'
|
127
|
+
|
128
|
+
compartment = OracleBMC.config.tenancy
|
129
|
+
|
130
|
+
api = OracleBMC::Identity::IdentityClient.new
|
131
|
+
users = api.list_users(compartment_id = compartment).data
|
132
|
+
puts "There are currently " + users.length.to_s + " users."
|
133
|
+
|
134
|
+
# Create User
|
135
|
+
request = OracleBMC::Identity::Models::CreateUserDetails.new
|
136
|
+
request.compartment_id = compartment
|
137
|
+
request.name = "userA"
|
138
|
+
request.description = "example user"
|
139
|
+
response = api.create_user(request)
|
140
|
+
|
141
|
+
puts "Created user " + response.data.name
|
142
|
+
user_id = response.data.id
|
143
|
+
|
144
|
+
users = api.list_users(compartment_id = compartment).data
|
145
|
+
puts "There are now " + users.length.to_s + " users."
|
146
|
+
|
147
|
+
# Get User
|
148
|
+
response = api.get_user(user_id = user_id)
|
149
|
+
|
150
|
+
# Update User (using a request object)
|
151
|
+
newDescription = "updated user description"
|
152
|
+
request = OracleBMC::Identity::Models::UpdateUserDetails.new
|
153
|
+
request.description = "Updated description"
|
154
|
+
response = api.update_user(user_id, request)
|
155
|
+
|
156
|
+
puts "Updated description to:" + response.data.description
|
157
|
+
|
158
|
+
# Update User (using a hash)
|
159
|
+
newDescription = "updated without a request object"
|
160
|
+
response = api.update_user(user_id, { description: "Updated again, but using a hash instead of an object." })
|
161
|
+
|
162
|
+
# Delete User
|
163
|
+
api.delete_user(user_id)
|
164
|
+
|
165
|
+
users = api.list_users(compartment_id = compartment).data
|
166
|
+
puts "Back to " + users.length.to_s + " users."
|
167
|
+
|
168
|
+
### Paging Through Results
|
169
|
+
The following example shows how to page through results. It also gives an example of supplying optional parameters.
|
170
|
+
|
171
|
+
require 'oraclebmc'
|
172
|
+
|
173
|
+
api = OracleBMC::Identity::IdentityClient.new
|
174
|
+
compartment = OracleBMC.config.tenancy
|
175
|
+
|
176
|
+
### Automatic paging:
|
177
|
+
api.list_users(compartment, limit:'3').each { |r| r.data.each { |user| puts user.name }}
|
178
|
+
|
179
|
+
### Manual paging:
|
180
|
+
request_number = 0
|
181
|
+
next_page = nil
|
182
|
+
|
183
|
+
loop do
|
184
|
+
response = api.list_users(compartment, {limit: '3', page: next_page})
|
185
|
+
|
186
|
+
puts "Page " + request_number.to_s
|
187
|
+
response.data.each { |user| puts user.name }
|
188
|
+
|
189
|
+
break unless response.has_next_page?
|
190
|
+
next_page = response.next_page
|
191
|
+
request_number += 1
|
192
|
+
end
|
193
|
+
|
194
|
+
### Launching an Instance and Waiting for a State
|
195
|
+
The following example shows how to launch an instance (which assumes that you already have a subnet created), and then wait until the instance is running.
|
196
|
+
|
197
|
+
require 'oraclebmc'
|
198
|
+
|
199
|
+
ssh_public_key = File.open(File.expand_path(public_key_file), "rb").read
|
200
|
+
|
201
|
+
request = OracleBMC::Core::Models::LaunchInstanceDetails.new
|
202
|
+
request.availability_domain = availability_domain # TODO: Set an availability domain, such as 'kIdk:PHX-AD-2'
|
203
|
+
request.compartment_id = compartment_id # TODO: set your compartment ID here
|
204
|
+
request.display_name = 'my_instance'
|
205
|
+
request.image_id = image_id # TODO: set your image ID here. You can see the available options with list_images.
|
206
|
+
request.shape = shape # TODO: set your instance shape. You can see the available options with list_shapes.
|
207
|
+
request.subnet_id = subnet_id # TODO: set your subnet ID here
|
208
|
+
request.metadata = {'ssh_authorized_keys' => ssh_public_key}
|
209
|
+
|
210
|
+
api = OracleBMC::Core::ComputeClient.new
|
211
|
+
response = api.launch_instance(request)
|
212
|
+
instance_id = response.data.id
|
213
|
+
response = api.get_instance(instance_id).wait_until(:lifecycle_state, OracleBMC::Core::Models::Instance::LIFECYCLE_STATE_RUNNING)
|
214
|
+
|
215
|
+
## Questions or Feedback?
|
216
|
+
Ways to get in touch:
|
217
|
+
|
218
|
+
* [Stack Overflow](https://stackoverflow.com/): Please use the [oracle-bmcs](https://stackoverflow.com/questions/tagged/oracle-bmcs) and [oracle-bmcs-ruby-sdk](https://stackoverflow.com/questions/tagged/oracle-bmcs-ruby-sdk) tags in your post
|
219
|
+
* [Developer Tools section](https://community.oracle.com/community/cloud_computing/bare-metal/content?filterID=contentstatus%5Bpublished%5D~category%5Bdeveloper-tools%5D&filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bthread%5D) of the Oracle Cloud forums
|
220
|
+
* [My Oracle Support](https://support.oracle.com)
|
@@ -0,0 +1,349 @@
|
|
1
|
+
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'json'
|
5
|
+
require 'logger'
|
6
|
+
require 'securerandom'
|
7
|
+
require 'tempfile'
|
8
|
+
require 'typhoeus'
|
9
|
+
require 'uri'
|
10
|
+
require_relative 'signer'
|
11
|
+
require_relative 'version'
|
12
|
+
require_relative 'response'
|
13
|
+
|
14
|
+
module OracleBMC
|
15
|
+
class ApiClient
|
16
|
+
# The Config object holding settings to be used in the API client.
|
17
|
+
attr_accessor :config
|
18
|
+
|
19
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
20
|
+
#
|
21
|
+
# @return [Hash]
|
22
|
+
attr_accessor :default_headers
|
23
|
+
|
24
|
+
# Request options to be sent with each Typhoeus request.
|
25
|
+
# These options will override any defaults normally set by ApiClient.
|
26
|
+
# See {https://github.com/typhoeus/ethon/blob/master/lib/ethon/curls/options.rb} for
|
27
|
+
# some of the available options.
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
attr_accessor :request_option_overrides
|
31
|
+
|
32
|
+
def initialize(config, signer)
|
33
|
+
fail "Missing the required parameter 'config' when initializing ApiClient." if config.nil?
|
34
|
+
fail "Missing the required parameter 'signer' when initializing ApiClient." if signer.nil?
|
35
|
+
|
36
|
+
@config = config
|
37
|
+
@signer = signer
|
38
|
+
@default_headers = {}
|
39
|
+
@request_option_overrides = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
# Call an API with given options.
|
43
|
+
#
|
44
|
+
# @param [Symbol] http_method HTTP method/verb (e.g. :post, :get)
|
45
|
+
# @param [String] path URL path (e.g. /volumeAttachments/)
|
46
|
+
# @param [String] endpoint URL of the endpoint (e.g https://iaas.us-phoenix-1.oraclecloud.com/20160918)
|
47
|
+
# @option opts [Hash] :header_params Header parameters
|
48
|
+
# @option opts [Hash] :query_params Query parameters
|
49
|
+
# @option opts [Hash] :form_params Form parameters
|
50
|
+
# @option opts [Object] :body HTTP body in JSON
|
51
|
+
#
|
52
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
53
|
+
# the data deserialized from response body (could be nil), response status code, and response headers.
|
54
|
+
def call_api(http_method, path, endpoint, opts)
|
55
|
+
http_method = http_method.to_sym.downcase
|
56
|
+
|
57
|
+
if http_method == :get
|
58
|
+
# Wrap get calls in a lambda that can be called later for paging
|
59
|
+
# and wait_until.
|
60
|
+
proc = lambda { |page|
|
61
|
+
if !page.nil?
|
62
|
+
opts[:query_params] ||= {}
|
63
|
+
opts[:query_params][:page] = page
|
64
|
+
end
|
65
|
+
|
66
|
+
return call_api_inner(http_method, path, endpoint, opts)
|
67
|
+
}
|
68
|
+
|
69
|
+
response = proc.call(nil)
|
70
|
+
response.api_call = proc
|
71
|
+
return response
|
72
|
+
else
|
73
|
+
# No need to wrap methods other than GET, just call them directly.
|
74
|
+
return call_api_inner(http_method, path, endpoint, opts)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
80
|
+
# @param [Object] model object to be converted into JSON string
|
81
|
+
# @return [String] JSON string representation of the object
|
82
|
+
def object_to_http_body(model)
|
83
|
+
return model if model.nil? || model.is_a?(String)
|
84
|
+
local_body = nil
|
85
|
+
if model.is_a?(Array)
|
86
|
+
local_body = model.map{|m| object_to_hash(m) }
|
87
|
+
else
|
88
|
+
local_body = object_to_hash(model)
|
89
|
+
end
|
90
|
+
local_body.to_json
|
91
|
+
end
|
92
|
+
|
93
|
+
# Builds the client info string to be sent with each request.
|
94
|
+
def build_request_id
|
95
|
+
return SecureRandom.uuid.gsub!('-', '').upcase
|
96
|
+
end
|
97
|
+
|
98
|
+
# Builds the client info string to be sent with each request.
|
99
|
+
def build_user_info
|
100
|
+
return "Oracle-RubySDK/#{VERSION}"
|
101
|
+
end
|
102
|
+
|
103
|
+
# Build the user agent string to be send with each request.
|
104
|
+
def build_user_agent
|
105
|
+
agent = "#{build_user_info} (ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})"
|
106
|
+
|
107
|
+
if config.additional_user_agent
|
108
|
+
agent = "#{agent} #{config.additional_user_agent}"
|
109
|
+
end
|
110
|
+
|
111
|
+
agent
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def call_api_inner(http_method, path, endpoint, opts)
|
117
|
+
request = build_request(http_method, path, endpoint, opts)
|
118
|
+
|
119
|
+
if defined? ResponseMocker
|
120
|
+
ResponseMocker.instance.process_request(request)
|
121
|
+
end
|
122
|
+
|
123
|
+
response = request.run
|
124
|
+
|
125
|
+
if defined? ResponseMocker
|
126
|
+
ResponseMocker.instance.process_response(response)
|
127
|
+
end
|
128
|
+
|
129
|
+
if @config.logger
|
130
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
131
|
+
end
|
132
|
+
|
133
|
+
# In the case of an error, deserialize to a plain hash by indicating 'Object'.
|
134
|
+
return_type = response.success? ? opts[:return_type] : 'Object'
|
135
|
+
|
136
|
+
if return_type
|
137
|
+
data = deserialize(response, return_type)
|
138
|
+
else
|
139
|
+
data = nil
|
140
|
+
end
|
141
|
+
|
142
|
+
unless response.success?
|
143
|
+
if data and not response.success?
|
144
|
+
fail Errors::ServiceError.new(response.code, data[:code], response.headers['opc-request-id'], data[:message])
|
145
|
+
else
|
146
|
+
fail Errors::NetworkError.new(response.return_code)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if @config.logger
|
151
|
+
@config.logger.debug "API Response Received:\nData: #{data.inspect}\nStatus code: #{response.code}\nHeaders: #{response.headers}"
|
152
|
+
end
|
153
|
+
|
154
|
+
return Response.new(status=response.code, headers=response.headers, data=data)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
# Builds the HTTP request
|
159
|
+
#
|
160
|
+
# @param [Symbol] http_method HTTP method/verb (e.g. :post, :get)
|
161
|
+
# @param [String] path URL path (e.g. /account/new)
|
162
|
+
# @param [String] endpoint URL of the endpoint
|
163
|
+
# @option opts [Hash] :header_params Header parameters
|
164
|
+
# @option opts [Hash] :query_params Query parameters
|
165
|
+
# @option opts [Hash] :form_params Query parameters
|
166
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
167
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
168
|
+
def build_request(http_method, path, endpoint, opts = {})
|
169
|
+
url = build_request_url(path, endpoint)
|
170
|
+
|
171
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
172
|
+
query_params = opts[:query_params] || {}
|
173
|
+
form_params = opts[:form_params] || {}
|
174
|
+
body = opts[:body] || nil
|
175
|
+
|
176
|
+
@signer.sign(http_method, ApiClient::append_query_params(url, query_params), header_params, body)
|
177
|
+
|
178
|
+
req_opts = {
|
179
|
+
:method => http_method,
|
180
|
+
:headers => header_params,
|
181
|
+
:params => query_params,
|
182
|
+
:connecttimeout => @config.connection_timeout,
|
183
|
+
:timeout => @config.timeout,
|
184
|
+
:verbose => @config.log_requests
|
185
|
+
}.merge(@request_option_overrides)
|
186
|
+
|
187
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
188
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
189
|
+
req_opts.update :body => req_body
|
190
|
+
if @config.logger
|
191
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
request = Typhoeus::Request.new(url, req_opts)
|
196
|
+
request.options[:headers]['opc-client-info'] = build_user_info
|
197
|
+
request.options[:headers]['opc-request-id'] ||= build_request_id
|
198
|
+
request.options[:headers]['User-Agent'] = build_user_agent
|
199
|
+
|
200
|
+
return request
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.append_query_params(url, query_params)
|
204
|
+
if query_params.empty?
|
205
|
+
url
|
206
|
+
else
|
207
|
+
# This must mirror the logic in Typhoeus for building query strings.
|
208
|
+
# Unfortunately, Typhoeus does not appear to expose this logic or the result,
|
209
|
+
# so we have to replicate it here.
|
210
|
+
url + '?' + query_params.map{|k,v| "#{k}=#{CGI.escape(v)}"}.join('&')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Check if the given MIME is a JSON MIME.
|
215
|
+
# JSON MIME examples:
|
216
|
+
# application/json
|
217
|
+
# application/json; charset=UTF8
|
218
|
+
# APPLICATION/JSON
|
219
|
+
# @param [String] mime MIME
|
220
|
+
# @return [Boolean] True if the MIME is applicaton/json
|
221
|
+
def json_mime?(mime)
|
222
|
+
!(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
|
223
|
+
end
|
224
|
+
|
225
|
+
# Deserialize the response to the given return type.
|
226
|
+
#
|
227
|
+
# @param [Response] response HTTP response
|
228
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
229
|
+
def deserialize(response, return_type)
|
230
|
+
body = response.body
|
231
|
+
return nil if body.nil? || body.empty?
|
232
|
+
|
233
|
+
# return response body directly for String return type
|
234
|
+
return body if return_type == 'String'
|
235
|
+
|
236
|
+
# ensuring a default content type
|
237
|
+
content_type = response.headers['content-type'] || 'application/json'
|
238
|
+
|
239
|
+
fail "content-type is not supported: #{content_type}" unless json_mime?(content_type)
|
240
|
+
|
241
|
+
begin
|
242
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
243
|
+
rescue JSON::ParserError => e
|
244
|
+
if %w(String Date DateTime).include?(return_type)
|
245
|
+
data = body
|
246
|
+
else
|
247
|
+
raise e
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
convert_to_type data, return_type
|
252
|
+
end
|
253
|
+
|
254
|
+
# Convert reponse data to the given return type
|
255
|
+
# (for example, data:"15", return_type:"Integer" => 15).
|
256
|
+
#
|
257
|
+
# @param [Object] data Data to be converted
|
258
|
+
# @param [String] return_type Return type
|
259
|
+
# @return [Mixed] Data in a particular type
|
260
|
+
def convert_to_type(data, return_type)
|
261
|
+
return nil if data.nil?
|
262
|
+
case return_type
|
263
|
+
when 'String'
|
264
|
+
data.to_s
|
265
|
+
when 'Integer'
|
266
|
+
data.to_i
|
267
|
+
when 'Float'
|
268
|
+
data.to_f
|
269
|
+
when 'BOOLEAN'
|
270
|
+
data == true
|
271
|
+
when 'DateTime'
|
272
|
+
# parse date time (expecting ISO 8601 format)
|
273
|
+
DateTime.parse data
|
274
|
+
when 'Date'
|
275
|
+
# parse date time (expecting ISO 8601 format)
|
276
|
+
Date.parse data
|
277
|
+
when 'Object'
|
278
|
+
# generic object (usually a Hash), return directly
|
279
|
+
data
|
280
|
+
when /\AArray<(.+)>\z/
|
281
|
+
# e.g. Array<Pet>
|
282
|
+
sub_type = $1
|
283
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
284
|
+
when /\AHash\<String, (.+)\>\z/
|
285
|
+
# e.g. Hash<String, Integer>
|
286
|
+
sub_type = $1
|
287
|
+
{}.tap do |hash|
|
288
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
289
|
+
end
|
290
|
+
else
|
291
|
+
if defined? OracleBMC.const_get(return_type).get_subtype
|
292
|
+
# The return type may be an abstract type, in which case
|
293
|
+
# we need to use the discriminator value to get the correct subtype.
|
294
|
+
return_type = OracleBMC.const_get(return_type).get_subtype(data)
|
295
|
+
end
|
296
|
+
|
297
|
+
OracleBMC.const_get(return_type).new.tap do |model|
|
298
|
+
model.build_from_hash data
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def build_request_url(path, endpoint)
|
304
|
+
# Add leading and trailing slashes to path
|
305
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
306
|
+
URI.encode(endpoint + path)
|
307
|
+
end
|
308
|
+
|
309
|
+
# Builds the HTTP request body
|
310
|
+
#
|
311
|
+
# @param [Hash] header_params Header parameters
|
312
|
+
# @param [Hash] form_params Query parameters
|
313
|
+
# @param [Object] body HTTP body (JSON/XML)
|
314
|
+
# @return [String] HTTP body data in the form of string
|
315
|
+
def build_request_body(header_params, form_params, body)
|
316
|
+
# http form
|
317
|
+
if header_params['content-type'] == 'application/x-www-form-urlencoded' ||
|
318
|
+
header_params['content-type'] == 'multipart/form-data'
|
319
|
+
data = {}
|
320
|
+
form_params.each do |key, value|
|
321
|
+
case value
|
322
|
+
when File, Array, nil
|
323
|
+
# let typhoeus handle File, Array and nil parameters
|
324
|
+
data[key] = value
|
325
|
+
else
|
326
|
+
data[key] = value.to_s
|
327
|
+
end
|
328
|
+
end
|
329
|
+
elsif body
|
330
|
+
data = body.is_a?(String) ? body : body.to_json
|
331
|
+
else
|
332
|
+
data = nil
|
333
|
+
end
|
334
|
+
data
|
335
|
+
end
|
336
|
+
|
337
|
+
# Convert object(non-array) to hash.
|
338
|
+
# @param [Object] obj object to be converted into JSON string
|
339
|
+
# @return [String] JSON string representation of the object
|
340
|
+
def object_to_hash(obj)
|
341
|
+
if obj.respond_to?(:to_hash)
|
342
|
+
obj.to_hash
|
343
|
+
else
|
344
|
+
obj
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
end
|