stigg-api-client 0.508.0__py3-none-any.whl → 0.512.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of stigg-api-client might be problematic. Click here for more details.

stigg/client.py CHANGED
@@ -1,21 +1,90 @@
1
- from sgqlc.endpoint.requests import RequestsEndpoint
1
+ import requests
2
+ from typing import Dict, Callable
3
+
2
4
  from sgqlc.operation import Operation
5
+ from sgqlc.endpoint.requests import RequestsEndpoint
6
+ from requests.exceptions import HTTPError
7
+ from tenacity import retry, retry_if_exception_type, stop_after_attempt
3
8
 
4
9
  from stigg.generated.operations import Operations
5
10
 
11
+ PRODUCTION_API_URL = "https://api.stigg.io/graphql"
12
+ PRODUCTION_EDGE_API_URL = "https://edge.api.stigg.io"
13
+
14
+ STIGG_REQUESTS_RETRY_COUNT = 3
15
+
16
+ RETRY_KWARGS = {
17
+ "retry": retry_if_exception_type(HTTPError),
18
+ "stop": stop_after_attempt(STIGG_REQUESTS_RETRY_COUNT),
19
+ "reraise": True,
20
+ }
21
+
6
22
 
7
23
  class StiggClient:
8
- def __init__(self, endpoint: RequestsEndpoint):
24
+ def __init__(self, endpoint: RequestsEndpoint, enable_edge: bool, edge_api_url: str):
9
25
  self._endpoint: RequestsEndpoint = endpoint
10
26
 
11
- def request(self, operation: Operation, variables: dict, raw_response=False):
27
+ self._enable_edge = enable_edge
28
+ self._edge_url = edge_api_url
29
+
30
+ self._EDGE_QUERIES: Dict[Operation, Callable[[Dict], Dict]] = {
31
+ Operations.query.get_entitlements: self.get_entitlements,
32
+ Operations.query.get_paywall: self.get_paywall,
33
+ }
34
+
35
+ @retry(**RETRY_KWARGS)
36
+ def _get_entitlements(self, variables: Dict[str, Dict]) -> Dict:
37
+ params = variables.get("query")
38
+ if params is None:
39
+ raise ValueError('Variables do not include required key "query".')
40
+
41
+ customer_id = params.pop("customerId")
42
+
43
+ url = f"{self._edge_url}/v1/c/{customer_id}/entitlements.json"
44
+
45
+ data = requests.get(url, headers=self._endpoint.base_headers, params=params, timeout=self._endpoint.timeout)
46
+ data.raise_for_status()
47
+
48
+ return data.json()
49
+
50
+ def get_entitlements(self, variables: Dict[str, Dict]) -> Dict:
51
+ if self._enable_edge is False:
52
+ return self.request(Operations.query.get_entitlements, variables, raw_response=True)
53
+
54
+ return self._get_entitlements(variables)
55
+
56
+ @retry(**RETRY_KWARGS)
57
+ def _get_paywall(self,variables: Dict[str, Dict]) -> Dict:
58
+ params = variables.get("input")
59
+ if params is None:
60
+ raise ValueError('Variables do not include required key "input".')
61
+
62
+ if params.get("productId") is not None:
63
+ url = f"{self._edge_url}/v1/p/{params['productId']}/paywall.json"
64
+ params.pop("productId")
65
+ else:
66
+ url = f"{self._edge_url}/v1/paywall.json"
67
+
68
+ data = requests.get(url, headers=self._endpoint.base_headers, params=params, timeout=self._endpoint.timeout)
69
+ data.raise_for_status()
70
+
71
+ return data.json()
72
+
73
+ def get_paywall(self, variables: Dict[str, Dict]) -> Dict:
74
+ if self._enable_edge is False:
75
+ return self.request(Operations.query.get_paywall, variables, raw_response=True)
76
+
77
+ return self._get_paywall(variables)
78
+
79
+ @retry(**RETRY_KWARGS)
80
+ def request(self, operation: Operation, variables: Dict, raw_response: bool = False):
12
81
  data = self._endpoint(operation, variables)
13
82
  if raw_response:
14
83
  return data
15
84
 
16
- # clean up data to so an exepction will be raised
85
+ # clean up data to so an exception will be raised
17
86
  errors = data.get('errors')
18
- if errors:
87
+ if errors and data.get('data') is not None:
19
88
  data.pop('data')
20
89
 
21
90
  # interpret results into native Python objects
@@ -24,11 +93,13 @@ class StiggClient:
24
93
 
25
94
  class Stigg(Operations):
26
95
  @staticmethod
27
- def create_client(api_key: str,
28
- api_url: str = 'https://api.stigg.io/graphql',
29
- request_timeout=30) -> StiggClient:
96
+ def create_client(
97
+ api_key: str,
98
+ api_url: str = PRODUCTION_API_URL,
99
+ enable_edge: bool = True,
100
+ edge_api_url: str = PRODUCTION_EDGE_API_URL,
101
+ request_timeout: int = 30,
102
+ ) -> StiggClient:
30
103
  headers = {'X-API-KEY': f'{api_key}'}
31
- endpoint = RequestsEndpoint(url=api_url,
32
- base_headers=headers,
33
- timeout=request_timeout)
34
- return StiggClient(endpoint)
104
+ endpoint = RequestsEndpoint(url=api_url, base_headers=headers, timeout=request_timeout)
105
+ return StiggClient(endpoint, enable_edge, edge_api_url)
stigg/generated/schema.py CHANGED
@@ -2701,7 +2701,8 @@ class SubscriptionAddonSort(sgqlc.types.Input):
2701
2701
 
2702
2702
  class SubscriptionBillingInfo(sgqlc.types.Input):
2703
2703
  __schema__ = schema
2704
- __field_names__ = ('tax_rate_ids',)
2704
+ __field_names__ = ('tax_percentage', 'tax_rate_ids')
2705
+ tax_percentage = sgqlc.types.Field(Float, graphql_name='taxPercentage')
2705
2706
  tax_rate_ids = sgqlc.types.Field(sgqlc.types.list_of(sgqlc.types.non_null(String)), graphql_name='taxRateIds')
2706
2707
 
2707
2708
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stigg-api-client
3
- Version: 0.508.0
3
+ Version: 0.512.0
4
4
  Summary:
5
5
  Author: Stigg
6
6
  Author-email: support@stigg.io
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
14
14
  Requires-Dist: graphql-core (>=3.1,<4.0)
15
15
  Requires-Dist: requests (>=2.28,<3.0)
16
16
  Requires-Dist: sgqlc (>=16.0,<17.0)
17
+ Requires-Dist: tenacity (>=8.2.2,<9.0.0)
17
18
  Description-Content-Type: text/markdown
18
19
 
19
20
  # stigg-api-client
@@ -0,0 +1,8 @@
1
+ stigg/__init__.py,sha256=uQeM3YjvH1X56xOPknIEQezw0yjNNS-m9gi3B0XlSOM,44
2
+ stigg/client.py,sha256=wSb0yyW13mWMr_4pooJArTtCa2fL5079ho9jGaZTdpE,3699
3
+ stigg/generated/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ stigg/generated/operations.py,sha256=E2qRZg7gj22JSCAbAme2SXizMtYmQaS-XldpgO3_X7Y,51059
5
+ stigg/generated/schema.py,sha256=MKLuaKjceCx_Q7S9ccf5sRZ6juN2qpSmYw5QbCBzNuM,467141
6
+ stigg_api_client-0.512.0.dist-info/METADATA,sha256=A2RXZJUq9dx0_MxcirNVIB0zIcM6x7ODA-85KyTnZmI,3122
7
+ stigg_api_client-0.512.0.dist-info/WHEEL,sha256=kLuE8m1WYU0Ig0_YEGrXyTtiJvKPpLpDEiChiNyei5Y,88
8
+ stigg_api_client-0.512.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- stigg/__init__.py,sha256=uQeM3YjvH1X56xOPknIEQezw0yjNNS-m9gi3B0XlSOM,44
2
- stigg/client.py,sha256=yJWbqm6yjLFGxtTHJxHX2mLqkCYMtOKxMDsN9vyFNcg,1141
3
- stigg/generated/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- stigg/generated/operations.py,sha256=E2qRZg7gj22JSCAbAme2SXizMtYmQaS-XldpgO3_X7Y,51059
5
- stigg/generated/schema.py,sha256=k9CCjx3pcjA9zOHr4Z9B5BYR2PMvEMjZhhlMYiPuIDw,467048
6
- stigg_api_client-0.508.0.dist-info/METADATA,sha256=fXDxyF01aGXDsG0pdHm5yhiOjU2El1tGDVgmDsioLik,3081
7
- stigg_api_client-0.508.0.dist-info/WHEEL,sha256=kLuE8m1WYU0Ig0_YEGrXyTtiJvKPpLpDEiChiNyei5Y,88
8
- stigg_api_client-0.508.0.dist-info/RECORD,,