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

add redirects stream #80

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.3.0
* Adds a `redirects` stream [#80] (https://github.com/singer-io/tap-shopify/pull/80)

## 1.2.6
* Accepts any string for `accepts_marketing_updated_at` field on the `customers` stream [#69] (https://github.com/singer-io/tap-shopify/pull/69)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="tap-shopify",
version="1.2.6",
version="1.3.0",
description="Singer.io tap for extracting Shopify data",
author="Stitch",
url="http://github.com/singer-io/tap-shopify",
Expand Down
23 changes: 23 additions & 0 deletions tap_shopify/schemas/redirects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"properties": {
"id": {
"type": [
"null",
"integer"
]
},
"path": {
"type": [
"null",
"string"
]
},
"target": {
"type": [
"null",
"string"
]
}
}
}
1 change: 1 addition & 0 deletions tap_shopify/streams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
import tap_shopify.streams.products
import tap_shopify.streams.collects
import tap_shopify.streams.custom_collections
import tap_shopify.streams.redirects
41 changes: 41 additions & 0 deletions tap_shopify/streams/redirects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import shopify
from tap_shopify.streams.base import (Stream,
RESULTS_PER_PAGE,
OutOfOrderIdsError)
from tap_shopify.context import Context


class Redirects(Stream):
name = 'redirects'
replication_object = shopify.Redirect
# Redirects have no timestamps, but can be updated after creation
# So the only option is to use full table replication
replication_method = 'FULL_TABLE'
replication_key = 'id'

def get_objects(self):
# Override base function as this is a full sync every time
since_id = 1
while True:
query_params = {
"since_id": since_id,
"limit": RESULTS_PER_PAGE,
}

objects = self.call_api(query_params)

for obj in objects:
if obj.id < since_id:
raise OutOfOrderIdsError("obj.id < since_id: {} < {}".format(
obj.id, since_id))
yield obj

if len(objects) < RESULTS_PER_PAGE:
break
if objects[-1].id != max([o.id for o in objects]):
raise OutOfOrderIdsError("{} is not the max id in objects ({})".format(
objects[-1].id, max([o.id for o in objects])))
since_id = objects[-1].id


Context.stream_objects['redirects'] = Redirects