Skip to content

Commit

Permalink
Merge pull request #7 from hotgluexyz/fix/inventoryLevelStates
Browse files Browse the repository at this point in the history
Fix/inventory level states
  • Loading branch information
hsyyid authored Feb 24, 2022
2 parents 9ee48fb + 0ea5793 commit 9fdc582
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
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.4.6",
version="1.4.",
description="Singer.io tap for extracting Shopify data",
author="Stitch",
url="http://github.com/singer-io/tap-shopify",
Expand Down
55 changes: 55 additions & 0 deletions tap_shopify/schemas/events_products.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"properties": {
"id": {
"type": [
"null",
"integer"
]
},
"subject_id": {
"type": [
"null",
"integer"
]
},
"created_at": {
"type": [
"null",
"string"
],
"format": "date-time"
},
"subject_type": {
"type": [
"null",
"string"
]
},
"verb": {
"type": [
"null",
"string"
]
},
"message": {
"type": [
"null",
"string"
]
},
"author": {
"type": [
"null",
"string"
]
},
"description": {
"type": [
"null",
"string"
]
}
},
"type": "object"
}

1 change: 1 addition & 0 deletions tap_shopify/streams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
import tap_shopify.streams.price_rules
import tap_shopify.streams.discount_codes
import tap_shopify.streams.incoming_items
import tap_shopify.streams.events_products
54 changes: 54 additions & 0 deletions tap_shopify/streams/events_products.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import shopify
import singer
from singer.utils import strftime, strptime_to_utc
from tap_shopify.context import Context
from tap_shopify.streams.base import (Stream,
shopify_error_handling)

LOGGER = singer.get_logger()

EVENTS_RESULTS_PER_PAGE = 100


class EventsProducts(Stream):
name = 'events_products'
replication_key = 'created_at'
replication_object = shopify.Event

@shopify_error_handling
def call_api_for_events_products(self):
return self.replication_object.find(
limit=EVENTS_RESULTS_PER_PAGE,
filter="Product",
# verb = "destroy",
created_at_min = self.get_bookmark()
)

def get_events_products(self, ):
page = self.call_api_for_events_products()
yield from page

while page.has_next_page():
page = page.next_page()
yield from page

def get_objects(self):
events_products = self.get_events_products()
for events_product in events_products:
yield events_product

def sync(self):
bookmark = self.get_bookmark()
self.max_bookmark = bookmark
for events_product in self.get_objects():
events_product_dict = events_product.to_dict()
replication_value = strptime_to_utc(events_product_dict[self.replication_key])
if replication_value >= bookmark:
yield events_product_dict
if replication_value > self.max_bookmark:
self.max_bookmark = replication_value

self.update_bookmark(strftime(self.max_bookmark))


Context.stream_objects['events_products'] = EventsProducts
2 changes: 1 addition & 1 deletion tap_shopify/streams/incoming_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call_api_for_incoming_items(self, parent_object):

def get_objects(self):
selected_parent = Context.stream_objects['inventory_levels']()
selected_parent.name = "incoming_items_inventory_levels"
selected_parent.name = "inventory_levels"

for parent_object in selected_parent.get_objects():
incoming_item = self.call_api_for_incoming_items(parent_object)
Expand Down

0 comments on commit 9fdc582

Please sign in to comment.