Skip to content
Open
Show file tree
Hide file tree
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
55 changes: 31 additions & 24 deletions tap_chargify/chargify.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get(self, path, stream=True, **kwargs):
uri = "{uri}{path}".format(uri=self.uri, path=path)
has_more = True
page = 1
per_page = 100
per_page = 200
while has_more:
params = {
"page": page,
Expand All @@ -66,25 +66,23 @@ def get(self, path, stream=True, **kwargs):
#

def customers(self, bookmark=None):
for i in self.get("customers.json"):
for i in self.get("customers.json", sort="asc", date_field="updated_at", start_datetime=bookmark):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs indicate the customers.json endpoint accepts a direction but not a sort parameter:
https://reference.chargify.com/v1/customers/list-customers

for j in i:
yield j["customer"]


def product_families(self, bookmark=None):
for i in self.get("product_families.json"):
for i in self.get("product_families.json", sort="asc", date_field="updated_at", start_datetime=bookmark):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for the product_families.json endpoint do not include the sort parameter
https://reference.chargify.com/v1/product-families/list-product-family-via-site

for j in i:
yield j["product_family"]


def products(self, bookmark=None):
for i in self.get("product_families.json"):
for k in i:
for j in self.get("product_families/{product_family_id}/products.json".format(product_family_id=k["product_family"]["id"])):
for j in self.get("product_families/{product_family_id}/products.json".format(product_family_id=k["product_family"]["id"]),
sort="asc", date_field="updated_at", start_datetime=bookmark):
Comment on lines +81 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for the product_families/{product_family_id}/products.json do not include a sort parameter:
https://reference.chargify.com/v1/products/list-products

for l in j:
yield l["product"]


def price_points(self, bookmark=None):
for i in self.get("product_families.json"):
for j in i:
Expand All @@ -94,56 +92,65 @@ def price_points(self, bookmark=None):
for m in o["price_points"]:
yield m


def coupons(self, bookmark=None):
for i in self.get("product_families.json"):
for k in i:
for j in self.get("product_families/{product_family_id}/coupons.json".format(product_family_id=k["product_family"]["id"])):
for l in j:
yield l["coupon"]


def components(self, bookmark=None):
for i in self.get("product_families.json"):
for k in i:
for j in self.get("product_families/{product_family_id}/components.json".format(product_family_id=k["product_family"]["id"])):
for l in j:
yield l["component"]



def subscriptions(self, bookmark=None):
for i in self.get("subscriptions.json", start_datetime=bookmark, date_field="updated_at", direction="asc"):
for i in self.get("subscriptions.json", start_datetime=bookmark, date_field="updated_at", sort="updated_at", direction="asc"):
for j in i:
yield j["subscription"]


def transactions(self, bookmark=None):
since_date = utils.strptime_with_tz(bookmark).strftime('%Y-%m-%d')
for i in self.get("transactions.json", since_date=since_date, direction="asc"):
# bookmark can be an id (regular case)
if isinstance(bookmark, int):
kwargs = {
"since_id": bookmark
}
# or a datetime (no saved state, only the start_date from the Context
else:
since_date = utils.strptime_with_tz(bookmark).strftime('%Y-%m-%d')
kwargs = {
"since_date": since_date
}
for i in self.get("transactions.json", direction="asc", **kwargs):
for j in i:
yield j["transaction"]


def statements(self, bookmark=None):
settled_since = mktime(utils.strptime_with_tz(bookmark).timetuple())
for i in self.get("statements.json", sort="settled_at", direction="asc", settled_since=settled_since):
for j in i:
yield j["statement"]


def invoices(self, bookmark=None):
start_date = utils.strptime_with_tz(bookmark).strftime('%Y-%m-%d')
for i in self.get("invoices.json", start_date=start_date, direction="asc"):
for j in i:
yield j["invoice"]


def events(self, bookmark=None):
for i in self.get("events.json"):
# bookmark can be an id (regular case)
if isinstance(bookmark, int):
kwargs = {
"since_id": bookmark
}
# or a datetime (no saved state, only the start_date from the Context)
else:
kwargs = {
"start_datetime": bookmark,
"date_field": "created_at"
}
for i in self.get("events.json", direction="asc", **kwargs):
for j in i:
yield j["event"]




yield j["event"]
130 changes: 104 additions & 26 deletions tap_chargify/schemas/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,40 @@
],
"properties": {
"state": {
"type": "string"
"type": [
"null",
"string"
]
},
"subscription_id": {
"type": "integer"
"type": [
"null",
"integer"
]
},
"created_at": {
"type": "string"
"type": [
"null",
"string"
]
},
"revenue_at_risk_in_cents": {
"type": "integer"
"type": [
"null",
"integer"
]
},
"attempts": {
"type": "integer"
"type": [
"null",
"integer"
]
},
"last_attempted_at": {
"type": "string"
"type": [
"null",
"string"
]
}
}
},
Expand All @@ -86,28 +104,52 @@
],
"properties": {
"day_threshold": {
"type": "integer"
"type": [
"null",
"integer"
]
},
"action": {
"type": "string"
"type": [
"null",
"string"
]
},
"email_body": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
},
"email_subject": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
},
"send_email": {
"type": "boolean"
"type": [
"null",
"boolean"
]
},
"send_bcc_email": {
"type": "boolean"
"type": [
"null",
"boolean"
]
},
"send_sms": {
"type": "boolean"
"type": [
"null",
"boolean"
]
},
"sms_body": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
}
}
},
Expand All @@ -118,42 +160,78 @@
],
"properties": {
"day_threshold": {
"type": "integer"
"type": [
"null",
"integer"
]
},
"action": {
"type": "string"
"type": [
"null",
"string"
]
},
"email_body": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
},
"email_subject": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
},
"send_email": {
"type": "boolean"
"type": [
"null",
"boolean"
]
},
"send_bcc_email": {
"type": "boolean"
"type": [
"null",
"boolean"
]
},
"send_sms": {
"type": "boolean"
"type": [
"null",
"boolean"
]
},
"sms_body": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
}
}
},
"previous_subscription_state": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
},
"new_subscription_state": {
"type": ["null", "string"]
"type": [
"null",
"string"
]
},
"previous_product_id": {
"type": ["null", "integer"]
"type": [
"null",
"integer"
]
},
"new_product_id": {
"type": ["null", "integer"]
"type": [
"null",
"integer"
]
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions tap_chargify/schemas/product_families.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
"null",
"string"
]
},
"created_at": {
"type": [
"null",
"string"
],
"format": "date-time"
},
"updated_at": {
"type": [
"null",
"string"
],
"format": "date-time"
}
}
}
Loading