* [Ruby] Use Ruby autoload to lower memory usage and load times Fixes #12648 Requiring all models up front can be very expensive in both time and memory if there are many models. In an example client with 6000 models, this would consume nearly 400MB of memory and take about 7 seconds to load. This is mostly unnecessary as most users of the client library will only actually use a small percentage of the library. The changes in this commit use Ruby's autoload capability to defer the loading until the constant is actually used. In that same example client with 6000 models, when initially requiring the library, the memory usage dropped to ~20MB and loaded in 0.3 seconds. As the constants are loaded on-demand, the memory would increase towards that 400MB ceiling, but if only a few constants are actually used, then memory will never actually hit that ceiling. An additional side effect of using Ruby's autoload is that the order of declaring the constants is not important, as Ruby will naturally load them in the correct order when they are needed. Thus, this commit obviates PR #9103 and fixes #4690. * add option to use autoload in ruby client * test ruby clients only * add tests * update samples * Revert "test ruby clients only" This reverts commit 0aaf71cd4cc5d266f824b261a4d312f07bd589e5. * update doc Co-authored-by: Jason Frey <fryguy9@gmail.com>
6.1 KiB
Petstore::StoreApi
All URIs are relative to http://petstore.swagger.io:80/v2
Method | HTTP request | Description |
---|---|---|
delete_order | DELETE /store/order/{order_id} | Delete purchase order by ID |
get_inventory | GET /store/inventory | Returns pet inventories by status |
get_order_by_id | GET /store/order/{order_id} | Find purchase order by ID |
place_order | POST /store/order | Place an order for a pet |
delete_order
delete_order(order_id)
Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
Examples
require 'time'
require 'petstore'
api_instance = Petstore::StoreApi.new
order_id = 'order_id_example' # String | ID of the order that needs to be deleted
begin
# Delete purchase order by ID
api_instance.delete_order(order_id)
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->delete_order: #{e}"
end
Using the delete_order_with_http_info variant
This returns an Array which contains the response data (nil
in this case), status code and headers.
<Array(nil, Integer, Hash)> delete_order_with_http_info(order_id)
begin
# Delete purchase order by ID
data, status_code, headers = api_instance.delete_order_with_http_info(order_id)
p status_code # => 2xx
p headers # => { ... }
p data # => nil
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->delete_order_with_http_info: #{e}"
end
Parameters
Name | Type | Description | Notes |
---|---|---|---|
order_id | String | ID of the order that needs to be deleted |
Return type
nil (empty response body)
Authorization
No authorization required
HTTP request headers
- Content-Type: Not defined
- Accept: Not defined
get_inventory
Hash<String, Integer> get_inventory
Returns pet inventories by status
Returns a map of status codes to quantities
Examples
require 'time'
require 'petstore'
# setup authorization
Petstore.configure do |config|
# Configure API key authorization: api_key
config.api_key['api_key'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
# config.api_key_prefix['api_key'] = 'Bearer'
end
api_instance = Petstore::StoreApi.new
begin
# Returns pet inventories by status
result = api_instance.get_inventory
p result
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->get_inventory: #{e}"
end
Using the get_inventory_with_http_info variant
This returns an Array which contains the response data, status code and headers.
<Array(Hash<String, Integer>, Integer, Hash)> get_inventory_with_http_info
begin
# Returns pet inventories by status
data, status_code, headers = api_instance.get_inventory_with_http_info
p status_code # => 2xx
p headers # => { ... }
p data # => Hash<String, Integer>
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->get_inventory_with_http_info: #{e}"
end
Parameters
This endpoint does not need any parameter.
Return type
Hash<String, Integer>
Authorization
HTTP request headers
- Content-Type: Not defined
- Accept: application/json
get_order_by_id
get_order_by_id(order_id)
Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
Examples
require 'time'
require 'petstore'
api_instance = Petstore::StoreApi.new
order_id = 789 # Integer | ID of pet that needs to be fetched
begin
# Find purchase order by ID
result = api_instance.get_order_by_id(order_id)
p result
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->get_order_by_id: #{e}"
end
Using the get_order_by_id_with_http_info variant
This returns an Array which contains the response data, status code and headers.
<Array(, Integer, Hash)> get_order_by_id_with_http_info(order_id)
begin
# Find purchase order by ID
data, status_code, headers = api_instance.get_order_by_id_with_http_info(order_id)
p status_code # => 2xx
p headers # => { ... }
p data # => <Order>
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->get_order_by_id_with_http_info: #{e}"
end
Parameters
Name | Type | Description | Notes |
---|---|---|---|
order_id | Integer | ID of pet that needs to be fetched |
Return type
Authorization
No authorization required
HTTP request headers
- Content-Type: Not defined
- Accept: application/xml, application/json
place_order
place_order(order)
Place an order for a pet
Examples
require 'time'
require 'petstore'
api_instance = Petstore::StoreApi.new
order = Petstore::Order.new # Order | order placed for purchasing the pet
begin
# Place an order for a pet
result = api_instance.place_order(order)
p result
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->place_order: #{e}"
end
Using the place_order_with_http_info variant
This returns an Array which contains the response data, status code and headers.
<Array(, Integer, Hash)> place_order_with_http_info(order)
begin
# Place an order for a pet
data, status_code, headers = api_instance.place_order_with_http_info(order)
p status_code # => 2xx
p headers # => { ... }
p data # => <Order>
rescue Petstore::ApiError => e
puts "Error when calling StoreApi->place_order_with_http_info: #{e}"
end
Parameters
Name | Type | Description | Notes |
---|---|---|---|
order | Order | order placed for purchasing the pet |
Return type
Authorization
No authorization required
HTTP request headers
- Content-Type: application/json
- Accept: application/xml, application/json