Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Known Parameters based on Endpoint #322

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions xero/basemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ class BaseManager(object):
OBJECT_DECORATED_METHODS = {
"Invoices": ["email", "online_invoice"],
}

KNOWN_PARAMETERS = {
# "Budgets": ["DateFrom", "DateTo", "IDs"],
# "Contacts": ["IDs"],
# "Invoices": [
# "ContactIDs", "createdByMyApp", "IDs", "InvoiceNumbers",
# "Statuses", "summaryOnly"],
# "Journals": ["paymentsOnly"],
# "LinkedTransactions": [
# "ContactID", "LinkedTransactionID", "SourceTransactionID",
# "Status", "TargetTransactionID"],
"PurchaseOrders": [
"DateFrom", "DateTo", "Status"],
"Quotes": [
"ContactID", "DateFrom", "DateTo", "ExpiryDateFrom",
"ExpiryDateTo", "QuoteNumber", "Status"],
# "TaxRates": ["TaxType"],
}

DATETIME_FIELDS = (
"UpdatedDateUTC",
"Updated",
Expand Down Expand Up @@ -197,7 +216,8 @@ def _get_data(self, func):
def wrapper(*args, **kwargs):
timeout = kwargs.pop("timeout", None)

uri, params, method, body, headers, singleobject = func(*args, **kwargs)
uri, params, method, body, headers, singleobject = func(
*args, **kwargs)

if headers is None:
headers = {}
Expand Down Expand Up @@ -257,7 +277,8 @@ def wrapper(*args, **kwargs):
raise XeroNotFound(response)

elif response.status_code == 429:
limit_reason = response.headers.get("X-Rate-Limit-Problem") or "unknown"
limit_reason = response.headers.get(
"X-Rate-Limit-Problem") or "unknown"
payload = {"oauth_problem": ["rate limit exceeded: " + limit_reason],
"oauth_problem_advice": ["please wait before retrying the xero api",
"The limit exceeded is: " + limit_reason]}
Expand Down Expand Up @@ -361,7 +382,8 @@ def _put_attachment_data(
"""Upload an attachment to the Xero object."""
uri = "/".join([self.base_url, self.name, id, "Attachments", filename])
params = {"IncludeOnline": "true"} if include_online else {}
headers = {"Content-Type": content_type, "Content-Length": str(len(data))}
headers = {"Content-Type": content_type,
"Content-Length": str(len(data))}
return uri, params, "put", data, headers, False

def put_attachment(self, id, filename, file, content_type, include_online=False):
Expand Down Expand Up @@ -430,7 +452,9 @@ def generate_param(key, value):
return fmt % (field, get_filter_params(key, value))

# Move any known parameter names to the query string
KNOWN_PARAMETERS = ["order", "offset", "page", "includeArchived"]
KNOWN_PARAMETERS = ["order", "offset", "page",
"includeArchived"] + self.KNOWN_PARAMETERS[self.name]

for param in KNOWN_PARAMETERS:
if param in kwargs:
params[param] = kwargs.pop(param)
Expand Down