diff --git a/shopify/base.py b/shopify/base.py index 47f40cb3..97fa0935 100644 --- a/shopify/base.py +++ b/shopify/base.py @@ -7,6 +7,7 @@ import sys from six.moves import urllib import six +import os from shopify.collection import PaginatedCollection from pyactiveresource.collection import Collection @@ -72,6 +73,8 @@ def set_password(cls, value): password = property(get_password, set_password, None, "The password for HTTP Basic Auth.") def get_site(cls): + if os.environ.get('SHOPIFY_HOST'): + return os.environ.get('SHOPIFY_HOST') return getattr(cls._threadlocal, "site", ShopifyResource._site) def set_site(cls, value): @@ -103,7 +106,10 @@ def set_timeout(cls, value): def get_headers(cls): if not hasattr(cls._threadlocal, "headers"): cls._threadlocal.headers = ShopifyResource._headers.copy() - return cls._threadlocal.headers + headers = cls._threadlocal.headers + if os.environ.get('SHOPIFY_HOST'): + headers['SHOPIFY-DOMAIN'] = getattr(cls._threadlocal, "site", ShopifyResource._site) + return headers def set_headers(cls, value): cls._threadlocal.headers = value @@ -147,6 +153,8 @@ def set_version(cls, value): version = property(get_version, set_version, None, "Shopify Api Version") def get_url(cls): + output = getattr(cls._threadlocal, "url", ShopifyResource._url) + print(output) return getattr(cls._threadlocal, "url", ShopifyResource._url) def set_url(cls, value): diff --git a/shopify/resources/graphql.py b/shopify/resources/graphql.py index 33525ef1..2609b3b9 100644 --- a/shopify/resources/graphql.py +++ b/shopify/resources/graphql.py @@ -21,6 +21,10 @@ def execute(self, query, variables=None, operation_name=None): headers = self.merge_headers(default_headers, self.headers) data = {"query": query, "variables": variables, "operationName": operation_name} + print('request endpoint -> {}'.format(self.endpoint)) + print('request data -> {}'.format(json.dumps(data).encode("utf-8"))) + print('request headers -> {}'.format(headers)) + req = urllib.request.Request(self.endpoint, json.dumps(data).encode("utf-8"), headers) try: