cjapy 0.2.4.post3__tar.gz → 0.3.1__tar.gz
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.
- {cjapy-0.2.4.post3/cjapy.egg-info → cjapy-0.3.1}/PKG-INFO +3 -5
- cjapy-0.3.1/cjapy/__version__.py +1 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/cjapy.py +36 -13
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/config.py +1 -4
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/configs.py +68 -53
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/connector.py +95 -113
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/requestCreator.py +32 -25
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/workspace.py +14 -5
- {cjapy-0.2.4.post3 → cjapy-0.3.1/cjapy.egg-info}/PKG-INFO +3 -5
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy.egg-info/SOURCES.txt +0 -1
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy.egg-info/requires.txt +1 -2
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/cja.md +46 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/getting_started.md +40 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/main.md +38 -9
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/releases.md +10 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/requestCreator.md +32 -6
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/pyproject.toml +3 -5
- cjapy-0.3.1/requirements.txt +6 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/setup.py +1 -2
- cjapy-0.2.4.post3/cjapy/__version__.py +0 -1
- cjapy-0.2.4.post3/cjapy/token_provider.py +0 -93
- cjapy-0.2.4.post3/requirements.txt +0 -6
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/.gitignore +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/LICENSE +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/README.md +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/__init__.py +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy/projects.py +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy.egg-info/dependency_links.txt +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/cjapy.egg-info/top_level.txt +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/authenticating_without_config_json.md +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/logging.md +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/projects.md +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/docs/workspace.md +0 -0
- {cjapy-0.2.4.post3 → cjapy-0.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cjapy
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Adobe Customer Journey Analytics (CJA) wrapper
|
|
5
5
|
Home-page: https://github.com/pitchmuc/cjapy
|
|
6
6
|
Author: Julien Piccini
|
|
@@ -14,10 +14,9 @@ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Programming Language :: Python
|
|
16
16
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.8
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
20
|
Classifier: Development Status :: 4 - Beta
|
|
22
21
|
Requires-Python: >=3.6
|
|
23
22
|
Description-Content-Type: text/markdown
|
|
@@ -26,8 +25,7 @@ Requires-Dist: pandas
|
|
|
26
25
|
Requires-Dist: pathlib2
|
|
27
26
|
Requires-Dist: pathlib
|
|
28
27
|
Requires-Dist: requests
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist: PyJWT[crypto]
|
|
28
|
+
Requires-Dist: deprecation
|
|
31
29
|
Requires-Dist: pytest
|
|
32
30
|
Provides-Extra: dynamic
|
|
33
31
|
Requires-Dist: version; extra == "dynamic"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.1"
|
|
@@ -13,6 +13,7 @@ import string
|
|
|
13
13
|
# Non standard libraries
|
|
14
14
|
import pandas as pd
|
|
15
15
|
from cjapy import config, connector
|
|
16
|
+
from .configs import ConfigObj
|
|
16
17
|
from .workspace import Workspace
|
|
17
18
|
from .requestCreator import RequestCreator
|
|
18
19
|
from .projects import Project
|
|
@@ -32,17 +33,30 @@ class CJA:
|
|
|
32
33
|
|
|
33
34
|
def __init__(
|
|
34
35
|
self,
|
|
35
|
-
config_object: dict =
|
|
36
|
-
header: dict = config.header,
|
|
36
|
+
config_object: Union[ConfigObj, dict, None] = None,
|
|
37
37
|
loggingObject: dict = None,
|
|
38
38
|
) -> None:
|
|
39
39
|
"""
|
|
40
40
|
Instantiate the class with the information provided.
|
|
41
41
|
Arguments:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
config_object : OPTIONAL : One of:
|
|
43
|
+
- A :class:`~cjapy.ConfigObj` instance (created via ``configure(..., return_object=True)``
|
|
44
|
+
or ``importConfigFile(..., return_object=True)``), for isolated credentials that allow
|
|
45
|
+
multiple CJA instances to run in parallel with different client IDs.
|
|
46
|
+
- A plain ``dict`` matching the internal config_object structure (legacy usage).
|
|
47
|
+
- ``None`` (default): uses the global config set by :func:`~cjapy.configure` or
|
|
48
|
+
:func:`~cjapy.importConfigFile`.
|
|
49
|
+
loggingObject : OPTIONAL : If you want to set logging capability for your actions.
|
|
50
|
+
"""
|
|
51
|
+
if isinstance(config_object, ConfigObj):
|
|
52
|
+
_config_object = config_object.config_object
|
|
53
|
+
_header = config_object.header
|
|
54
|
+
elif isinstance(config_object, dict):
|
|
55
|
+
_config_object = config_object
|
|
56
|
+
_header = config.header
|
|
57
|
+
else:
|
|
58
|
+
_config_object = config.config_object
|
|
59
|
+
_header = config.header
|
|
46
60
|
if loggingObject is not None and sorted(
|
|
47
61
|
["level", "stream", "format", "filename", "file"]
|
|
48
62
|
) == sorted(list(loggingObject.keys())):
|
|
@@ -59,8 +73,8 @@ class CJA:
|
|
|
59
73
|
streamHandler.setFormatter(formatter)
|
|
60
74
|
self.logger.addHandler(streamHandler)
|
|
61
75
|
self.connector = connector.AdobeRequest(
|
|
62
|
-
config_object=
|
|
63
|
-
header=
|
|
76
|
+
config_object=_config_object,
|
|
77
|
+
header=_header,
|
|
64
78
|
loggingEnabled=self.loggingEnabled,
|
|
65
79
|
logger=self.logger,
|
|
66
80
|
)
|
|
@@ -2141,9 +2155,16 @@ class CJA:
|
|
|
2141
2155
|
data_rows = deepcopy(dataRows)
|
|
2142
2156
|
expanded_rows = {}
|
|
2143
2157
|
if reportType == "normal":
|
|
2144
|
-
for row in data_rows:
|
|
2145
|
-
|
|
2146
|
-
|
|
2158
|
+
for idx, row in enumerate(data_rows):
|
|
2159
|
+
if 'itemId' in row.keys():
|
|
2160
|
+
expanded_rows[row["itemId"]] = [row["value"]]
|
|
2161
|
+
expanded_rows[row["itemId"]] += row["data"]
|
|
2162
|
+
elif "itemIds" in row.keys():
|
|
2163
|
+
expanded_rows[row["itemIds"][0]] = [row["values"][0]]
|
|
2164
|
+
expanded_rows[row["itemIds"][0]] += row["data"]
|
|
2165
|
+
elif reportType == "multidimensional":
|
|
2166
|
+
for idx, row in enumerate(data_rows):
|
|
2167
|
+
expanded_rows[idx] = list(row["values"]) + row["data"]
|
|
2147
2168
|
elif reportType == "static":
|
|
2148
2169
|
expanded_rows = data_rows
|
|
2149
2170
|
return expanded_rows
|
|
@@ -2186,7 +2207,7 @@ class CJA:
|
|
|
2186
2207
|
segmentApplied[obj["id"]] = obj["dateRange"]
|
|
2187
2208
|
### table columnIds and StaticRow IDs
|
|
2188
2209
|
tableColumnIds = {
|
|
2189
|
-
obj
|
|
2210
|
+
obj.get("columnId"): obj.get("filters",[])[0]
|
|
2190
2211
|
for obj
|
|
2191
2212
|
in dataRequest["metricContainer"]["metrics"]
|
|
2192
2213
|
}
|
|
@@ -2285,7 +2306,7 @@ class CJA:
|
|
|
2285
2306
|
### Settings
|
|
2286
2307
|
dataRequest["settings"]["page"] = 0
|
|
2287
2308
|
dataRequest["settings"]["limit"] = limit
|
|
2288
|
-
if returnsNone:
|
|
2309
|
+
if returnsNone is None or len(dataRequest.get("dimensions",[])) >1 :
|
|
2289
2310
|
dataRequest["settings"]["nonesBehavior"] = "return-nones"
|
|
2290
2311
|
else:
|
|
2291
2312
|
dataRequest["settings"]["nonesBehavior"] = "exclude-nones"
|
|
@@ -2405,6 +2426,8 @@ class CJA:
|
|
|
2405
2426
|
metricColumns.append(metricName)
|
|
2406
2427
|
### ending with ['metric1','metric2 + segId',...]
|
|
2407
2428
|
### preparing data points
|
|
2429
|
+
if len(dataRequest.get("dimensions",[]))>1 and reportType == "normal":
|
|
2430
|
+
reportType = "multidimensional"
|
|
2408
2431
|
if self.loggingEnabled:
|
|
2409
2432
|
self.logger.debug(f"preparing data")
|
|
2410
2433
|
preparedData = self._prepareData(dataRows, reportType=reportType)
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
config_object = {
|
|
2
2
|
"org_id": "",
|
|
3
3
|
"client_id": "",
|
|
4
|
-
"tech_id": "",
|
|
5
|
-
"pathToKey": "",
|
|
6
4
|
"secret": "",
|
|
7
5
|
"date_limit": 0,
|
|
8
6
|
"token": "",
|
|
9
7
|
"scopes":"",
|
|
10
8
|
"imsEndpoint":"https://ims-na1.adobelogin.com",
|
|
11
|
-
"
|
|
12
|
-
"jwtTokenEndpoint": "https://ims-na1.adobelogin.com/ims/exchange/jwt"
|
|
9
|
+
"oauthTokenEndpoint": "",
|
|
13
10
|
}
|
|
14
11
|
header = {"Accept": "application/json",
|
|
15
12
|
"Content-Type": "application/json",
|
|
@@ -5,7 +5,7 @@ from typing import Optional
|
|
|
5
5
|
import time
|
|
6
6
|
|
|
7
7
|
# Non standard libraries
|
|
8
|
-
from .config import config_object, header
|
|
8
|
+
from cjapy.config import config_object, header
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def find_path(path: str) -> Optional[Path]:
|
|
@@ -37,19 +37,15 @@ def createConfigFile(
|
|
|
37
37
|
to store the access data in under the specified `destination`.
|
|
38
38
|
Parameters:
|
|
39
39
|
filename : OPTIONAL : : name of the config file.
|
|
40
|
-
auth_type : OPTIONAL : type of authentication
|
|
40
|
+
auth_type : OPTIONAL : type of authentication. Default is oauthV2
|
|
41
41
|
verbose : OPTIONAL : set to true, gives you a print stateent where is the location.
|
|
42
42
|
"""
|
|
43
43
|
json_data = {
|
|
44
44
|
"org_id": "<orgID>",
|
|
45
45
|
"client_id": "<APIkey>",
|
|
46
46
|
"secret": "<YourSecret>",
|
|
47
|
+
"scopes": "<scope1,scope2>",
|
|
47
48
|
}
|
|
48
|
-
if auth_type == 'jwt':
|
|
49
|
-
json_data["tech_id"] = "<something>@techacct.adobe.com"
|
|
50
|
-
json_data["pathToKey"] = "<path/to/your/privatekey.key>"
|
|
51
|
-
elif auth_type == 'OauthV2':
|
|
52
|
-
json_data["scopes"] = "<scopes>"
|
|
53
49
|
with open(filename, "w") as cf:
|
|
54
50
|
cf.write(json.dumps(json_data, indent=4))
|
|
55
51
|
if verbose:
|
|
@@ -60,16 +56,16 @@ def createConfigFile(
|
|
|
60
56
|
|
|
61
57
|
def importConfigFile(
|
|
62
58
|
path: str = None,
|
|
63
|
-
auth_type: str = None,
|
|
64
59
|
client_secret_index: int = 0,
|
|
65
|
-
|
|
60
|
+
return_object: bool = False,
|
|
61
|
+
) -> Optional["ConfigObj"]:
|
|
66
62
|
"""Reads the file denoted by the supplied `path` and retrieves the configuration information
|
|
67
63
|
from it.
|
|
68
64
|
|
|
69
65
|
Arguments:
|
|
70
66
|
path: REQUIRED : path to the configuration file. Can be either a fully-qualified or relative.
|
|
71
|
-
auth_type : OPTIONAL : type of authentication, either "jwt" or "oauthV2". Detected based on keys present in config file.
|
|
72
67
|
client_secret_index : OPTIONAL : choose which of your client secrets that you want to use, specify the index, default 0.
|
|
68
|
+
return_object : OPTIONAL : If True, returns a ConfigObj instance instead of updating the global config. Default False.
|
|
73
69
|
|
|
74
70
|
Example of path value.
|
|
75
71
|
"config.json"
|
|
@@ -109,90 +105,109 @@ def importConfigFile(
|
|
|
109
105
|
)
|
|
110
106
|
|
|
111
107
|
if "scopes" in provided_keys:
|
|
112
|
-
## old naming for client_secret
|
|
113
108
|
scopes = provided_config["scopes"]
|
|
114
109
|
elif "SCOPES" in provided_keys:
|
|
115
110
|
scopes = provided_config["SCOPES"]
|
|
111
|
+
else:
|
|
112
|
+
raise RuntimeError(
|
|
113
|
+
"Either a `scopes` or a `SCOPES` key should be provided."
|
|
114
|
+
)
|
|
116
115
|
|
|
117
116
|
client_secret = client_secret[client_secret_index] if type(client_secret) == list else client_secret
|
|
118
|
-
if auth_type is None:
|
|
119
|
-
if 'scopes' in provided_keys:
|
|
120
|
-
auth_type = 'oauthV2'
|
|
121
|
-
elif 'tech_id' in provided_keys and "pathToKey" in provided_keys:
|
|
122
|
-
auth_type = 'jwt'
|
|
123
117
|
args = {
|
|
124
118
|
"org_id": provided_config["org_id"] if provided_config.get("org_id") is not None else provided_config["ORG_ID"],
|
|
125
119
|
"client_id": client_id,
|
|
126
120
|
"secret": client_secret,
|
|
121
|
+
"scopes": ",".join(scopes) if type(scopes) == list else scopes.replace(' ',''),
|
|
127
122
|
}
|
|
128
|
-
if
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
123
|
+
if return_object:
|
|
124
|
+
return ConfigObj(
|
|
125
|
+
org_id=args["org_id"],
|
|
126
|
+
client_id=args["client_id"],
|
|
127
|
+
secret=args["secret"],
|
|
128
|
+
scopes=args["scopes"],
|
|
129
|
+
)
|
|
134
130
|
configure(**args)
|
|
135
131
|
|
|
136
132
|
|
|
137
133
|
def configure(
|
|
138
134
|
org_id: str = None,
|
|
139
|
-
tech_id: str = None,
|
|
140
135
|
secret: str = None,
|
|
141
136
|
client_id: str = None,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
):
|
|
137
|
+
scopes: str = None,
|
|
138
|
+
return_object: bool = False,
|
|
139
|
+
) -> Optional["ConfigObj"]:
|
|
146
140
|
"""Performs programmatic configuration of the API using provided values.
|
|
147
141
|
Arguments:
|
|
148
142
|
org_id : REQUIRED : Organization ID
|
|
149
|
-
tech_id : REQUIRED : Technical Account ID
|
|
150
143
|
secret : REQUIRED : secret generated for your connection
|
|
151
|
-
client_id : REQUIRED : The client_id (old api_key) provided by the
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
scopes : OPTIONAL : The scope define in your project for your API connection. Oauth V2, for clients and customers.
|
|
144
|
+
client_id : REQUIRED : The client_id (old api_key) provided by the connection.
|
|
145
|
+
scopes : REQUIRED : The scopes defined in your project for your API connection.
|
|
146
|
+
return_object : OPTIONAL : If True, returns a ConfigObj instance instead of updating the global config. Default False.
|
|
155
147
|
"""
|
|
156
148
|
if not org_id:
|
|
157
149
|
raise ValueError("`org_id` must be specified in the configuration.")
|
|
158
150
|
if not client_id:
|
|
159
151
|
raise ValueError("`client_id` must be specified in the configuration.")
|
|
160
|
-
if
|
|
161
|
-
raise ValueError("
|
|
152
|
+
if not scopes:
|
|
153
|
+
raise ValueError("`scopes` must be specified in the configuration.")
|
|
162
154
|
if not secret:
|
|
163
155
|
raise ValueError("`secret` must be specified in the configuration.")
|
|
164
156
|
config_object["org_id"] = org_id
|
|
165
157
|
config_object["client_id"] = client_id
|
|
166
158
|
header["x-api-key"] = client_id
|
|
167
159
|
header["x-gw-ims-org-id"] = org_id
|
|
168
|
-
config_object["tech_id"] = tech_id
|
|
169
160
|
config_object["secret"] = secret
|
|
170
|
-
config_object["pathToKey"] = path_to_key
|
|
171
|
-
config_object["private_key"] = private_key
|
|
172
161
|
config_object["scopes"] = scopes
|
|
173
|
-
config_object["
|
|
174
|
-
config_object["oauthTokenEndpointV2"] = f"{config_object['imsEndpoint']}/ims/token/v3"
|
|
162
|
+
config_object["oauthTokenEndpoint"] = f"{config_object['imsEndpoint']}/ims/token/v3"
|
|
175
163
|
|
|
176
164
|
# ensure the reset of the state by overwriting possible values from previous import.
|
|
177
165
|
config_object["date_limit"] = 0
|
|
178
166
|
config_object["token"] = ""
|
|
167
|
+
if return_object:
|
|
168
|
+
return ConfigObj(
|
|
169
|
+
org_id=org_id,
|
|
170
|
+
client_id=client_id,
|
|
171
|
+
secret=secret,
|
|
172
|
+
scopes=scopes,
|
|
173
|
+
)
|
|
179
174
|
|
|
180
|
-
|
|
181
|
-
def get_private_key_from_config(config: dict) -> str:
|
|
175
|
+
class ConfigObj:
|
|
182
176
|
"""
|
|
183
|
-
|
|
177
|
+
Holds an isolated set of credentials and configuration for a single CJA API connection.
|
|
178
|
+
cfg = importConfigFile("config_client_a.json", return_object=True)
|
|
179
|
+
cfg = configure(org_id="...", client_id="...", secret="...", scopes="...", return_object=True)
|
|
180
|
+
cja = CJA(config_object=cfg)
|
|
181
|
+
Attributes:
|
|
182
|
+
config_object : dict holding all credential and token state.
|
|
183
|
+
header : dict holding the HTTP headers for API requests.
|
|
184
184
|
"""
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
185
|
+
|
|
186
|
+
def __init__(
|
|
187
|
+
self,
|
|
188
|
+
org_id: str = "",
|
|
189
|
+
client_id: str = "",
|
|
190
|
+
secret: str = "",
|
|
191
|
+
scopes: str = None,
|
|
192
|
+
) -> None:
|
|
193
|
+
ims_endpoint = "https://ims-na1.adobelogin.com"
|
|
194
|
+
self.config_object: dict = {
|
|
195
|
+
"org_id": org_id,
|
|
196
|
+
"client_id": client_id,
|
|
197
|
+
"secret": secret,
|
|
198
|
+
"date_limit": 0,
|
|
199
|
+
"token": "",
|
|
200
|
+
"scopes": scopes,
|
|
201
|
+
"imsEndpoint": ims_endpoint,
|
|
202
|
+
"oauthTokenEndpoint": f"{ims_endpoint}/ims/token/v3",
|
|
203
|
+
}
|
|
204
|
+
self.header: dict = {
|
|
205
|
+
"Accept": "application/json",
|
|
206
|
+
"Content-Type": "application/json",
|
|
207
|
+
"Authorization": "Bearer ",
|
|
208
|
+
"x-api-key": client_id,
|
|
209
|
+
"x-gw-ims-org-id": org_id,
|
|
210
|
+
}
|
|
196
211
|
|
|
197
212
|
|
|
198
213
|
def generateLoggingObject(level:str="WARNING",filename:str="cjapy.log") -> dict:
|