pluggy-sdk 1.0.0.post34__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.
- pluggy_sdk/__init__.py +200 -0
- pluggy_sdk/api/__init__.py +25 -0
- pluggy_sdk/api/account_api.py +588 -0
- pluggy_sdk/api/acquirer_anticipation_api.py +664 -0
- pluggy_sdk/api/acquirer_receivable_api.py +664 -0
- pluggy_sdk/api/acquirer_sale_api.py +664 -0
- pluggy_sdk/api/auth_api.py +605 -0
- pluggy_sdk/api/benefit_api.py +567 -0
- pluggy_sdk/api/bill_api.py +567 -0
- pluggy_sdk/api/bulk_payment_api.py +1127 -0
- pluggy_sdk/api/category_api.py +1096 -0
- pluggy_sdk/api/connector_api.py +979 -0
- pluggy_sdk/api/consent_api.py +576 -0
- pluggy_sdk/api/identity_api.py +581 -0
- pluggy_sdk/api/income_report_api.py +311 -0
- pluggy_sdk/api/investment_api.py +918 -0
- pluggy_sdk/api/items_api.py +1456 -0
- pluggy_sdk/api/loan_api.py +567 -0
- pluggy_sdk/api/payment_customer_api.py +1414 -0
- pluggy_sdk/api/payment_intent_api.py +842 -0
- pluggy_sdk/api/payment_receipts_api.py +842 -0
- pluggy_sdk/api/payment_recipient_api.py +1997 -0
- pluggy_sdk/api/payment_request_api.py +2739 -0
- pluggy_sdk/api/payment_schedule_api.py +823 -0
- pluggy_sdk/api/payroll_loan_api.py +561 -0
- pluggy_sdk/api/portfolio_yield_api.py +580 -0
- pluggy_sdk/api/smart_account_api.py +1704 -0
- pluggy_sdk/api/smart_account_transfer_api.py +610 -0
- pluggy_sdk/api/smart_transfer_api.py +1406 -0
- pluggy_sdk/api/transaction_api.py +963 -0
- pluggy_sdk/api/webhook_api.py +1406 -0
- pluggy_sdk/api_client.py +798 -0
- pluggy_sdk/api_response.py +21 -0
- pluggy_sdk/configuration.py +596 -0
- pluggy_sdk/exceptions.py +217 -0
- pluggy_sdk/models/__init__.py +163 -0
- pluggy_sdk/models/account.py +134 -0
- pluggy_sdk/models/accounts_list200_response.py +102 -0
- pluggy_sdk/models/acquirer_anticipation.py +117 -0
- pluggy_sdk/models/acquirer_anticipation_data.py +101 -0
- pluggy_sdk/models/acquirer_data.py +113 -0
- pluggy_sdk/models/acquirer_receivable.py +143 -0
- pluggy_sdk/models/acquirer_receivable_data.py +108 -0
- pluggy_sdk/models/acquirer_receivable_data_establishment.py +96 -0
- pluggy_sdk/models/acquirer_receivable_destination_account.py +92 -0
- pluggy_sdk/models/acquirer_receivable_related_sale.py +99 -0
- pluggy_sdk/models/acquirer_sale.py +171 -0
- pluggy_sdk/models/acquirer_sale_data.py +150 -0
- pluggy_sdk/models/acquirer_sale_installment.py +93 -0
- pluggy_sdk/models/acquirer_sale_installment_data.py +95 -0
- pluggy_sdk/models/address.py +110 -0
- pluggy_sdk/models/aggregated_portfolio.py +120 -0
- pluggy_sdk/models/aggregated_portfolio_response.py +102 -0
- pluggy_sdk/models/asset_distribution.py +88 -0
- pluggy_sdk/models/auth_request.py +90 -0
- pluggy_sdk/models/auth_response.py +88 -0
- pluggy_sdk/models/bank_data.py +92 -0
- pluggy_sdk/models/benefit_loan.py +121 -0
- pluggy_sdk/models/benefit_loan_client.py +102 -0
- pluggy_sdk/models/benefit_response.py +118 -0
- pluggy_sdk/models/benefit_response_paying_institution.py +94 -0
- pluggy_sdk/models/benefits_list200_response.py +102 -0
- pluggy_sdk/models/bill.py +109 -0
- pluggy_sdk/models/bill_finance_charge.py +103 -0
- pluggy_sdk/models/bills_list200_response.py +102 -0
- pluggy_sdk/models/boleto.py +121 -0
- pluggy_sdk/models/boleto_payer.py +90 -0
- pluggy_sdk/models/boleto_recipient.py +90 -0
- pluggy_sdk/models/bulk_payment.py +128 -0
- pluggy_sdk/models/bulk_payments_list200_response.py +102 -0
- pluggy_sdk/models/category.py +96 -0
- pluggy_sdk/models/client_category_rule.py +98 -0
- pluggy_sdk/models/company.py +90 -0
- pluggy_sdk/models/connect_token_request.py +94 -0
- pluggy_sdk/models/connect_token_response.py +88 -0
- pluggy_sdk/models/connector.py +145 -0
- pluggy_sdk/models/connector_credential.py +121 -0
- pluggy_sdk/models/connector_health.py +96 -0
- pluggy_sdk/models/connector_health_details.py +90 -0
- pluggy_sdk/models/connector_list_response.py +102 -0
- pluggy_sdk/models/connector_user_action.py +93 -0
- pluggy_sdk/models/consent.py +120 -0
- pluggy_sdk/models/create_boleto_payment_request.py +98 -0
- pluggy_sdk/models/create_bulk_payment.py +96 -0
- pluggy_sdk/models/create_client_category_rule.py +96 -0
- pluggy_sdk/models/create_item.py +115 -0
- pluggy_sdk/models/create_item_parameters.py +144 -0
- pluggy_sdk/models/create_or_update_payment_customer.py +105 -0
- pluggy_sdk/models/create_payment_customer_request_body.py +103 -0
- pluggy_sdk/models/create_payment_intent.py +110 -0
- pluggy_sdk/models/create_payment_recipient.py +104 -0
- pluggy_sdk/models/create_payment_request.py +115 -0
- pluggy_sdk/models/create_payment_request_schedule.py +189 -0
- pluggy_sdk/models/create_pix_qr_payment_request.py +96 -0
- pluggy_sdk/models/create_smart_account_request.py +104 -0
- pluggy_sdk/models/create_smart_account_transfer_request.py +92 -0
- pluggy_sdk/models/create_smart_transfer_payment.py +96 -0
- pluggy_sdk/models/create_smart_transfer_preauthorization.py +104 -0
- pluggy_sdk/models/create_webhook.py +99 -0
- pluggy_sdk/models/credential_select_option.py +90 -0
- pluggy_sdk/models/credit_card_metadata.py +101 -0
- pluggy_sdk/models/credit_data.py +127 -0
- pluggy_sdk/models/custom.py +100 -0
- pluggy_sdk/models/daily.py +101 -0
- pluggy_sdk/models/document.py +100 -0
- pluggy_sdk/models/email.py +100 -0
- pluggy_sdk/models/global_error_response.py +94 -0
- pluggy_sdk/models/i_count_response.py +88 -0
- pluggy_sdk/models/identity_relation.py +102 -0
- pluggy_sdk/models/identity_response.py +173 -0
- pluggy_sdk/models/identity_response_financial_relationships.py +111 -0
- pluggy_sdk/models/identity_response_financial_relationships_accounts_inner.py +98 -0
- pluggy_sdk/models/identity_response_financial_relationships_procurators_inner.py +101 -0
- pluggy_sdk/models/identity_response_qualifications.py +112 -0
- pluggy_sdk/models/identity_response_qualifications_informed_income.py +100 -0
- pluggy_sdk/models/identity_response_qualifications_informed_patrimony.py +90 -0
- pluggy_sdk/models/income_report.py +90 -0
- pluggy_sdk/models/income_reports_response.py +102 -0
- pluggy_sdk/models/investment.py +192 -0
- pluggy_sdk/models/investment_expenses.py +108 -0
- pluggy_sdk/models/investment_metadata.py +100 -0
- pluggy_sdk/models/investment_transaction.py +124 -0
- pluggy_sdk/models/investments_list200_response.py +102 -0
- pluggy_sdk/models/item.py +150 -0
- pluggy_sdk/models/item_creation_error_response.py +102 -0
- pluggy_sdk/models/item_error.py +94 -0
- pluggy_sdk/models/item_options.py +94 -0
- pluggy_sdk/models/loan.py +199 -0
- pluggy_sdk/models/loan_contracted_fee.py +118 -0
- pluggy_sdk/models/loan_contracted_finance_charge.py +92 -0
- pluggy_sdk/models/loan_installment_balloon_payment.py +95 -0
- pluggy_sdk/models/loan_installment_balloon_payment_amount.py +90 -0
- pluggy_sdk/models/loan_installments.py +130 -0
- pluggy_sdk/models/loan_interest_rate.py +136 -0
- pluggy_sdk/models/loan_payment_release.py +103 -0
- pluggy_sdk/models/loan_payment_release_over_parcel.py +106 -0
- pluggy_sdk/models/loan_payment_release_over_parcel_charge.py +92 -0
- pluggy_sdk/models/loan_payment_release_over_parcel_fee.py +92 -0
- pluggy_sdk/models/loan_payments.py +98 -0
- pluggy_sdk/models/loan_warranty.py +94 -0
- pluggy_sdk/models/loans_list200_response.py +102 -0
- pluggy_sdk/models/merchant.py +96 -0
- pluggy_sdk/models/monthly.py +103 -0
- pluggy_sdk/models/monthly_portfolio.py +100 -0
- pluggy_sdk/models/monthly_portfolio_response.py +102 -0
- pluggy_sdk/models/not_authenticated_response.py +90 -0
- pluggy_sdk/models/page_response_acquirer_anticipations.py +102 -0
- pluggy_sdk/models/page_response_acquirer_receivables.py +102 -0
- pluggy_sdk/models/page_response_acquirer_sales.py +102 -0
- pluggy_sdk/models/page_response_category_rules.py +102 -0
- pluggy_sdk/models/page_response_consents.py +102 -0
- pluggy_sdk/models/page_response_investment_transactions.py +102 -0
- pluggy_sdk/models/page_response_transactions.py +102 -0
- pluggy_sdk/models/parameter_validation_error.py +92 -0
- pluggy_sdk/models/parameter_validation_response.py +98 -0
- pluggy_sdk/models/payment_customer.py +105 -0
- pluggy_sdk/models/payment_customers_list200_response.py +102 -0
- pluggy_sdk/models/payment_data.py +111 -0
- pluggy_sdk/models/payment_data_boleto_metadata.py +98 -0
- pluggy_sdk/models/payment_data_participant.py +102 -0
- pluggy_sdk/models/payment_institution.py +101 -0
- pluggy_sdk/models/payment_intent.py +145 -0
- pluggy_sdk/models/payment_intent_parameter.py +90 -0
- pluggy_sdk/models/payment_intents_list200_response.py +102 -0
- pluggy_sdk/models/payment_receipt.py +120 -0
- pluggy_sdk/models/payment_receipt_bank_account.py +92 -0
- pluggy_sdk/models/payment_receipt_person.py +96 -0
- pluggy_sdk/models/payment_recipient.py +110 -0
- pluggy_sdk/models/payment_recipient_account.py +92 -0
- pluggy_sdk/models/payment_recipients_institution_list200_response.py +102 -0
- pluggy_sdk/models/payment_recipients_list200_response.py +102 -0
- pluggy_sdk/models/payment_request.py +132 -0
- pluggy_sdk/models/payment_request_callback_urls.py +92 -0
- pluggy_sdk/models/payment_request_receipt_list200_response.py +102 -0
- pluggy_sdk/models/payment_request_schedule.py +183 -0
- pluggy_sdk/models/payment_requests_list200_response.py +102 -0
- pluggy_sdk/models/payment_schedules_list200_response.py +102 -0
- pluggy_sdk/models/payroll_loan.py +121 -0
- pluggy_sdk/models/payroll_loan_client.py +102 -0
- pluggy_sdk/models/payroll_loan_response.py +125 -0
- pluggy_sdk/models/payroll_loan_response_client.py +102 -0
- pluggy_sdk/models/payroll_loans_list200_response.py +102 -0
- pluggy_sdk/models/percentage_over_index.py +90 -0
- pluggy_sdk/models/phone_number.py +100 -0
- pluggy_sdk/models/pix_data.py +90 -0
- pluggy_sdk/models/schedule_payment.py +102 -0
- pluggy_sdk/models/schedule_type_custom.py +100 -0
- pluggy_sdk/models/schedule_type_daily.py +101 -0
- pluggy_sdk/models/schedule_type_monthly.py +103 -0
- pluggy_sdk/models/schedule_type_single.py +98 -0
- pluggy_sdk/models/schedule_type_weekly.py +110 -0
- pluggy_sdk/models/single.py +98 -0
- pluggy_sdk/models/smart_account.py +107 -0
- pluggy_sdk/models/smart_account_address.py +112 -0
- pluggy_sdk/models/smart_account_balance.py +95 -0
- pluggy_sdk/models/smart_account_transfer.py +123 -0
- pluggy_sdk/models/smart_accounts_list200_response.py +102 -0
- pluggy_sdk/models/smart_tranfers_preauthorizations_list200_response.py +102 -0
- pluggy_sdk/models/smart_transfer_callback_urls.py +90 -0
- pluggy_sdk/models/smart_transfer_payment.py +116 -0
- pluggy_sdk/models/smart_transfer_preauthorization.py +128 -0
- pluggy_sdk/models/smart_transfer_preauthorization_parameter.py +90 -0
- pluggy_sdk/models/status_detail.py +127 -0
- pluggy_sdk/models/status_detail_product.py +101 -0
- pluggy_sdk/models/status_detail_product_warning.py +92 -0
- pluggy_sdk/models/transaction.py +141 -0
- pluggy_sdk/models/update_item.py +109 -0
- pluggy_sdk/models/update_item_parameters.py +144 -0
- pluggy_sdk/models/update_payment_recipient.py +102 -0
- pluggy_sdk/models/update_payment_request.py +102 -0
- pluggy_sdk/models/update_transaction.py +88 -0
- pluggy_sdk/models/webhook.py +106 -0
- pluggy_sdk/models/webhook_creation_error_response.py +90 -0
- pluggy_sdk/models/webhooks_list200_response.py +102 -0
- pluggy_sdk/models/weekly.py +110 -0
- pluggy_sdk/py.typed +0 -0
- pluggy_sdk/rest.py +258 -0
- pluggy_sdk-1.0.0.post34.dist-info/METADATA +373 -0
- pluggy_sdk-1.0.0.post34.dist-info/RECORD +221 -0
- pluggy_sdk-1.0.0.post34.dist-info/WHEEL +5 -0
- pluggy_sdk-1.0.0.post34.dist-info/top_level.txt +1 -0
@@ -0,0 +1,110 @@
|
|
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
|
+
from __future__ import annotations
|
17
|
+
import pprint
|
18
|
+
import re # noqa: F401
|
19
|
+
import json
|
20
|
+
|
21
|
+
from datetime import date
|
22
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
23
|
+
from typing import Any, ClassVar, Dict, List, Optional, Union
|
24
|
+
from typing_extensions import Annotated
|
25
|
+
from typing import Optional, Set
|
26
|
+
from typing_extensions import Self
|
27
|
+
|
28
|
+
class WEEKLY(BaseModel):
|
29
|
+
"""
|
30
|
+
Schedule atribute to generate weekly payments
|
31
|
+
""" # noqa: E501
|
32
|
+
type: StrictStr = Field(description="Scheduled type")
|
33
|
+
start_date: date = Field(description="The start date of the validity of the scheduled payment authorization.", alias="startDate")
|
34
|
+
day_of_week: StrictStr = Field(description="Day of the week on which each payment will occur. For instance, if set to 'MONDAY', the first payment will occur on the first monday after the startDate (or the same day, if it is already monday), and every monday after that.", alias="dayOfWeek")
|
35
|
+
occurrences: Optional[Union[Annotated[float, Field(le=59, strict=True, ge=3)], Annotated[int, Field(le=59, strict=True, ge=3)]]] = Field(default=None, description="Under the specified schedule frequency, how many payments will be scheduled to occur.")
|
36
|
+
__properties: ClassVar[List[str]] = ["type", "startDate", "dayOfWeek", "occurrences"]
|
37
|
+
|
38
|
+
@field_validator('type')
|
39
|
+
def type_validate_enum(cls, value):
|
40
|
+
"""Validates the enum"""
|
41
|
+
if value not in set(['WEEKLY']):
|
42
|
+
raise ValueError("must be one of enum values ('WEEKLY')")
|
43
|
+
return value
|
44
|
+
|
45
|
+
@field_validator('day_of_week')
|
46
|
+
def day_of_week_validate_enum(cls, value):
|
47
|
+
"""Validates the enum"""
|
48
|
+
if value not in set(['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURDSAY', 'FRIDAY', 'SATURDAY', 'SUNDAY']):
|
49
|
+
raise ValueError("must be one of enum values ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURDSAY', 'FRIDAY', 'SATURDAY', 'SUNDAY')")
|
50
|
+
return value
|
51
|
+
|
52
|
+
model_config = ConfigDict(
|
53
|
+
populate_by_name=True,
|
54
|
+
validate_assignment=True,
|
55
|
+
protected_namespaces=(),
|
56
|
+
)
|
57
|
+
|
58
|
+
|
59
|
+
def to_str(self) -> str:
|
60
|
+
"""Returns the string representation of the model using alias"""
|
61
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
62
|
+
|
63
|
+
def to_json(self) -> str:
|
64
|
+
"""Returns the JSON representation of the model using alias"""
|
65
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
66
|
+
return json.dumps(self.to_dict())
|
67
|
+
|
68
|
+
@classmethod
|
69
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
70
|
+
"""Create an instance of WEEKLY from a JSON string"""
|
71
|
+
return cls.from_dict(json.loads(json_str))
|
72
|
+
|
73
|
+
def to_dict(self) -> Dict[str, Any]:
|
74
|
+
"""Return the dictionary representation of the model using alias.
|
75
|
+
|
76
|
+
This has the following differences from calling pydantic's
|
77
|
+
`self.model_dump(by_alias=True)`:
|
78
|
+
|
79
|
+
* `None` is only added to the output dict for nullable fields that
|
80
|
+
were set at model initialization. Other fields with value `None`
|
81
|
+
are ignored.
|
82
|
+
"""
|
83
|
+
excluded_fields: Set[str] = set([
|
84
|
+
])
|
85
|
+
|
86
|
+
_dict = self.model_dump(
|
87
|
+
by_alias=True,
|
88
|
+
exclude=excluded_fields,
|
89
|
+
exclude_none=True,
|
90
|
+
)
|
91
|
+
return _dict
|
92
|
+
|
93
|
+
@classmethod
|
94
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
95
|
+
"""Create an instance of WEEKLY from a dict"""
|
96
|
+
if obj is None:
|
97
|
+
return None
|
98
|
+
|
99
|
+
if not isinstance(obj, dict):
|
100
|
+
return cls.model_validate(obj)
|
101
|
+
|
102
|
+
_obj = cls.model_validate({
|
103
|
+
"type": obj.get("type"),
|
104
|
+
"startDate": obj.get("startDate"),
|
105
|
+
"dayOfWeek": obj.get("dayOfWeek"),
|
106
|
+
"occurrences": obj.get("occurrences")
|
107
|
+
})
|
108
|
+
return _obj
|
109
|
+
|
110
|
+
|
pluggy_sdk/py.typed
ADDED
File without changes
|
pluggy_sdk/rest.py
ADDED
@@ -0,0 +1,258 @@
|
|
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 io
|
17
|
+
import json
|
18
|
+
import re
|
19
|
+
import ssl
|
20
|
+
|
21
|
+
import urllib3
|
22
|
+
|
23
|
+
from pluggy_sdk.exceptions import ApiException, ApiValueError
|
24
|
+
|
25
|
+
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
26
|
+
RESTResponseType = urllib3.HTTPResponse
|
27
|
+
|
28
|
+
|
29
|
+
def is_socks_proxy_url(url):
|
30
|
+
if url is None:
|
31
|
+
return False
|
32
|
+
split_section = url.split("://")
|
33
|
+
if len(split_section) < 2:
|
34
|
+
return False
|
35
|
+
else:
|
36
|
+
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
37
|
+
|
38
|
+
|
39
|
+
class RESTResponse(io.IOBase):
|
40
|
+
|
41
|
+
def __init__(self, resp) -> None:
|
42
|
+
self.response = resp
|
43
|
+
self.status = resp.status
|
44
|
+
self.reason = resp.reason
|
45
|
+
self.data = None
|
46
|
+
|
47
|
+
def read(self):
|
48
|
+
if self.data is None:
|
49
|
+
self.data = self.response.data
|
50
|
+
return self.data
|
51
|
+
|
52
|
+
def getheaders(self):
|
53
|
+
"""Returns a dictionary of the response headers."""
|
54
|
+
return self.response.headers
|
55
|
+
|
56
|
+
def getheader(self, name, default=None):
|
57
|
+
"""Returns a given response header."""
|
58
|
+
return self.response.headers.get(name, default)
|
59
|
+
|
60
|
+
|
61
|
+
class RESTClientObject:
|
62
|
+
|
63
|
+
def __init__(self, configuration) -> None:
|
64
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
65
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
66
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
67
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
68
|
+
|
69
|
+
# cert_reqs
|
70
|
+
if configuration.verify_ssl:
|
71
|
+
cert_reqs = ssl.CERT_REQUIRED
|
72
|
+
else:
|
73
|
+
cert_reqs = ssl.CERT_NONE
|
74
|
+
|
75
|
+
pool_args = {
|
76
|
+
"cert_reqs": cert_reqs,
|
77
|
+
"ca_certs": configuration.ssl_ca_cert,
|
78
|
+
"cert_file": configuration.cert_file,
|
79
|
+
"key_file": configuration.key_file,
|
80
|
+
}
|
81
|
+
if configuration.assert_hostname is not None:
|
82
|
+
pool_args['assert_hostname'] = (
|
83
|
+
configuration.assert_hostname
|
84
|
+
)
|
85
|
+
|
86
|
+
if configuration.retries is not None:
|
87
|
+
pool_args['retries'] = configuration.retries
|
88
|
+
|
89
|
+
if configuration.tls_server_name:
|
90
|
+
pool_args['server_hostname'] = configuration.tls_server_name
|
91
|
+
|
92
|
+
|
93
|
+
if configuration.socket_options is not None:
|
94
|
+
pool_args['socket_options'] = configuration.socket_options
|
95
|
+
|
96
|
+
if configuration.connection_pool_maxsize is not None:
|
97
|
+
pool_args['maxsize'] = configuration.connection_pool_maxsize
|
98
|
+
|
99
|
+
# https pool manager
|
100
|
+
self.pool_manager: urllib3.PoolManager
|
101
|
+
|
102
|
+
if configuration.proxy:
|
103
|
+
if is_socks_proxy_url(configuration.proxy):
|
104
|
+
from urllib3.contrib.socks import SOCKSProxyManager
|
105
|
+
pool_args["proxy_url"] = configuration.proxy
|
106
|
+
pool_args["headers"] = configuration.proxy_headers
|
107
|
+
self.pool_manager = SOCKSProxyManager(**pool_args)
|
108
|
+
else:
|
109
|
+
pool_args["proxy_url"] = configuration.proxy
|
110
|
+
pool_args["proxy_headers"] = configuration.proxy_headers
|
111
|
+
self.pool_manager = urllib3.ProxyManager(**pool_args)
|
112
|
+
else:
|
113
|
+
self.pool_manager = urllib3.PoolManager(**pool_args)
|
114
|
+
|
115
|
+
def request(
|
116
|
+
self,
|
117
|
+
method,
|
118
|
+
url,
|
119
|
+
headers=None,
|
120
|
+
body=None,
|
121
|
+
post_params=None,
|
122
|
+
_request_timeout=None
|
123
|
+
):
|
124
|
+
"""Perform requests.
|
125
|
+
|
126
|
+
:param method: http request method
|
127
|
+
:param url: http request url
|
128
|
+
:param headers: http request headers
|
129
|
+
:param body: request json body, for `application/json`
|
130
|
+
:param post_params: request post parameters,
|
131
|
+
`application/x-www-form-urlencoded`
|
132
|
+
and `multipart/form-data`
|
133
|
+
:param _request_timeout: timeout setting for this request. If one
|
134
|
+
number provided, it will be total request
|
135
|
+
timeout. It can also be a pair (tuple) of
|
136
|
+
(connection, read) timeouts.
|
137
|
+
"""
|
138
|
+
method = method.upper()
|
139
|
+
assert method in [
|
140
|
+
'GET',
|
141
|
+
'HEAD',
|
142
|
+
'DELETE',
|
143
|
+
'POST',
|
144
|
+
'PUT',
|
145
|
+
'PATCH',
|
146
|
+
'OPTIONS'
|
147
|
+
]
|
148
|
+
|
149
|
+
if post_params and body:
|
150
|
+
raise ApiValueError(
|
151
|
+
"body parameter cannot be used with post_params parameter."
|
152
|
+
)
|
153
|
+
|
154
|
+
post_params = post_params or {}
|
155
|
+
headers = headers or {}
|
156
|
+
|
157
|
+
timeout = None
|
158
|
+
if _request_timeout:
|
159
|
+
if isinstance(_request_timeout, (int, float)):
|
160
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
161
|
+
elif (
|
162
|
+
isinstance(_request_timeout, tuple)
|
163
|
+
and len(_request_timeout) == 2
|
164
|
+
):
|
165
|
+
timeout = urllib3.Timeout(
|
166
|
+
connect=_request_timeout[0],
|
167
|
+
read=_request_timeout[1]
|
168
|
+
)
|
169
|
+
|
170
|
+
try:
|
171
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
172
|
+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
173
|
+
|
174
|
+
# no content type provided or payload is json
|
175
|
+
content_type = headers.get('Content-Type')
|
176
|
+
if (
|
177
|
+
not content_type
|
178
|
+
or re.search('json', content_type, re.IGNORECASE)
|
179
|
+
):
|
180
|
+
request_body = None
|
181
|
+
if body is not None:
|
182
|
+
request_body = json.dumps(body)
|
183
|
+
r = self.pool_manager.request(
|
184
|
+
method,
|
185
|
+
url,
|
186
|
+
body=request_body,
|
187
|
+
timeout=timeout,
|
188
|
+
headers=headers,
|
189
|
+
preload_content=False
|
190
|
+
)
|
191
|
+
elif content_type == 'application/x-www-form-urlencoded':
|
192
|
+
r = self.pool_manager.request(
|
193
|
+
method,
|
194
|
+
url,
|
195
|
+
fields=post_params,
|
196
|
+
encode_multipart=False,
|
197
|
+
timeout=timeout,
|
198
|
+
headers=headers,
|
199
|
+
preload_content=False
|
200
|
+
)
|
201
|
+
elif content_type == 'multipart/form-data':
|
202
|
+
# must del headers['Content-Type'], or the correct
|
203
|
+
# Content-Type which generated by urllib3 will be
|
204
|
+
# overwritten.
|
205
|
+
del headers['Content-Type']
|
206
|
+
# Ensures that dict objects are serialized
|
207
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
|
208
|
+
r = self.pool_manager.request(
|
209
|
+
method,
|
210
|
+
url,
|
211
|
+
fields=post_params,
|
212
|
+
encode_multipart=True,
|
213
|
+
timeout=timeout,
|
214
|
+
headers=headers,
|
215
|
+
preload_content=False
|
216
|
+
)
|
217
|
+
# Pass a `string` parameter directly in the body to support
|
218
|
+
# other content types than JSON when `body` argument is
|
219
|
+
# provided in serialized form.
|
220
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
221
|
+
r = self.pool_manager.request(
|
222
|
+
method,
|
223
|
+
url,
|
224
|
+
body=body,
|
225
|
+
timeout=timeout,
|
226
|
+
headers=headers,
|
227
|
+
preload_content=False
|
228
|
+
)
|
229
|
+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
230
|
+
request_body = "true" if body else "false"
|
231
|
+
r = self.pool_manager.request(
|
232
|
+
method,
|
233
|
+
url,
|
234
|
+
body=request_body,
|
235
|
+
preload_content=False,
|
236
|
+
timeout=timeout,
|
237
|
+
headers=headers)
|
238
|
+
else:
|
239
|
+
# Cannot generate the request from given parameters
|
240
|
+
msg = """Cannot prepare a request message for provided
|
241
|
+
arguments. Please check that your arguments match
|
242
|
+
declared content type."""
|
243
|
+
raise ApiException(status=0, reason=msg)
|
244
|
+
# For `GET`, `HEAD`
|
245
|
+
else:
|
246
|
+
r = self.pool_manager.request(
|
247
|
+
method,
|
248
|
+
url,
|
249
|
+
fields={},
|
250
|
+
timeout=timeout,
|
251
|
+
headers=headers,
|
252
|
+
preload_content=False
|
253
|
+
)
|
254
|
+
except urllib3.exceptions.SSLError as e:
|
255
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
256
|
+
raise ApiException(status=0, reason=msg)
|
257
|
+
|
258
|
+
return RESTResponse(r)
|