pluggy-sdk 1.0.0.post2__py3-none-any.whl

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.
Files changed (163) hide show
  1. pluggy_sdk/__init__.py +183 -0
  2. pluggy_sdk/api/__init__.py +26 -0
  3. pluggy_sdk/api/account_api.py +582 -0
  4. pluggy_sdk/api/acquirer_anticipation_api.py +658 -0
  5. pluggy_sdk/api/acquirer_receivable_api.py +658 -0
  6. pluggy_sdk/api/acquirer_sale_api.py +658 -0
  7. pluggy_sdk/api/auth_api.py +599 -0
  8. pluggy_sdk/api/bill_api.py +561 -0
  9. pluggy_sdk/api/bulk_payment_api.py +854 -0
  10. pluggy_sdk/api/category_api.py +1084 -0
  11. pluggy_sdk/api/connector_api.py +970 -0
  12. pluggy_sdk/api/identity_api.py +575 -0
  13. pluggy_sdk/api/income_report_api.py +308 -0
  14. pluggy_sdk/api/investment_api.py +909 -0
  15. pluggy_sdk/api/items_api.py +1441 -0
  16. pluggy_sdk/api/loan_api.py +561 -0
  17. pluggy_sdk/api/payment_customer_api.py +1399 -0
  18. pluggy_sdk/api/payment_intent_api.py +833 -0
  19. pluggy_sdk/api/payment_recipient_api.py +1976 -0
  20. pluggy_sdk/api/payment_request_api.py +1636 -0
  21. pluggy_sdk/api/portfolio_yield_api.py +574 -0
  22. pluggy_sdk/api/smart_account_api.py +1116 -0
  23. pluggy_sdk/api/transaction_api.py +954 -0
  24. pluggy_sdk/api/webhook_api.py +1391 -0
  25. pluggy_sdk/api_client.py +769 -0
  26. pluggy_sdk/api_response.py +21 -0
  27. pluggy_sdk/configuration.py +466 -0
  28. pluggy_sdk/exceptions.py +200 -0
  29. pluggy_sdk/models/__init__.py +145 -0
  30. pluggy_sdk/models/account.py +134 -0
  31. pluggy_sdk/models/accounts_list200_response.py +102 -0
  32. pluggy_sdk/models/acquirer_anticipation.py +117 -0
  33. pluggy_sdk/models/acquirer_anticipation_data.py +101 -0
  34. pluggy_sdk/models/acquirer_data.py +113 -0
  35. pluggy_sdk/models/acquirer_receivable.py +143 -0
  36. pluggy_sdk/models/acquirer_receivable_data.py +108 -0
  37. pluggy_sdk/models/acquirer_receivable_data_establishment.py +96 -0
  38. pluggy_sdk/models/acquirer_receivable_destination_account.py +92 -0
  39. pluggy_sdk/models/acquirer_receivable_related_sale.py +99 -0
  40. pluggy_sdk/models/acquirer_sale.py +171 -0
  41. pluggy_sdk/models/acquirer_sale_data.py +150 -0
  42. pluggy_sdk/models/acquirer_sale_installment.py +93 -0
  43. pluggy_sdk/models/acquirer_sale_installment_data.py +95 -0
  44. pluggy_sdk/models/address.py +110 -0
  45. pluggy_sdk/models/aggregated_portfolio.py +120 -0
  46. pluggy_sdk/models/aggregated_portfolio_response.py +102 -0
  47. pluggy_sdk/models/asset_distribution.py +88 -0
  48. pluggy_sdk/models/auth_request.py +90 -0
  49. pluggy_sdk/models/auth_response.py +88 -0
  50. pluggy_sdk/models/bank_data.py +92 -0
  51. pluggy_sdk/models/bill.py +109 -0
  52. pluggy_sdk/models/bill_finance_charge.py +103 -0
  53. pluggy_sdk/models/bills_list200_response.py +102 -0
  54. pluggy_sdk/models/bulk_payment.py +128 -0
  55. pluggy_sdk/models/bulk_payments_list200_response.py +102 -0
  56. pluggy_sdk/models/category.py +96 -0
  57. pluggy_sdk/models/client_category_rule.py +94 -0
  58. pluggy_sdk/models/company.py +90 -0
  59. pluggy_sdk/models/connect_token_request.py +94 -0
  60. pluggy_sdk/models/connect_token_response.py +88 -0
  61. pluggy_sdk/models/connector.py +141 -0
  62. pluggy_sdk/models/connector_credential.py +121 -0
  63. pluggy_sdk/models/connector_health.py +96 -0
  64. pluggy_sdk/models/connector_health_details.py +90 -0
  65. pluggy_sdk/models/connector_list_response.py +102 -0
  66. pluggy_sdk/models/connector_user_action.py +93 -0
  67. pluggy_sdk/models/create_bulk_payment.py +96 -0
  68. pluggy_sdk/models/create_client_category_rule.py +92 -0
  69. pluggy_sdk/models/create_item.py +111 -0
  70. pluggy_sdk/models/create_item_parameters.py +144 -0
  71. pluggy_sdk/models/create_or_update_payment_customer.py +105 -0
  72. pluggy_sdk/models/create_payment_customer_request_body.py +103 -0
  73. pluggy_sdk/models/create_payment_intent.py +94 -0
  74. pluggy_sdk/models/create_payment_recipient.py +100 -0
  75. pluggy_sdk/models/create_payment_request.py +102 -0
  76. pluggy_sdk/models/create_pix_qr_payment_request.py +96 -0
  77. pluggy_sdk/models/create_smart_account_request.py +102 -0
  78. pluggy_sdk/models/create_webhook.py +99 -0
  79. pluggy_sdk/models/credential_select_option.py +90 -0
  80. pluggy_sdk/models/credit_card_metadata.py +101 -0
  81. pluggy_sdk/models/credit_data.py +127 -0
  82. pluggy_sdk/models/document.py +100 -0
  83. pluggy_sdk/models/email.py +100 -0
  84. pluggy_sdk/models/global_error_response.py +94 -0
  85. pluggy_sdk/models/i_count_response.py +88 -0
  86. pluggy_sdk/models/identity_relation.py +102 -0
  87. pluggy_sdk/models/identity_response.py +149 -0
  88. pluggy_sdk/models/income_report.py +90 -0
  89. pluggy_sdk/models/income_reports_response.py +102 -0
  90. pluggy_sdk/models/investment.py +192 -0
  91. pluggy_sdk/models/investment_expenses.py +108 -0
  92. pluggy_sdk/models/investment_metadata.py +99 -0
  93. pluggy_sdk/models/investment_transaction.py +124 -0
  94. pluggy_sdk/models/investments_list200_response.py +102 -0
  95. pluggy_sdk/models/item.py +148 -0
  96. pluggy_sdk/models/item_creation_error_response.py +102 -0
  97. pluggy_sdk/models/item_error.py +94 -0
  98. pluggy_sdk/models/item_options.py +90 -0
  99. pluggy_sdk/models/loan.py +199 -0
  100. pluggy_sdk/models/loan_contracted_fee.py +118 -0
  101. pluggy_sdk/models/loan_contracted_finance_charge.py +92 -0
  102. pluggy_sdk/models/loan_installment_balloon_payment.py +95 -0
  103. pluggy_sdk/models/loan_installment_balloon_payment_amount.py +90 -0
  104. pluggy_sdk/models/loan_installments.py +130 -0
  105. pluggy_sdk/models/loan_interest_rate.py +136 -0
  106. pluggy_sdk/models/loan_payment_release.py +103 -0
  107. pluggy_sdk/models/loan_payment_release_over_parcel.py +106 -0
  108. pluggy_sdk/models/loan_payment_release_over_parcel_charge.py +92 -0
  109. pluggy_sdk/models/loan_payment_release_over_parcel_fee.py +92 -0
  110. pluggy_sdk/models/loan_payments.py +98 -0
  111. pluggy_sdk/models/loan_warranty.py +94 -0
  112. pluggy_sdk/models/loans_list200_response.py +102 -0
  113. pluggy_sdk/models/merchant.py +96 -0
  114. pluggy_sdk/models/monthly_portfolio.py +100 -0
  115. pluggy_sdk/models/monthly_portfolio_response.py +102 -0
  116. pluggy_sdk/models/not_authenticated_response.py +90 -0
  117. pluggy_sdk/models/page_response_acquirer_anticipations.py +102 -0
  118. pluggy_sdk/models/page_response_acquirer_receivables.py +102 -0
  119. pluggy_sdk/models/page_response_acquirer_sales.py +102 -0
  120. pluggy_sdk/models/page_response_category_rules.py +102 -0
  121. pluggy_sdk/models/page_response_investment_transactions.py +102 -0
  122. pluggy_sdk/models/page_response_transactions.py +102 -0
  123. pluggy_sdk/models/parameter_validation_error.py +92 -0
  124. pluggy_sdk/models/parameter_validation_response.py +98 -0
  125. pluggy_sdk/models/payment_customer.py +105 -0
  126. pluggy_sdk/models/payment_customers_list200_response.py +102 -0
  127. pluggy_sdk/models/payment_data.py +105 -0
  128. pluggy_sdk/models/payment_data_participant.py +101 -0
  129. pluggy_sdk/models/payment_institution.py +101 -0
  130. pluggy_sdk/models/payment_intent.py +145 -0
  131. pluggy_sdk/models/payment_intents_list200_response.py +102 -0
  132. pluggy_sdk/models/payment_recipient.py +106 -0
  133. pluggy_sdk/models/payment_recipient_account.py +99 -0
  134. pluggy_sdk/models/payment_recipients_institution_list200_response.py +102 -0
  135. pluggy_sdk/models/payment_recipients_list200_response.py +102 -0
  136. pluggy_sdk/models/payment_request.py +118 -0
  137. pluggy_sdk/models/payment_request_callback_urls.py +92 -0
  138. pluggy_sdk/models/payment_requests_list200_response.py +102 -0
  139. pluggy_sdk/models/percentage_over_index.py +90 -0
  140. pluggy_sdk/models/phone_number.py +100 -0
  141. pluggy_sdk/models/pix_data.py +90 -0
  142. pluggy_sdk/models/smart_account.py +107 -0
  143. pluggy_sdk/models/smart_account_address.py +112 -0
  144. pluggy_sdk/models/smart_account_balance.py +95 -0
  145. pluggy_sdk/models/smart_accounts_list200_response.py +102 -0
  146. pluggy_sdk/models/status_detail.py +142 -0
  147. pluggy_sdk/models/status_detail_product.py +101 -0
  148. pluggy_sdk/models/status_detail_product_warning.py +92 -0
  149. pluggy_sdk/models/transaction.py +145 -0
  150. pluggy_sdk/models/update_item.py +109 -0
  151. pluggy_sdk/models/update_item_parameters.py +144 -0
  152. pluggy_sdk/models/update_payment_recipient.py +100 -0
  153. pluggy_sdk/models/update_payment_request.py +102 -0
  154. pluggy_sdk/models/update_transaction.py +88 -0
  155. pluggy_sdk/models/webhook.py +106 -0
  156. pluggy_sdk/models/webhook_creation_error_response.py +90 -0
  157. pluggy_sdk/models/webhooks_list200_response.py +102 -0
  158. pluggy_sdk/py.typed +0 -0
  159. pluggy_sdk/rest.py +258 -0
  160. pluggy_sdk-1.0.0.post2.dist-info/METADATA +336 -0
  161. pluggy_sdk-1.0.0.post2.dist-info/RECORD +163 -0
  162. pluggy_sdk-1.0.0.post2.dist-info/WHEEL +5 -0
  163. pluggy_sdk-1.0.0.post2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,769 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Pluggy API
5
+
6
+ Pluggy's main API to review data and execute connectors
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: hello@pluggy.ai
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ import datetime
17
+ from dateutil.parser import parse
18
+ from enum import Enum
19
+ import json
20
+ import mimetypes
21
+ import os
22
+ import re
23
+ import tempfile
24
+
25
+ from urllib.parse import quote
26
+ from typing import Tuple, Optional, List, Dict, Union
27
+ from pydantic import SecretStr
28
+
29
+ from pluggy_sdk.configuration import Configuration
30
+ from pluggy_sdk.api_response import ApiResponse, T as ApiResponseT
31
+ import pluggy_sdk.models
32
+ from pluggy_sdk import rest
33
+ from pluggy_sdk.exceptions import (
34
+ ApiValueError,
35
+ ApiException,
36
+ BadRequestException,
37
+ UnauthorizedException,
38
+ ForbiddenException,
39
+ NotFoundException,
40
+ ServiceException
41
+ )
42
+
43
+ RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
44
+
45
+ class ApiClient:
46
+ """Generic API client for OpenAPI client library builds.
47
+
48
+ OpenAPI generic API client. This client handles the client-
49
+ server communication, and is invariant across implementations. Specifics of
50
+ the methods and models for each application are generated from the OpenAPI
51
+ templates.
52
+
53
+ :param configuration: .Configuration object for this client
54
+ :param header_name: a header to pass when making calls to the API.
55
+ :param header_value: a header value to pass when making calls to
56
+ the API.
57
+ :param cookie: a cookie to include in the header when making calls
58
+ to the API
59
+ """
60
+
61
+ PRIMITIVE_TYPES = (float, bool, bytes, str, int)
62
+ NATIVE_TYPES_MAPPING = {
63
+ 'int': int,
64
+ 'long': int, # TODO remove as only py3 is supported?
65
+ 'float': float,
66
+ 'str': str,
67
+ 'bool': bool,
68
+ 'date': datetime.date,
69
+ 'datetime': datetime.datetime,
70
+ 'object': object,
71
+ }
72
+ _pool = None
73
+
74
+ def __init__(
75
+ self,
76
+ configuration=None,
77
+ header_name=None,
78
+ header_value=None,
79
+ cookie=None
80
+ ) -> None:
81
+ # use default configuration if none is provided
82
+ if configuration is None:
83
+ configuration = Configuration.get_default()
84
+ self.configuration = configuration
85
+
86
+ self.rest_client = rest.RESTClientObject(configuration)
87
+ self.default_headers = {}
88
+ if header_name is not None:
89
+ self.default_headers[header_name] = header_value
90
+ self.cookie = cookie
91
+ # Set default User-Agent.
92
+ self.user_agent = 'OpenAPI-Generator/1.0.0.post2/python'
93
+ self.client_side_validation = configuration.client_side_validation
94
+
95
+ def __enter__(self):
96
+ return self
97
+
98
+ def __exit__(self, exc_type, exc_value, traceback):
99
+ pass
100
+
101
+ @property
102
+ def user_agent(self):
103
+ """User agent for this API client"""
104
+ return self.default_headers['User-Agent']
105
+
106
+ @user_agent.setter
107
+ def user_agent(self, value):
108
+ self.default_headers['User-Agent'] = value
109
+
110
+ def set_default_header(self, header_name, header_value):
111
+ self.default_headers[header_name] = header_value
112
+
113
+
114
+ _default = None
115
+
116
+ @classmethod
117
+ def get_default(cls):
118
+ """Return new instance of ApiClient.
119
+
120
+ This method returns newly created, based on default constructor,
121
+ object of ApiClient class or returns a copy of default
122
+ ApiClient.
123
+
124
+ :return: The ApiClient object.
125
+ """
126
+ if cls._default is None:
127
+ cls._default = ApiClient()
128
+ return cls._default
129
+
130
+ @classmethod
131
+ def set_default(cls, default):
132
+ """Set default instance of ApiClient.
133
+
134
+ It stores default ApiClient.
135
+
136
+ :param default: object of ApiClient.
137
+ """
138
+ cls._default = default
139
+
140
+ def param_serialize(
141
+ self,
142
+ method,
143
+ resource_path,
144
+ path_params=None,
145
+ query_params=None,
146
+ header_params=None,
147
+ body=None,
148
+ post_params=None,
149
+ files=None, auth_settings=None,
150
+ collection_formats=None,
151
+ _host=None,
152
+ _request_auth=None
153
+ ) -> RequestSerialized:
154
+
155
+ """Builds the HTTP request params needed by the request.
156
+ :param method: Method to call.
157
+ :param resource_path: Path to method endpoint.
158
+ :param path_params: Path parameters in the url.
159
+ :param query_params: Query parameters in the url.
160
+ :param header_params: Header parameters to be
161
+ placed in the request header.
162
+ :param body: Request body.
163
+ :param post_params dict: Request post form parameters,
164
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
165
+ :param auth_settings list: Auth Settings names for the request.
166
+ :param files dict: key -> filename, value -> filepath,
167
+ for `multipart/form-data`.
168
+ :param collection_formats: dict of collection formats for path, query,
169
+ header, and post parameters.
170
+ :param _request_auth: set to override the auth_settings for an a single
171
+ request; this effectively ignores the authentication
172
+ in the spec for a single request.
173
+ :return: tuple of form (path, http_method, query_params, header_params,
174
+ body, post_params, files)
175
+ """
176
+
177
+ config = self.configuration
178
+
179
+ # header parameters
180
+ header_params = header_params or {}
181
+ header_params.update(self.default_headers)
182
+ if self.cookie:
183
+ header_params['Cookie'] = self.cookie
184
+ if header_params:
185
+ header_params = self.sanitize_for_serialization(header_params)
186
+ header_params = dict(
187
+ self.parameters_to_tuples(header_params,collection_formats)
188
+ )
189
+
190
+ # path parameters
191
+ if path_params:
192
+ path_params = self.sanitize_for_serialization(path_params)
193
+ path_params = self.parameters_to_tuples(
194
+ path_params,
195
+ collection_formats
196
+ )
197
+ for k, v in path_params:
198
+ # specified safe chars, encode everything
199
+ resource_path = resource_path.replace(
200
+ '{%s}' % k,
201
+ quote(str(v), safe=config.safe_chars_for_path_param)
202
+ )
203
+
204
+ # post parameters
205
+ if post_params or files:
206
+ post_params = post_params if post_params else []
207
+ post_params = self.sanitize_for_serialization(post_params)
208
+ post_params = self.parameters_to_tuples(
209
+ post_params,
210
+ collection_formats
211
+ )
212
+ if files:
213
+ post_params.extend(self.files_parameters(files))
214
+
215
+ # auth setting
216
+ self.update_params_for_auth(
217
+ header_params,
218
+ query_params,
219
+ auth_settings,
220
+ resource_path,
221
+ method,
222
+ body,
223
+ request_auth=_request_auth
224
+ )
225
+
226
+ # body
227
+ if body:
228
+ body = self.sanitize_for_serialization(body)
229
+
230
+ # request url
231
+ if _host is None:
232
+ url = self.configuration.host + resource_path
233
+ else:
234
+ # use server/host defined in path or operation instead
235
+ url = _host + resource_path
236
+
237
+ # query parameters
238
+ if query_params:
239
+ query_params = self.sanitize_for_serialization(query_params)
240
+ url_query = self.parameters_to_url_query(
241
+ query_params,
242
+ collection_formats
243
+ )
244
+ url += "?" + url_query
245
+
246
+ return method, url, header_params, body, post_params
247
+
248
+
249
+ def call_api(
250
+ self,
251
+ method,
252
+ url,
253
+ header_params=None,
254
+ body=None,
255
+ post_params=None,
256
+ _request_timeout=None
257
+ ) -> rest.RESTResponse:
258
+ """Makes the HTTP request (synchronous)
259
+ :param method: Method to call.
260
+ :param url: Path to method endpoint.
261
+ :param header_params: Header parameters to be
262
+ placed in the request header.
263
+ :param body: Request body.
264
+ :param post_params dict: Request post form parameters,
265
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
266
+ :param _request_timeout: timeout setting for this request.
267
+ :return: RESTResponse
268
+ """
269
+
270
+ try:
271
+ # perform request and return response
272
+ response_data = self.rest_client.request(
273
+ method, url,
274
+ headers=header_params,
275
+ body=body, post_params=post_params,
276
+ _request_timeout=_request_timeout
277
+ )
278
+
279
+ except ApiException as e:
280
+ raise e
281
+
282
+ return response_data
283
+
284
+ def response_deserialize(
285
+ self,
286
+ response_data: rest.RESTResponse,
287
+ response_types_map: Optional[Dict[str, ApiResponseT]]=None
288
+ ) -> ApiResponse[ApiResponseT]:
289
+ """Deserializes response into an object.
290
+ :param response_data: RESTResponse object to be deserialized.
291
+ :param response_types_map: dict of response types.
292
+ :return: ApiResponse
293
+ """
294
+
295
+ msg = "RESTResponse.read() must be called before passing it to response_deserialize()"
296
+ assert response_data.data is not None, msg
297
+
298
+ response_type = response_types_map.get(str(response_data.status), None)
299
+ if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
300
+ # if not found, look for '1XX', '2XX', etc.
301
+ response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
302
+
303
+ # deserialize response data
304
+ response_text = None
305
+ return_data = None
306
+ try:
307
+ if response_type == "bytearray":
308
+ return_data = response_data.data
309
+ elif response_type == "file":
310
+ return_data = self.__deserialize_file(response_data)
311
+ elif response_type is not None:
312
+ match = None
313
+ content_type = response_data.getheader('content-type')
314
+ if content_type is not None:
315
+ match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
316
+ encoding = match.group(1) if match else "utf-8"
317
+ response_text = response_data.data.decode(encoding)
318
+ if response_type in ["bytearray", "str"]:
319
+ return_data = self.__deserialize_primitive(response_text, response_type)
320
+ else:
321
+ return_data = self.deserialize(response_text, response_type)
322
+ finally:
323
+ if not 200 <= response_data.status <= 299:
324
+ raise ApiException.from_response(
325
+ http_resp=response_data,
326
+ body=response_text,
327
+ data=return_data,
328
+ )
329
+
330
+ return ApiResponse(
331
+ status_code = response_data.status,
332
+ data = return_data,
333
+ headers = response_data.getheaders(),
334
+ raw_data = response_data.data
335
+ )
336
+
337
+ def sanitize_for_serialization(self, obj):
338
+ """Builds a JSON POST object.
339
+
340
+ If obj is None, return None.
341
+ If obj is SecretStr, return obj.get_secret_value()
342
+ If obj is str, int, long, float, bool, return directly.
343
+ If obj is datetime.datetime, datetime.date
344
+ convert to string in iso8601 format.
345
+ If obj is list, sanitize each element in the list.
346
+ If obj is dict, return the dict.
347
+ If obj is OpenAPI model, return the properties dict.
348
+
349
+ :param obj: The data to serialize.
350
+ :return: The serialized form of data.
351
+ """
352
+ if obj is None:
353
+ return None
354
+ elif isinstance(obj, SecretStr):
355
+ return obj.get_secret_value()
356
+ elif isinstance(obj, self.PRIMITIVE_TYPES):
357
+ return obj
358
+ elif isinstance(obj, list):
359
+ return [
360
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
361
+ ]
362
+ elif isinstance(obj, tuple):
363
+ return tuple(
364
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
365
+ )
366
+ elif isinstance(obj, (datetime.datetime, datetime.date)):
367
+ return obj.isoformat()
368
+
369
+ elif isinstance(obj, dict):
370
+ obj_dict = obj
371
+ else:
372
+ # Convert model obj to dict except
373
+ # attributes `openapi_types`, `attribute_map`
374
+ # and attributes which value is not None.
375
+ # Convert attribute name to json key in
376
+ # model definition for request.
377
+ if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
378
+ obj_dict = obj.to_dict()
379
+ else:
380
+ obj_dict = obj.__dict__
381
+
382
+ return {
383
+ key: self.sanitize_for_serialization(val)
384
+ for key, val in obj_dict.items()
385
+ }
386
+
387
+ def deserialize(self, response_text, response_type):
388
+ """Deserializes response into an object.
389
+
390
+ :param response: RESTResponse object to be deserialized.
391
+ :param response_type: class literal for
392
+ deserialized object, or string of class name.
393
+
394
+ :return: deserialized object.
395
+ """
396
+
397
+ # fetch data from response object
398
+ try:
399
+ data = json.loads(response_text)
400
+ except ValueError:
401
+ data = response_text
402
+
403
+ return self.__deserialize(data, response_type)
404
+
405
+ def __deserialize(self, data, klass):
406
+ """Deserializes dict, list, str into an object.
407
+
408
+ :param data: dict, list or str.
409
+ :param klass: class literal, or string of class name.
410
+
411
+ :return: object.
412
+ """
413
+ if data is None:
414
+ return None
415
+
416
+ if isinstance(klass, str):
417
+ if klass.startswith('List['):
418
+ m = re.match(r'List\[(.*)]', klass)
419
+ assert m is not None, "Malformed List type definition"
420
+ sub_kls = m.group(1)
421
+ return [self.__deserialize(sub_data, sub_kls)
422
+ for sub_data in data]
423
+
424
+ if klass.startswith('Dict['):
425
+ m = re.match(r'Dict\[([^,]*), (.*)]', klass)
426
+ assert m is not None, "Malformed Dict type definition"
427
+ sub_kls = m.group(2)
428
+ return {k: self.__deserialize(v, sub_kls)
429
+ for k, v in data.items()}
430
+
431
+ # convert str to class
432
+ if klass in self.NATIVE_TYPES_MAPPING:
433
+ klass = self.NATIVE_TYPES_MAPPING[klass]
434
+ else:
435
+ klass = getattr(pluggy_sdk.models, klass)
436
+
437
+ if klass in self.PRIMITIVE_TYPES:
438
+ return self.__deserialize_primitive(data, klass)
439
+ elif klass == object:
440
+ return self.__deserialize_object(data)
441
+ elif klass == datetime.date:
442
+ return self.__deserialize_date(data)
443
+ elif klass == datetime.datetime:
444
+ return self.__deserialize_datetime(data)
445
+ elif issubclass(klass, Enum):
446
+ return self.__deserialize_enum(data, klass)
447
+ else:
448
+ return self.__deserialize_model(data, klass)
449
+
450
+ def parameters_to_tuples(self, params, collection_formats):
451
+ """Get parameters as list of tuples, formatting collections.
452
+
453
+ :param params: Parameters as dict or list of two-tuples
454
+ :param dict collection_formats: Parameter collection formats
455
+ :return: Parameters as list of tuples, collections formatted
456
+ """
457
+ new_params: List[Tuple[str, str]] = []
458
+ if collection_formats is None:
459
+ collection_formats = {}
460
+ for k, v in params.items() if isinstance(params, dict) else params:
461
+ if k in collection_formats:
462
+ collection_format = collection_formats[k]
463
+ if collection_format == 'multi':
464
+ new_params.extend((k, value) for value in v)
465
+ else:
466
+ if collection_format == 'ssv':
467
+ delimiter = ' '
468
+ elif collection_format == 'tsv':
469
+ delimiter = '\t'
470
+ elif collection_format == 'pipes':
471
+ delimiter = '|'
472
+ else: # csv is the default
473
+ delimiter = ','
474
+ new_params.append(
475
+ (k, delimiter.join(str(value) for value in v)))
476
+ else:
477
+ new_params.append((k, v))
478
+ return new_params
479
+
480
+ def parameters_to_url_query(self, params, collection_formats):
481
+ """Get parameters as list of tuples, formatting collections.
482
+
483
+ :param params: Parameters as dict or list of two-tuples
484
+ :param dict collection_formats: Parameter collection formats
485
+ :return: URL query string (e.g. a=Hello%20World&b=123)
486
+ """
487
+ new_params: List[Tuple[str, str]] = []
488
+ if collection_formats is None:
489
+ collection_formats = {}
490
+ for k, v in params.items() if isinstance(params, dict) else params:
491
+ if isinstance(v, bool):
492
+ v = str(v).lower()
493
+ if isinstance(v, (int, float)):
494
+ v = str(v)
495
+ if isinstance(v, dict):
496
+ v = json.dumps(v)
497
+
498
+ if k in collection_formats:
499
+ collection_format = collection_formats[k]
500
+ if collection_format == 'multi':
501
+ new_params.extend((k, str(value)) for value in v)
502
+ else:
503
+ if collection_format == 'ssv':
504
+ delimiter = ' '
505
+ elif collection_format == 'tsv':
506
+ delimiter = '\t'
507
+ elif collection_format == 'pipes':
508
+ delimiter = '|'
509
+ else: # csv is the default
510
+ delimiter = ','
511
+ new_params.append(
512
+ (k, delimiter.join(quote(str(value)) for value in v))
513
+ )
514
+ else:
515
+ new_params.append((k, quote(str(v))))
516
+
517
+ return "&".join(["=".join(map(str, item)) for item in new_params])
518
+
519
+ def files_parameters(self, files: Dict[str, Union[str, bytes]]):
520
+ """Builds form parameters.
521
+
522
+ :param files: File parameters.
523
+ :return: Form parameters with files.
524
+ """
525
+ params = []
526
+ for k, v in files.items():
527
+ if isinstance(v, str):
528
+ with open(v, 'rb') as f:
529
+ filename = os.path.basename(f.name)
530
+ filedata = f.read()
531
+ elif isinstance(v, bytes):
532
+ filename = k
533
+ filedata = v
534
+ else:
535
+ raise ValueError("Unsupported file value")
536
+ mimetype = (
537
+ mimetypes.guess_type(filename)[0]
538
+ or 'application/octet-stream'
539
+ )
540
+ params.append(
541
+ tuple([k, tuple([filename, filedata, mimetype])])
542
+ )
543
+ return params
544
+
545
+ def select_header_accept(self, accepts: List[str]) -> Optional[str]:
546
+ """Returns `Accept` based on an array of accepts provided.
547
+
548
+ :param accepts: List of headers.
549
+ :return: Accept (e.g. application/json).
550
+ """
551
+ if not accepts:
552
+ return None
553
+
554
+ for accept in accepts:
555
+ if re.search('json', accept, re.IGNORECASE):
556
+ return accept
557
+
558
+ return accepts[0]
559
+
560
+ def select_header_content_type(self, content_types):
561
+ """Returns `Content-Type` based on an array of content_types provided.
562
+
563
+ :param content_types: List of content-types.
564
+ :return: Content-Type (e.g. application/json).
565
+ """
566
+ if not content_types:
567
+ return None
568
+
569
+ for content_type in content_types:
570
+ if re.search('json', content_type, re.IGNORECASE):
571
+ return content_type
572
+
573
+ return content_types[0]
574
+
575
+ def update_params_for_auth(
576
+ self,
577
+ headers,
578
+ queries,
579
+ auth_settings,
580
+ resource_path,
581
+ method,
582
+ body,
583
+ request_auth=None
584
+ ) -> None:
585
+ """Updates header and query params based on authentication setting.
586
+
587
+ :param headers: Header parameters dict to be updated.
588
+ :param queries: Query parameters tuple list to be updated.
589
+ :param auth_settings: Authentication setting identifiers list.
590
+ :resource_path: A string representation of the HTTP request resource path.
591
+ :method: A string representation of the HTTP request method.
592
+ :body: A object representing the body of the HTTP request.
593
+ The object type is the return value of sanitize_for_serialization().
594
+ :param request_auth: if set, the provided settings will
595
+ override the token in the configuration.
596
+ """
597
+ if not auth_settings:
598
+ return
599
+
600
+ if request_auth:
601
+ self._apply_auth_params(
602
+ headers,
603
+ queries,
604
+ resource_path,
605
+ method,
606
+ body,
607
+ request_auth
608
+ )
609
+ else:
610
+ for auth in auth_settings:
611
+ auth_setting = self.configuration.auth_settings().get(auth)
612
+ if auth_setting:
613
+ self._apply_auth_params(
614
+ headers,
615
+ queries,
616
+ resource_path,
617
+ method,
618
+ body,
619
+ auth_setting
620
+ )
621
+
622
+ def _apply_auth_params(
623
+ self,
624
+ headers,
625
+ queries,
626
+ resource_path,
627
+ method,
628
+ body,
629
+ auth_setting
630
+ ) -> None:
631
+ """Updates the request parameters based on a single auth_setting
632
+
633
+ :param headers: Header parameters dict to be updated.
634
+ :param queries: Query parameters tuple list to be updated.
635
+ :resource_path: A string representation of the HTTP request resource path.
636
+ :method: A string representation of the HTTP request method.
637
+ :body: A object representing the body of the HTTP request.
638
+ The object type is the return value of sanitize_for_serialization().
639
+ :param auth_setting: auth settings for the endpoint
640
+ """
641
+ if auth_setting['in'] == 'cookie':
642
+ headers['Cookie'] = auth_setting['value']
643
+ elif auth_setting['in'] == 'header':
644
+ if auth_setting['type'] != 'http-signature':
645
+ headers[auth_setting['key']] = auth_setting['value']
646
+ elif auth_setting['in'] == 'query':
647
+ queries.append((auth_setting['key'], auth_setting['value']))
648
+ else:
649
+ raise ApiValueError(
650
+ 'Authentication token must be in `query` or `header`'
651
+ )
652
+
653
+ def __deserialize_file(self, response):
654
+ """Deserializes body to file
655
+
656
+ Saves response body into a file in a temporary folder,
657
+ using the filename from the `Content-Disposition` header if provided.
658
+
659
+ handle file downloading
660
+ save response body into a tmp file and return the instance
661
+
662
+ :param response: RESTResponse.
663
+ :return: file path.
664
+ """
665
+ fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
666
+ os.close(fd)
667
+ os.remove(path)
668
+
669
+ content_disposition = response.getheader("Content-Disposition")
670
+ if content_disposition:
671
+ m = re.search(
672
+ r'filename=[\'"]?([^\'"\s]+)[\'"]?',
673
+ content_disposition
674
+ )
675
+ assert m is not None, "Unexpected 'content-disposition' header value"
676
+ filename = m.group(1)
677
+ path = os.path.join(os.path.dirname(path), filename)
678
+
679
+ with open(path, "wb") as f:
680
+ f.write(response.data)
681
+
682
+ return path
683
+
684
+ def __deserialize_primitive(self, data, klass):
685
+ """Deserializes string to primitive type.
686
+
687
+ :param data: str.
688
+ :param klass: class literal.
689
+
690
+ :return: int, long, float, str, bool.
691
+ """
692
+ try:
693
+ return klass(data)
694
+ except UnicodeEncodeError:
695
+ return str(data)
696
+ except TypeError:
697
+ return data
698
+
699
+ def __deserialize_object(self, value):
700
+ """Return an original value.
701
+
702
+ :return: object.
703
+ """
704
+ return value
705
+
706
+ def __deserialize_date(self, string):
707
+ """Deserializes string to date.
708
+
709
+ :param string: str.
710
+ :return: date.
711
+ """
712
+ try:
713
+ return parse(string).date()
714
+ except ImportError:
715
+ return string
716
+ except ValueError:
717
+ raise rest.ApiException(
718
+ status=0,
719
+ reason="Failed to parse `{0}` as date object".format(string)
720
+ )
721
+
722
+ def __deserialize_datetime(self, string):
723
+ """Deserializes string to datetime.
724
+
725
+ The string should be in iso8601 datetime format.
726
+
727
+ :param string: str.
728
+ :return: datetime.
729
+ """
730
+ try:
731
+ return parse(string)
732
+ except ImportError:
733
+ return string
734
+ except ValueError:
735
+ raise rest.ApiException(
736
+ status=0,
737
+ reason=(
738
+ "Failed to parse `{0}` as datetime object"
739
+ .format(string)
740
+ )
741
+ )
742
+
743
+ def __deserialize_enum(self, data, klass):
744
+ """Deserializes primitive type to enum.
745
+
746
+ :param data: primitive type.
747
+ :param klass: class literal.
748
+ :return: enum value.
749
+ """
750
+ try:
751
+ return klass(data)
752
+ except ValueError:
753
+ raise rest.ApiException(
754
+ status=0,
755
+ reason=(
756
+ "Failed to parse `{0}` as `{1}`"
757
+ .format(data, klass)
758
+ )
759
+ )
760
+
761
+ def __deserialize_model(self, data, klass):
762
+ """Deserializes list or dict to model.
763
+
764
+ :param data: dict, list.
765
+ :param klass: class literal.
766
+ :return: model object.
767
+ """
768
+
769
+ return klass.from_dict(data)