Skip to content

Commit

Permalink
lint project with black to match pep8
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Vieira <[email protected]>
  • Loading branch information
Bruno Vieira committed Oct 3, 2023
1 parent f93dacd commit 009d7ca
Show file tree
Hide file tree
Showing 51 changed files with 1,434 additions and 1,449 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[flake8]
ignore = E501,W503
exclude = __init__.py
max-line-length = 100
8 changes: 4 additions & 4 deletions chartmogul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
:license: MIT, see LICENSE for more details.
"""

__title__ = 'chartmogul'
__title__ = "chartmogul"
__build__ = 0x000000
__author__ = 'ChartMogul Ltd'
__license__ = 'MIT'
__copyright__ = 'Copyright 2023 ChartMogul Ltd'
__author__ = "ChartMogul Ltd"
__license__ = "MIT"
__copyright__ = "Copyright 2023 ChartMogul Ltd"
1 change: 0 additions & 1 deletion chartmogul/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

# api module is imported directly into chartmogul namespace for users' convenience.
1 change: 1 addition & 0 deletions chartmogul/api/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Account(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#account
"""

_path = "/account"

class _Schema(Schema):
Expand Down
16 changes: 9 additions & 7 deletions chartmogul/api/activities_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class ExportParams(DataObject):

class _Schema(Schema):
kind = fields.String()
params = fields.Dict(allow_none=True)
Expand All @@ -19,8 +18,9 @@ class ActivitiesExport(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#
"""

_path = "/activities_export"
_many = namedtuple('ActivitiesExport', ["id", "status", "file_url", "expires_at", "created_at"])
_many = namedtuple("ActivitiesExport", ["id", "status", "file_url", "expires_at", "created_at"])

class _Schema(Schema):
# Create
Expand All @@ -45,11 +45,13 @@ def make(self, data, **kwargs):
@classmethod
def _validate_arguments(cls, method, kwargs):
# This enforces user to pass correct argument
if method in ['retrieve'] and 'id' not in kwargs:
raise ArgumentMissingError("Please pass 'id' parameter to retrieve your export request status")
if method in ['create'] and 'data' not in kwargs:
if method in ["retrieve"] and "id" not in kwargs:
raise ArgumentMissingError(
"Please pass 'id' parameter to retrieve your export request status"
)
if method in ["create"] and "data" not in kwargs:
raise ArgumentMissingError("Please pass 'data' parameter")


ActivitiesExport.create = ActivitiesExport._method('create', 'post', '/activities_export')
ActivitiesExport.retrieve = ActivitiesExport._method('retrieve', 'get', '/activities_export/{id}')
ActivitiesExport.create = ActivitiesExport._method("create", "post", "/activities_export")
ActivitiesExport.retrieve = ActivitiesExport._method("retrieve", "get", "/activities_export/{id}")
31 changes: 16 additions & 15 deletions chartmogul/api/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ class Activity(Resource):
"""
https://dev.chartmogul.com/reference/list-activities
"""
_path = '/activities'
_root_key = 'entries'
_many = namedtuple('Activities',
[_root_key, 'has_more', 'per_page', 'cursor'],
defaults=[None, None, None])

_path = "/activities"
_root_key = "entries"
_many = namedtuple(
"Activities", [_root_key, "has_more", "per_page", "cursor"], defaults=[None, None, None]
)

class _Schema(Schema):
activity_arr = fields.Number(data_key='activity-arr')
activity_mrr = fields.Number(data_key='activity-mrr')
activity_mrr_movement = fields.Number(data_key='activity-mrr-movement')
activity_arr = fields.Number(data_key="activity-arr")
activity_mrr = fields.Number(data_key="activity-mrr")
activity_mrr_movement = fields.Number(data_key="activity-mrr-movement")
currency = fields.String()
date = fields.DateTime()
description = fields.String()
type = fields.String()
subscription_external_id = fields.String(data_key='subscription-external-id')
plan_external_id = fields.String(data_key='plan-external-id')
customer_name = fields.String(data_key='customer-name')
customer_uuid = fields.String(data_key='customer-uuid')
customer_external_id = fields.String(data_key='customer-external-id')
billing_connector_uuid = fields.String(data_key='billing-connector-uuid')
uuid = fields.String(data_key='uuid')
subscription_external_id = fields.String(data_key="subscription-external-id")
plan_external_id = fields.String(data_key="plan-external-id")
customer_name = fields.String(data_key="customer-name")
customer_uuid = fields.String(data_key="customer-uuid")
customer_external_id = fields.String(data_key="customer-external-id")
billing_connector_uuid = fields.String(data_key="billing-connector-uuid")
uuid = fields.String(data_key="uuid")

@post_load
def make(self, data, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions chartmogul/api/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Attributes(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#customer-attributes
"""

_path = "/customers{/uuid}/attributes"

class _Schema(Schema):
Expand Down
2 changes: 1 addition & 1 deletion chartmogul/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Config:
uri = API_BASE + "/" + VERSION

def __init__(self, api_key, request_timeout=None, max_retries=20, backoff_factor=2):
self.auth = (api_key, '')
self.auth = (api_key, "")
self.request_timeout = request_timeout
self.max_retries = max_retries
self.backoff_factor = backoff_factor
1 change: 1 addition & 0 deletions chartmogul/api/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Contact(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#contacts
"""

_path = "/contacts{/uuid}"
_root_key = "entries"
_many = namedtuple("Contacts", [_root_key, "has_more", "cursor"])
Expand Down
7 changes: 4 additions & 3 deletions chartmogul/api/custom_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CustomAttributes(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#custom-attributes
"""

_path = "/customers{/uuid}/attributes/custom"

class _Schema(Schema):
Expand All @@ -17,7 +18,7 @@ class _Schema(Schema):
def make(self, data, **kwargs):
return CustomAttributes(**data)

_customers = namedtuple('Customers', ['entries'])
_customers = namedtuple("Customers", ["entries"])
_schema = _Schema(unknown=EXCLUDE)

@classmethod
Expand All @@ -30,8 +31,8 @@ def _load(cls, response):
if response.status_code == 204:
return None
jsonObj = response.json()
if 'entries' in jsonObj:
customers = Customer._schema.load(jsonObj['entries'], many=True)
if "entries" in jsonObj:
customers = Customer._schema.load(jsonObj["entries"], many=True)
return cls._customers(customers)
else:
return cls._schema.load(jsonObj)
27 changes: 16 additions & 11 deletions chartmogul/api/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class Address(DataObject):

class _Schema(Schema):
address_zip = fields.String(allow_none=True)
city = fields.String(allow_none=True)
Expand All @@ -29,12 +28,14 @@ class Customer(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#customers
"""

_path = "/customers{/uuid}"
_root_key = 'entries'
_many = namedtuple('Customers',
[_root_key, "has_more", "per_page", "page",
"current_page", "total_pages", "cursor"],
defaults=[None, None, None, None, None, None])
_root_key = "entries"
_many = namedtuple(
"Customers",
[_root_key, "has_more", "per_page", "page", "current_page", "total_pages", "cursor"],
defaults=[None, None, None, None, None, None],
)

class _Schema(Schema):
# All operations
Expand Down Expand Up @@ -76,8 +77,12 @@ def make(self, data, **kwargs):
_schema = _Schema(unknown=EXCLUDE)


Customer.search = Customer._method('all', 'get', '/customers/search')
Customer.merge = Customer._method('merge', 'post', '/customers/merges')
Customer.connectSubscriptions = Customer._method('create', 'post', '/customers/{uuid}/connect_subscriptions')
Customer.contacts = Contact._method('all', 'get', '/customers/{uuid}/contacts', useCallerClass=True)
Customer.createContact = Contact._method('create', 'post', '/customers/{uuid}/contacts', useCallerClass=True)
Customer.search = Customer._method("all", "get", "/customers/search")
Customer.merge = Customer._method("merge", "post", "/customers/merges")
Customer.connectSubscriptions = Customer._method(
"create", "post", "/customers/{uuid}/connect_subscriptions"
)
Customer.contacts = Contact._method("all", "get", "/customers/{uuid}/contacts", useCallerClass=True)
Customer.createContact = Contact._method(
"create", "post", "/customers/{uuid}/contacts", useCallerClass=True
)
2 changes: 1 addition & 1 deletion chartmogul/api/customers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Allow users to access the submodules of customers
# Allow users to access the submodules of customers
23 changes: 13 additions & 10 deletions chartmogul/api/customers/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ class CustomerActivity(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#list-customer-subscriptions
"""
_path = '/customers{/uuid}/activities'
_root_key = 'entries'
_many = namedtuple('Activities',
[_root_key, 'has_more', 'per_page', 'page', 'cursor'],
defaults=[None, None, None, None])

_path = "/customers{/uuid}/activities"
_root_key = "entries"
_many = namedtuple(
"Activities",
[_root_key, "has_more", "per_page", "page", "cursor"],
defaults=[None, None, None, None],
)

class _Schema(Schema):
id = fields.Int()
activity_arr = fields.Number(data_key='activity-arr')
activity_mrr = fields.Number(data_key='activity-mrr')
activity_mrr_movement = fields.Number(data_key='activity-mrr-movement')
activity_arr = fields.Number(data_key="activity-arr")
activity_mrr = fields.Number(data_key="activity-mrr")
activity_mrr_movement = fields.Number(data_key="activity-mrr-movement")
currency = fields.String()
currency_sign = fields.String(data_key='currency-sign')
currency_sign = fields.String(data_key="currency-sign")
date = fields.DateTime()
description = fields.String()
type = fields.String()
subscription_external_id = fields.String(data_key='subscription-external-id')
subscription_external_id = fields.String(data_key="subscription-external-id")

@post_load
def make(self, data, **kwargs):
Expand Down
60 changes: 39 additions & 21 deletions chartmogul/api/customers/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ class CustomerSubscription(Resource):
https://dev.chartmogul.com/v1.0/reference#list-customer-subscriptions
https://dev.chartmogul.com/v1.0/reference#list-a-customers-subscriptions
"""
_path = '/customers{/uuid}/subscriptions'
_root_key = 'entries'
_many = namedtuple('Subscriptions',
[_root_key, 'has_more', 'per_page', 'page', 'cursor'],
defaults=[None, None, None, None])

_path = "/customers{/uuid}/subscriptions"
_root_key = "entries"
_many = namedtuple(
"Subscriptions",
[_root_key, "has_more", "per_page", "page", "cursor"],
defaults=[None, None, None, None],
)

class _Schema(Schema):
id = fields.Int(allow_none=True)
Expand All @@ -21,12 +24,12 @@ class _Schema(Schema):
mrr = fields.Number(allow_none=True)
arr = fields.Number(allow_none=True)
status = fields.String(allow_none=True)
billing_cycle = fields.String(data_key='billing-cycle', allow_none=True)
billing_cycle_count = fields.Number(data_key='billing-cycle-count', allow_none=True)
start_date = fields.DateTime(data_key='start-date', allow_none=True)
end_date = fields.DateTime(data_key='end-date', allow_none=True)
billing_cycle = fields.String(data_key="billing-cycle", allow_none=True)
billing_cycle_count = fields.Number(data_key="billing-cycle-count", allow_none=True)
start_date = fields.DateTime(data_key="start-date", allow_none=True)
end_date = fields.DateTime(data_key="end-date", allow_none=True)
currency = fields.String(allow_none=True)
currency_sign = fields.String(data_key='currency-sign', allow_none=True)
currency_sign = fields.String(data_key="currency-sign", allow_none=True)

# /import namespace
uuid = fields.String(allow_none=True)
Expand All @@ -48,20 +51,35 @@ def make(self, data, **kwargs):
def _loadJSON(cls, jsonObj):
if "subscriptions" in jsonObj:
_many = namedtuple(
'Subscriptions',
["subscriptions", "current_page", "total_pages", "customer_uuid", "has_more", "cursor"]
"Subscriptions",
[
"subscriptions",
"current_page",
"total_pages",
"customer_uuid",
"has_more",
"cursor",
],
)
return _many(
cls._schema.load(jsonObj["subscriptions"], many=True),
current_page=jsonObj.get("current_page", None),
total_pages=jsonObj.get("total_pages", None),
customer_uuid=jsonObj.get("customer_uuid", None),
has_more=jsonObj.get("has_more", None),
cursor=jsonObj.get("cursor", None),
)
return _many(cls._schema.load(jsonObj['subscriptions'], many=True),
current_page=jsonObj.get('current_page', None),
total_pages=jsonObj.get('total_pages', None),
customer_uuid=jsonObj.get('customer_uuid', None),
has_more=jsonObj.get('has_more', None),
cursor=jsonObj.get('cursor', None))
else:
return super(CustomerSubscription, cls)._loadJSON(jsonObj)


# /import namespace
CustomerSubscription.list_imported = CustomerSubscription._method('list_imported', 'get', "/import/customers{/uuid}/subscriptions")
CustomerSubscription.cancel = CustomerSubscription._method('cancel', 'patch', "/import/subscriptions{/uuid}")
CustomerSubscription.modify = CustomerSubscription._method('modify', 'patch', "/import/subscriptions{/uuid}")
CustomerSubscription.list_imported = CustomerSubscription._method(
"list_imported", "get", "/import/customers{/uuid}/subscriptions"
)
CustomerSubscription.cancel = CustomerSubscription._method(
"cancel", "patch", "/import/subscriptions{/uuid}"
)
CustomerSubscription.modify = CustomerSubscription._method(
"modify", "patch", "/import/subscriptions{/uuid}"
)
7 changes: 4 additions & 3 deletions chartmogul/api/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class DataSource(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#data-sources
"""
_path = '/data_sources{/uuid}'
_root_key = 'data_sources'
_many = namedtuple('DataSources', [_root_key])

_path = "/data_sources{/uuid}"
_root_key = "data_sources"
_many = namedtuple("DataSources", [_root_key])

class _Schema(Schema):
uuid = fields.String()
Expand Down
22 changes: 13 additions & 9 deletions chartmogul/api/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class LineItem(DataObject):

class _Schema(Schema):
uuid = fields.String()
external_id = fields.String(allow_none=True)
Expand Down Expand Up @@ -38,11 +37,14 @@ class Invoice(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#invoices
"""

_path = "/import/customers{/uuid}/invoices"
_root_key = 'invoices'
_many = namedtuple('Invoices',
_root_key = "invoices"
_many = namedtuple(
"Invoices",
[_root_key, "current_page", "total_pages", "cursor", "has_more", "customer_uuid"],
defaults=[None, None, None, None, None])
defaults=[None, None, None, None, None],
)
_many.__new__.__defaults__ = (None,) * len(_many._fields)

class _Schema(Schema):
Expand Down Expand Up @@ -71,13 +73,15 @@ def all(cls, config, **kwargs):
Actually uses two different endpoints, where it dispatches the call depends on whether
customer uuid is given with the old parameter name ('uuid') or not.
"""
if 'uuid' in kwargs:
if "uuid" in kwargs:
return super(Invoice, cls).all(config, **kwargs)
else:
return cls.all_any(config, **kwargs)


Invoice.all_any = Invoice._method('all', 'get', '/invoices')
Invoice.destroy = Invoice._method('destroy', 'delete', '/invoices{/uuid}')
Invoice.destroy_all = Invoice._method('destroy_all', 'delete', '/data_sources{/data_source_uuid}/customers{/customer_uuid}/invoices')
Invoice.retrieve = Invoice._method('retrieve', 'get', '/invoices{/uuid}')
Invoice.all_any = Invoice._method("all", "get", "/invoices")
Invoice.destroy = Invoice._method("destroy", "delete", "/invoices{/uuid}")
Invoice.destroy_all = Invoice._method(
"destroy_all", "delete", "/data_sources{/data_source_uuid}/customers{/customer_uuid}/invoices"
)
Invoice.retrieve = Invoice._method("retrieve", "get", "/invoices{/uuid}")
Loading

0 comments on commit 009d7ca

Please sign in to comment.