zahra-package-test 1.1.2
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/LICENSE +28 -0
- data/README.md +112 -0
- data/lib/swagger_petstore/api_helper.rb +10 -0
- data/lib/swagger_petstore/client.rb +84 -0
- data/lib/swagger_petstore/configuration.rb +124 -0
- data/lib/swagger_petstore/controllers/base_controller.rb +66 -0
- data/lib/swagger_petstore/controllers/pet_controller.rb +206 -0
- data/lib/swagger_petstore/controllers/store_controller.rb +94 -0
- data/lib/swagger_petstore/controllers/user_controller.rb +165 -0
- data/lib/swagger_petstore/exceptions/api_exception.rb +10 -0
- data/lib/swagger_petstore/exceptions/o_auth_provider_exception.rb +48 -0
- data/lib/swagger_petstore/http/auth/api_key.rb +42 -0
- data/lib/swagger_petstore/http/auth/http_basic.rb +50 -0
- data/lib/swagger_petstore/http/auth/petstore_auth.rb +91 -0
- data/lib/swagger_petstore/http/http_call_back.rb +10 -0
- data/lib/swagger_petstore/http/http_method_enum.rb +10 -0
- data/lib/swagger_petstore/http/http_request.rb +10 -0
- data/lib/swagger_petstore/http/http_response.rb +10 -0
- data/lib/swagger_petstore/models/api_response.rb +70 -0
- data/lib/swagger_petstore/models/base_model.rb +62 -0
- data/lib/swagger_petstore/models/category.rb +60 -0
- data/lib/swagger_petstore/models/category2.rb +60 -0
- data/lib/swagger_petstore/models/content_type_enum.rb +20 -0
- data/lib/swagger_petstore/models/o_auth_provider_error_enum.rb +45 -0
- data/lib/swagger_petstore/models/o_auth_scope_petstore_auth_enum.rb +23 -0
- data/lib/swagger_petstore/models/o_auth_token.rb +100 -0
- data/lib/swagger_petstore/models/order.rb +109 -0
- data/lib/swagger_petstore/models/pet.rb +107 -0
- data/lib/swagger_petstore/models/pet_request.rb +107 -0
- data/lib/swagger_petstore/models/status1_enum.rb +26 -0
- data/lib/swagger_petstore/models/status2_enum.rb +26 -0
- data/lib/swagger_petstore/models/status_enum.rb +26 -0
- data/lib/swagger_petstore/models/store_order_request.rb +109 -0
- data/lib/swagger_petstore/models/tag.rb +60 -0
- data/lib/swagger_petstore/models/user.rb +120 -0
- data/lib/swagger_petstore/models/user_request.rb +120 -0
- data/lib/swagger_petstore/utilities/date_time_helper.rb +11 -0
- data/lib/swagger_petstore/utilities/file_wrapper.rb +16 -0
- data/lib/swagger_petstore.rb +61 -0
- data/test/controllers/controller_test_base.rb +38 -0
- data/test/controllers/test_store_controller.rb +32 -0
- data/test/http_response_catcher.rb +19 -0
- metadata +160 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# StoreController
|
8
|
+
class StoreController < BaseController
|
9
|
+
# For valid response try integer IDs with value >= 1 and <= 10. Other values
|
10
|
+
# will generated exceptions
|
11
|
+
# @param [Integer] order_id Required parameter: ID of pet that needs to be
|
12
|
+
# fetched
|
13
|
+
# @return [Order] response from the API call
|
14
|
+
def get_order_by_id(order_id)
|
15
|
+
new_api_call_builder
|
16
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
17
|
+
'/store/order/{orderId}',
|
18
|
+
Server::DEFAULT)
|
19
|
+
.template_param(new_parameter(order_id, key: 'orderId')
|
20
|
+
.should_encode(true))
|
21
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
22
|
+
.response(new_response_handler
|
23
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
24
|
+
.deserialize_into(Order.method(:from_hash))
|
25
|
+
.local_error('400',
|
26
|
+
'Invalid ID supplied',
|
27
|
+
APIException)
|
28
|
+
.local_error('404',
|
29
|
+
'Order not found',
|
30
|
+
APIException))
|
31
|
+
.execute
|
32
|
+
end
|
33
|
+
|
34
|
+
# Place an order for a pet
|
35
|
+
# @param [StoreOrderRequest] body Required parameter: order placed for
|
36
|
+
# purchasing the pet
|
37
|
+
# @return [Order] response from the API call
|
38
|
+
def place_order(body)
|
39
|
+
new_api_call_builder
|
40
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
41
|
+
'/store/order',
|
42
|
+
Server::DEFAULT)
|
43
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
44
|
+
.body_param(new_parameter(body))
|
45
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
46
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
47
|
+
.response(new_response_handler
|
48
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
49
|
+
.deserialize_into(Order.method(:from_hash))
|
50
|
+
.local_error('400',
|
51
|
+
'Invalid Order',
|
52
|
+
APIException))
|
53
|
+
.execute
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a map of status codes to quantities
|
57
|
+
# @return [Hash[String, Integer]] response from the API call
|
58
|
+
def get_inventory
|
59
|
+
new_api_call_builder
|
60
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
61
|
+
'/store/inventory',
|
62
|
+
Server::DEFAULT)
|
63
|
+
.auth(Single.new('api_key')))
|
64
|
+
.response(new_response_handler
|
65
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
66
|
+
.deserialize_into(proc do |response| response.to_i end)
|
67
|
+
.is_primitive_response(true))
|
68
|
+
.execute
|
69
|
+
end
|
70
|
+
|
71
|
+
# For valid response try integer IDs with positive integer value. Negative
|
72
|
+
# or non-integer values will generate API errors
|
73
|
+
# @param [Integer] order_id Required parameter: ID of the order that needs
|
74
|
+
# to be deleted
|
75
|
+
# @return [void] response from the API call
|
76
|
+
def delete_order(order_id)
|
77
|
+
new_api_call_builder
|
78
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
79
|
+
'/store/order/{orderId}',
|
80
|
+
Server::DEFAULT)
|
81
|
+
.template_param(new_parameter(order_id, key: 'orderId')
|
82
|
+
.should_encode(true)))
|
83
|
+
.response(new_response_handler
|
84
|
+
.is_response_void(true)
|
85
|
+
.local_error('400',
|
86
|
+
'Invalid ID supplied',
|
87
|
+
APIException)
|
88
|
+
.local_error('404',
|
89
|
+
'Order not found',
|
90
|
+
APIException))
|
91
|
+
.execute
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# UserController
|
8
|
+
class UserController < BaseController
|
9
|
+
# Creates list of users with given input array
|
10
|
+
# @param [Array[User]] body Required parameter: List of user object
|
11
|
+
# @return [void] response from the API call
|
12
|
+
def create_users_with_array_input(body)
|
13
|
+
new_api_call_builder
|
14
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
15
|
+
'/user/createWithArray',
|
16
|
+
Server::DEFAULT)
|
17
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
18
|
+
.body_param(new_parameter(body))
|
19
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
20
|
+
.response(new_response_handler
|
21
|
+
.is_response_void(true))
|
22
|
+
.execute
|
23
|
+
end
|
24
|
+
|
25
|
+
# This can only be done by the logged in user.
|
26
|
+
# @param [String] username Required parameter: name that need to be
|
27
|
+
# updated
|
28
|
+
# @param [UserRequest] body Required parameter: Updated user object
|
29
|
+
# @return [void] response from the API call
|
30
|
+
def update_user(username,
|
31
|
+
body)
|
32
|
+
new_api_call_builder
|
33
|
+
.request(new_request_builder(HttpMethodEnum::PUT,
|
34
|
+
'/user/{username}',
|
35
|
+
Server::DEFAULT)
|
36
|
+
.template_param(new_parameter(username, key: 'username')
|
37
|
+
.should_encode(true))
|
38
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
39
|
+
.body_param(new_parameter(body))
|
40
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
41
|
+
.response(new_response_handler
|
42
|
+
.is_response_void(true)
|
43
|
+
.local_error('400',
|
44
|
+
'Invalid user supplied',
|
45
|
+
APIException)
|
46
|
+
.local_error('404',
|
47
|
+
'User not found',
|
48
|
+
APIException))
|
49
|
+
.execute
|
50
|
+
end
|
51
|
+
|
52
|
+
# Creates list of users with given input array
|
53
|
+
# @param [Array[User]] body Required parameter: List of user object
|
54
|
+
# @return [void] response from the API call
|
55
|
+
def create_users_with_list_input(body)
|
56
|
+
new_api_call_builder
|
57
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
58
|
+
'/user/createWithList',
|
59
|
+
Server::DEFAULT)
|
60
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
61
|
+
.body_param(new_parameter(body))
|
62
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
63
|
+
.response(new_response_handler
|
64
|
+
.is_response_void(true))
|
65
|
+
.execute
|
66
|
+
end
|
67
|
+
|
68
|
+
# Logs out current logged in user session
|
69
|
+
# @return [void] response from the API call
|
70
|
+
def logout_user
|
71
|
+
new_api_call_builder
|
72
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
73
|
+
'/user/logout',
|
74
|
+
Server::DEFAULT))
|
75
|
+
.response(new_response_handler
|
76
|
+
.is_response_void(true))
|
77
|
+
.execute
|
78
|
+
end
|
79
|
+
|
80
|
+
# Logs user into the system
|
81
|
+
# @param [String] username Required parameter: The user name for login
|
82
|
+
# @param [String] password Required parameter: The password for login in
|
83
|
+
# clear text
|
84
|
+
# @return [String] response from the API call
|
85
|
+
def login_user(username,
|
86
|
+
password)
|
87
|
+
new_api_call_builder
|
88
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
89
|
+
'/user/login',
|
90
|
+
Server::DEFAULT)
|
91
|
+
.query_param(new_parameter(username, key: 'username'))
|
92
|
+
.query_param(new_parameter(password, key: 'password')))
|
93
|
+
.response(new_response_handler
|
94
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
95
|
+
.deserialize_into(proc do |response| response.to_s end)
|
96
|
+
.is_primitive_response(true)
|
97
|
+
.local_error('400',
|
98
|
+
'Invalid username/password supplied',
|
99
|
+
APIException))
|
100
|
+
.execute
|
101
|
+
end
|
102
|
+
|
103
|
+
# Get user by user name
|
104
|
+
# @param [String] username Required parameter: The name that needs to be
|
105
|
+
# fetched. Use user1 for testing.
|
106
|
+
# @return [User] response from the API call
|
107
|
+
def get_user_by_name(username)
|
108
|
+
new_api_call_builder
|
109
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
110
|
+
'/user/{username}',
|
111
|
+
Server::DEFAULT)
|
112
|
+
.template_param(new_parameter(username, key: 'username')
|
113
|
+
.should_encode(true))
|
114
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
115
|
+
.response(new_response_handler
|
116
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
117
|
+
.deserialize_into(User.method(:from_hash))
|
118
|
+
.local_error('400',
|
119
|
+
'Invalid username supplied',
|
120
|
+
APIException)
|
121
|
+
.local_error('404',
|
122
|
+
'User not found',
|
123
|
+
APIException))
|
124
|
+
.execute
|
125
|
+
end
|
126
|
+
|
127
|
+
# This can only be done by the logged in user.
|
128
|
+
# @param [UserRequest] body Required parameter: Created user object
|
129
|
+
# @return [void] response from the API call
|
130
|
+
def create_user(body)
|
131
|
+
new_api_call_builder
|
132
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
133
|
+
'/user',
|
134
|
+
Server::DEFAULT)
|
135
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
136
|
+
.body_param(new_parameter(body))
|
137
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
138
|
+
.response(new_response_handler
|
139
|
+
.is_response_void(true))
|
140
|
+
.execute
|
141
|
+
end
|
142
|
+
|
143
|
+
# This can only be done by the logged in user.
|
144
|
+
# @param [String] username Required parameter: The name that needs to be
|
145
|
+
# deleted
|
146
|
+
# @return [void] response from the API call
|
147
|
+
def delete_user(username)
|
148
|
+
new_api_call_builder
|
149
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
150
|
+
'/user/{username}',
|
151
|
+
Server::DEFAULT)
|
152
|
+
.template_param(new_parameter(username, key: 'username')
|
153
|
+
.should_encode(true)))
|
154
|
+
.response(new_response_handler
|
155
|
+
.is_response_void(true)
|
156
|
+
.local_error('400',
|
157
|
+
'Invalid username supplied',
|
158
|
+
APIException)
|
159
|
+
.local_error('404',
|
160
|
+
'User not found',
|
161
|
+
APIException))
|
162
|
+
.execute
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < CoreLibrary::ApiException
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# OAuth 2 Authorization endpoint exception.
|
8
|
+
class OAuthProviderException < APIException
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
12
|
+
# Gets or sets error code.
|
13
|
+
# @return [OAuthProviderErrorEnum]
|
14
|
+
attr_accessor :error
|
15
|
+
|
16
|
+
# Gets or sets human-readable text providing additional information on
|
17
|
+
# error.
|
18
|
+
# Used to assist the client developer in understanding the error that
|
19
|
+
# occurred.
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :error_description
|
22
|
+
|
23
|
+
# Gets or sets a URI identifying a human-readable web page with information
|
24
|
+
# about the error, used to provide the client developer with additional
|
25
|
+
# information about the error.
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :error_uri
|
28
|
+
|
29
|
+
# The constructor.
|
30
|
+
# @param [String] The reason for raising an exception.
|
31
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
32
|
+
def initialize(reason, response)
|
33
|
+
super(reason, response)
|
34
|
+
hash = APIHelper.json_deserialize(@response.raw_body)
|
35
|
+
unbox(hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Populates this object by extracting properties from a hash.
|
39
|
+
# @param [Hash] The deserialized response sent by the server in the
|
40
|
+
# response body.
|
41
|
+
def unbox(hash)
|
42
|
+
@error = hash.key?('error') ? hash['error'] : nil
|
43
|
+
@error_description =
|
44
|
+
hash.key?('error_description') ? hash['error_description'] : SKIP
|
45
|
+
@error_uri = hash.key?('error_uri') ? hash['error_uri'] : SKIP
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# Utility class for custom header authorization.
|
8
|
+
class ApiKey < CoreLibrary::HeaderAuth
|
9
|
+
# Display error message on occurrence of authentication failure.
|
10
|
+
# @returns [String] The oAuth error message.
|
11
|
+
def error_message
|
12
|
+
'ApiKey: api_key is undefined.'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Initialization constructor.
|
16
|
+
def initialize(api_key_credentials)
|
17
|
+
auth_params = {}
|
18
|
+
auth_params['api_key'] = api_key_credentials.api_key unless
|
19
|
+
api_key_credentials.nil? || api_key_credentials.api_key.nil?
|
20
|
+
|
21
|
+
super auth_params
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Data class for ApiKeyCredentials.
|
26
|
+
# Data class for ApiKeyCredentials.
|
27
|
+
class ApiKeyCredentials
|
28
|
+
attr_reader :api_key
|
29
|
+
|
30
|
+
def initialize(api_key:)
|
31
|
+
raise ArgumentError, 'api_key cannot be nil' if api_key.nil?
|
32
|
+
|
33
|
+
@api_key = api_key
|
34
|
+
end
|
35
|
+
|
36
|
+
def clone_with(api_key: nil)
|
37
|
+
api_key ||= self.api_key
|
38
|
+
|
39
|
+
ApiKeyCredentials.new(api_key: api_key)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# Utility class for basic authorization.
|
8
|
+
class HttpBasic < CoreLibrary::HeaderAuth
|
9
|
+
include CoreLibrary
|
10
|
+
# Display error message on occurrence of authentication failure.
|
11
|
+
# @returns [String] The oAuth error message.
|
12
|
+
def error_message
|
13
|
+
'HttpBasic: username or passwprd is undefined.'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Initialization constructor.
|
17
|
+
def initialize(http_basic_credentials)
|
18
|
+
auth_params = {}
|
19
|
+
unless http_basic_credentials.nil? ||
|
20
|
+
http_basic_credentials.username.nil? ||
|
21
|
+
http_basic_credentials.passwprd.nil?
|
22
|
+
auth_params['Authorization'] =
|
23
|
+
"Basic #{AuthHelper.get_base64_encoded_value(http_basic_credentials.username,
|
24
|
+
http_basic_credentials.passwprd)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
super auth_params
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Data class for HttpBasicCredentials.
|
32
|
+
class HttpBasicCredentials
|
33
|
+
attr_reader :username, :passwprd
|
34
|
+
|
35
|
+
def initialize(username:, passwprd:)
|
36
|
+
raise ArgumentError, 'username cannot be nil' if username.nil?
|
37
|
+
raise ArgumentError, 'passwprd cannot be nil' if passwprd.nil?
|
38
|
+
|
39
|
+
@username = username
|
40
|
+
@passwprd = passwprd
|
41
|
+
end
|
42
|
+
|
43
|
+
def clone_with(username: nil, passwprd: nil)
|
44
|
+
username ||= self.username
|
45
|
+
passwprd ||= self.passwprd
|
46
|
+
|
47
|
+
HttpBasicCredentials.new(username: username, passwprd: passwprd)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
8
|
+
class PetstoreAuth < CoreLibrary::HeaderAuth
|
9
|
+
include CoreLibrary
|
10
|
+
# Display error message on occurrence of authentication failure.
|
11
|
+
# @returns [String] The oAuth error message.
|
12
|
+
def error_message
|
13
|
+
'PetstoreAuth: OAuthToken is undefined or expired.'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Initialization constructor.
|
17
|
+
def initialize(petstore_auth_credentials, config)
|
18
|
+
auth_params = {}
|
19
|
+
@_o_auth_client_id = petstore_auth_credentials.o_auth_client_id unless
|
20
|
+
petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_client_id.nil?
|
21
|
+
@_o_auth_redirect_uri = petstore_auth_credentials.o_auth_redirect_uri unless
|
22
|
+
petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_redirect_uri.nil?
|
23
|
+
@_o_auth_token = petstore_auth_credentials.o_auth_token unless
|
24
|
+
petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_token.nil?
|
25
|
+
@_o_auth_scopes = petstore_auth_credentials.o_auth_scopes unless
|
26
|
+
petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_scopes.nil?
|
27
|
+
@_o_auth_api = OAuthAuthorizationController.new(config)
|
28
|
+
auth_params['Authorization'] = "Bearer #{@_o_auth_token.access_token}" unless @_o_auth_token.nil?
|
29
|
+
|
30
|
+
super auth_params
|
31
|
+
end
|
32
|
+
|
33
|
+
# Validates the oAuth token.
|
34
|
+
# @return [Boolean] true if the token is present and not expired.
|
35
|
+
def valid
|
36
|
+
!@_o_auth_token.nil? && !token_expired?(@_o_auth_token)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Builds and returns an authorization URL.
|
40
|
+
# The user is expected to obtain an authorization code from this URL and then call the
|
41
|
+
# fetch token function with that authorization code.
|
42
|
+
# @param [String] state An opaque state string.
|
43
|
+
# @param [Hash] additional_params Any additional query parameters to be added to the URL.
|
44
|
+
# @return [String] additional_params The authorization URL.
|
45
|
+
def get_authorization_url(state: nil, additional_params: nil)
|
46
|
+
auth_url = @_config.get_base_uri
|
47
|
+
auth_url += '/authorize'
|
48
|
+
query_params = {
|
49
|
+
'response_type' => 'code',
|
50
|
+
'client_id' => @_o_auth_client_id,
|
51
|
+
'redirect_uri' => @_o_auth_client_id
|
52
|
+
}
|
53
|
+
query_params['scope'] = Array(@_o_auth_scopes).compact.join(' ') if @_o_auth_scopes
|
54
|
+
query_params['state'] = state if state
|
55
|
+
query_params.merge!(additional_params) if additional_params
|
56
|
+
auth_url = APIHelper.append_url_with_query_parameters(auth_url,
|
57
|
+
query_params)
|
58
|
+
APIHelper.clean_url(auth_url)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Data class for PetstoreAuthCredentials.
|
63
|
+
class PetstoreAuthCredentials
|
64
|
+
attr_reader :o_auth_client_id, :o_auth_redirect_uri, :o_auth_token,
|
65
|
+
:o_auth_scopes
|
66
|
+
|
67
|
+
def initialize(o_auth_client_id:, o_auth_redirect_uri:, o_auth_token: nil,
|
68
|
+
o_auth_scopes: nil)
|
69
|
+
raise ArgumentError, 'o_auth_client_id cannot be nil' if o_auth_client_id.nil?
|
70
|
+
raise ArgumentError, 'o_auth_redirect_uri cannot be nil' if o_auth_redirect_uri.nil?
|
71
|
+
|
72
|
+
@o_auth_client_id = o_auth_client_id
|
73
|
+
@o_auth_redirect_uri = o_auth_redirect_uri
|
74
|
+
@o_auth_token = o_auth_token
|
75
|
+
@o_auth_scopes = o_auth_scopes
|
76
|
+
end
|
77
|
+
|
78
|
+
def clone_with(o_auth_client_id: nil, o_auth_redirect_uri: nil,
|
79
|
+
o_auth_token: nil, o_auth_scopes: nil)
|
80
|
+
o_auth_client_id ||= self.o_auth_client_id
|
81
|
+
o_auth_redirect_uri ||= self.o_auth_redirect_uri
|
82
|
+
o_auth_token ||= self.o_auth_token
|
83
|
+
o_auth_scopes ||= self.o_auth_scopes
|
84
|
+
|
85
|
+
PetstoreAuthCredentials.new(o_auth_client_id: o_auth_client_id,
|
86
|
+
o_auth_redirect_uri: o_auth_redirect_uri,
|
87
|
+
o_auth_token: o_auth_token,
|
88
|
+
o_auth_scopes: o_auth_scopes)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
8
|
+
class HttpCallBack < CoreLibrary::HttpCallback
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# ApiResponse Model.
|
8
|
+
class ApiResponse < BaseModel
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
12
|
+
# TODO: Write general description for this method
|
13
|
+
# @return [Integer]
|
14
|
+
attr_accessor :code
|
15
|
+
|
16
|
+
# TODO: Write general description for this method
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :type
|
19
|
+
|
20
|
+
# TODO: Write general description for this method
|
21
|
+
# @return [String]
|
22
|
+
attr_accessor :message
|
23
|
+
|
24
|
+
# A mapping from model property names to API property names.
|
25
|
+
def self.names
|
26
|
+
@_hash = {} if @_hash.nil?
|
27
|
+
@_hash['code'] = 'code'
|
28
|
+
@_hash['type'] = 'type'
|
29
|
+
@_hash['message'] = 'message'
|
30
|
+
@_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
# An array for optional fields
|
34
|
+
def self.optionals
|
35
|
+
%w[
|
36
|
+
code
|
37
|
+
type
|
38
|
+
message
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
# An array for nullable fields
|
43
|
+
def self.nullables
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize(code = SKIP,
|
48
|
+
type = SKIP,
|
49
|
+
message = SKIP)
|
50
|
+
@code = code unless code == SKIP
|
51
|
+
@type = type unless type == SKIP
|
52
|
+
@message = message unless message == SKIP
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates an instance of the object from a hash.
|
56
|
+
def self.from_hash(hash)
|
57
|
+
return nil unless hash
|
58
|
+
|
59
|
+
# Extract variables from the hash.
|
60
|
+
code = hash.key?('code') ? hash['code'] : SKIP
|
61
|
+
type = hash.key?('type') ? hash['type'] : SKIP
|
62
|
+
message = hash.key?('message') ? hash['message'] : SKIP
|
63
|
+
|
64
|
+
# Create object from extracted values.
|
65
|
+
ApiResponse.new(code,
|
66
|
+
type,
|
67
|
+
message)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# swagger_petstore
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstore
|
7
|
+
# Base model.
|
8
|
+
class BaseModel < CoreLibrary::BaseModel
|
9
|
+
# Returns a Hash representation of the current object.
|
10
|
+
def to_hash
|
11
|
+
# validating the model being serialized
|
12
|
+
self.class.validate(self) if self.class.respond_to?(:validate)
|
13
|
+
|
14
|
+
hash = {}
|
15
|
+
instance_variables.each do |name|
|
16
|
+
value = instance_variable_get(name)
|
17
|
+
name = name[1..]
|
18
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
19
|
+
optional_fields = self.class.optionals
|
20
|
+
nullable_fields = self.class.nullables
|
21
|
+
if value.nil?
|
22
|
+
next unless nullable_fields.include?(name)
|
23
|
+
|
24
|
+
if !optional_fields.include?(name) && !nullable_fields.include?(name)
|
25
|
+
raise ArgumentError,
|
26
|
+
"`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
hash[key] = nil
|
31
|
+
unless value.nil?
|
32
|
+
if respond_to?("to_custom_#{name}")
|
33
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
34
|
+
params = [hash, key]
|
35
|
+
hash[key] = send("to_custom_#{name}", *params)
|
36
|
+
else
|
37
|
+
hash[key] = send("to_custom_#{name}")
|
38
|
+
end
|
39
|
+
elsif respond_to?("to_union_type_#{name}")
|
40
|
+
hash[key] = send("to_union_type_#{name}")
|
41
|
+
elsif value.instance_of? Array
|
42
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
43
|
+
elsif value.instance_of? Hash
|
44
|
+
hash[key] = {}
|
45
|
+
value.each do |k, v|
|
46
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
47
|
+
end
|
48
|
+
else
|
49
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a JSON representation of the curent object.
|
57
|
+
def to_json(options = {})
|
58
|
+
hash = to_hash
|
59
|
+
hash.to_json(options)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|