Skip to content

Commit e1b9ae8

Browse files
committed
adding Production and Staging URL fetch + support Library via string ID
1 parent b73d65d commit e1b9ae8

File tree

6 files changed

+64
-10
lines changed

6 files changed

+64
-10
lines changed

docs/library.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ The different attributes are the following:
3333

3434
* id : id of the library
3535
* name : name of the library
36-
* state : is it development”, “staging or production environment
36+
* state : is it "development", "staging" or "production" environment
3737
* build_required : is a build required or not (Boolean)
3838
* builds : The build attache to this library
39-
* buid_status : Is the last build has been successful ?
39+
* buid_status : Is the last build has been "successful" ?
4040
* relationships : the different element attached to this Library
4141
* _environments = a dictionary of the different environment possible.
4242

@@ -45,10 +45,11 @@ The different attributes are the following:
4545
The get methods will enable you to retrieve the elements that have been attached to this library.
4646
The different get methods are the followings:
4747

48-
* getDataElements
49-
* getExtensions
50-
* getRules
48+
* getDataElements : get the data element in that library
49+
* getExtensions : get the Extension in that library
50+
* getRules : get the rules in the library
5151
* getFullLibrary : It is a combinaison of all of the 3 above.
52+
* getBuilds : Retrieve the builds of that library
5253

5354
## Adding element to a library
5455

@@ -62,7 +63,7 @@ They are the following:
6263

6364
## Environments settings
6465

65-
Before you can actually start building the library and pass it from one state to another (development -> staging). You would need to set the different environments.
66+
Before you can actually start building the library and pass it from one state to another ("development" -> "staging"). You would need to set the different environments.
6667

6768
The method used for that is : setEnvironments().
6869
It takes 2 arguments:
@@ -90,7 +91,7 @@ myLib.build() # require that you have set your environment.
9091
As it is your goal to publish your library, you want to transition it from the dev to the staging environment and so forth.
9192
In order to do that, you can use the transition() method.
9293
***Note*** : You would need to build your library between 2 transition.
93-
At the end of the funnel, you just need to build your library when you are in the approved state.
94+
At the end of the funnel, you just need to build your library when you are in the "approved" state.
9495
The transition method takes 1 argument:
9596

9697
* action : it can be either

docs/property.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ The different get methods are the following :
9898
Arguments:
9999
* element : REQUIRED : the element definition dictionary
100100

101+
* **getProductionEndpoint** : Get the URL for the production library
102+
103+
* **getStagingEndpoint** : Get the URL for the staging library
104+
101105

102106
## Create methods
103107

docs/releases.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
This page gathered the changes made between version of the launchpy module.\
44
This has been started after the 0.3.0 release.\
55

6+
## 0.4.4
7+
* adding a `getBuilds` method on the `Library` class instance
8+
* extend support for pagination on `getEnvironments`
9+
* adding `getProductionEndpoint` and `getStagingEndpoint` to retrieve the URL to use on websites
10+
* support the instantiation of the `Library` class via a single libraryId string.
11+
612
## 0.4.3
713
* Refactor `Translator` class for removing `pandas` dependency\
814
Patch:

launchpy/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.4.3-3"
1+
__version__ = "0.4.4"

launchpy/library.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import time
22
# Non standard libraries
33
from launchpy import config, connector
4+
from typing import Union
45

56
class Library:
67
"""
78
A class that handle the library in a Launch environment.
89
"""
910

10-
def __init__(self, data: dict,config_object:dict=config.config_object,header:dict=config.header):
11+
def __init__(self, data: Union[str,dict],config_object:dict=config.config_object,header:dict=config.header):
1112
"""
1213
The instantiator for the library.
1314
Arguments:
@@ -19,6 +20,8 @@ def __init__(self, data: dict,config_object:dict=config.config_object,header:dic
1920
config_object=config_object, header=header)
2021
self.header = self.connector.header
2122
self.endpoint = config.endpoints['global']
23+
if type(data) == str:
24+
data = self.connector.getData("https://reactor.adobe.io/libraries/"+data).get('data')
2225
self.id = data['id']
2326
self.name = data['attributes']['name']
2427
self.state = data['attributes']['state']
@@ -100,6 +103,23 @@ def getExtensions(self,page:int=0,pageSize:int=50,origin:bool=True)->list:
100103
return dataOrigin
101104
self.relationships['extensions'] = data
102105
return data
106+
107+
def getBuilds(self)->list:
108+
"""
109+
Retrieve the last builds.
110+
Return a list of build
111+
"""
112+
params = {'page[number]':1}
113+
res = self.connector.getData(self._Builds,params=params)
114+
builds = res.get('data',[])
115+
next_page = res.get('meta',{}).get('pagination',{}).get('next_page',None)
116+
while next_page is not None:
117+
params['page[number]'] +=1
118+
res = self.connector.getData(self._Builds,params=params)
119+
builds += res.get('data',[])
120+
next_page = res.get('meta',{}).get('pagination',{}).get('next_page',None)
121+
return builds
122+
103123

104124
def getRules(self,page:int=0,pageSize:int=50,origin:bool=True)->list:
105125
"""
@@ -296,7 +316,7 @@ def setEnvironments(self, environments_list: list, dev_name: str = None)->None:
296316
Save the different environments ids available.
297317
It is required to use the library class.
298318
Arguments :
299-
environments_list : REQUIRED : list of environment retrieved by the getEnvironment method
319+
environments_list : REQUIRED : list of environment retrieved by the getEnvironments method
300320
dev_name : OPTIONAL : Name of your dev environment. If not defined, will take the first dev environment.
301321
"""
302322
for env in environments_list:

launchpy/property.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ def getEnvironments(self)->object:
9999
"""
100100
Retrieve the environment sets for this property
101101
"""
102+
params = {"page[number]":1}
102103
env = self.connector.getData(self._Environments)
103104
data = env['data'] # skip meta for now
105+
next_page = env.get('meta',{}).get('pagination',{}).get('next_page',None)
106+
while next_page is not None:
107+
params['page[number]'] = next_page
108+
env = self.connector.getData(self._Environments,params=params)
109+
data += env.get('data',[])
110+
next_page = env.get('meta',{}).get('pagination',{}).get('next_page',None)
104111
return data
105112

106113
def getHost(self)->object:
@@ -1187,6 +1194,22 @@ def deleteLibrary(self,library:str=None,components:bool=False)->str:
11871194
for de in dataelements:
11881195
self.deleteDataElement(de['id'])
11891196
return res
1197+
1198+
def getProductionEndpoint(self)->dict:
1199+
"""
1200+
Returns the production library URL to use on the website
1201+
"""
1202+
envs = self.getEnvironments()
1203+
prod = [env for env in envs if env['attributes']['stage'] == 'production'][0]
1204+
return prod['meta']['script_sources'][0]["license_path"]
1205+
1206+
def getStagingEndpoint(self)->dict:
1207+
"""
1208+
Returns the staging library URL to use on the website
1209+
"""
1210+
envs = self.getEnvironments()
1211+
staging = [env for env in envs if env['attributes']['stage'] == 'staging'][0]
1212+
return staging['meta']['script_sources'][0]["license_path"]
11901213

11911214
def extensionsInfo(data: list)->dict:
11921215
"""

0 commit comments

Comments
 (0)