aboutsummaryrefslogtreecommitdiff
path: root/src/ee/element14/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/element14/__init__.py')
-rw-r--r--src/ee/element14/__init__.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/ee/element14/__init__.py b/src/ee/element14/__init__.py
new file mode 100644
index 0000000..17a8825
--- /dev/null
+++ b/src/ee/element14/__init__.py
@@ -0,0 +1,63 @@
+import json
+from pathlib import Path
+from typing import Optional
+from urllib.parse import urlencode
+from urllib.request import urlopen
+
+import ee._utils
+
+__all__ = [
+ "Element14Config",
+ "Element14Client",
+]
+
+
+class Element14Config(object):
+ def __init__(self, store: Optional[str], api_key: Optional[str]):
+ self.store = store
+ self.api_key = api_key
+
+
+class Element14Client(object):
+ def __init__(self, config: Element14Config, cache_dir: Path):
+ self.config = config
+ self.cache = ee._utils.maybe_cache(cache_dir)
+
+ def search(self, term: Optional[str] = None):
+ url = "https://api.element14.com/catalog/products"
+
+ kv = {
+ "callInfo.responseDataFormat": "XML",
+ }
+
+ if self.config.api_key:
+ kv["callInfo.apiKey"] = self.config.api_key
+
+ if self.config.store:
+ kv["storeInfo.id"] = self.config.store
+
+ if term:
+ kv["term"] = term
+
+ kv["resultsSettings.offset"] = "0"
+ kv["resultsSettings.numberOfResults"] = "100"
+
+ print("params: {}".format(kv))
+
+ # &resultsSettings.refinements.filters={rohsCompliant,inStock}
+ # &resultsSettings.responseGroup={none,small,medium,large, Prices, Inventory}
+
+ url = url + "?" + urlencode(kv)
+
+ print("url={}".format(url))
+
+ data = "wat!!"
+ data = urlopen(url).read()
+
+ print("-----------")
+ print(data)
+ print("-----------")
+
+ search_response = json.loads(data)
+
+ return