-
Notifications
You must be signed in to change notification settings - Fork 17
Incremental streams #40
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
base: master
Are you sure you want to change the base?
Changes from all commits
23834c6
279f79d
264d6d2
2f7383a
c02e618
ff249ee
4498242
91481d8
165e401
a3cd39a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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): | ||
| 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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs for the |
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs for the |
||
| 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: | ||
|
|
@@ -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"] | ||
There was a problem hiding this comment.
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.jsonendpoint accepts adirectionbut not asortparameter:https://reference.chargify.com/v1/customers/list-customers