<s> from st2actions . runners . pythonrunner import Action <EOL> import requests <EOL> class BaseAction ( Action ) : <EOL> def __init__ ( self , config ) : <EOL> super ( BaseAction , self ) . __init__ ( config ) <EOL> self . url = None <EOL> self . headers = None <EOL> def _headers ( self ) : <EOL> if not self . headers : <EOL> api_token = self . config . get ( '<STR_LIT>' , None ) <EOL> if not api_token : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> self . headers = { <EOL> "<STR_LIT>" : "<STR_LIT>" . format ( api_token ) <EOL> } <EOL> return self . headers <EOL> def _url ( self ) : <EOL> if not self . url : <EOL> url = self . config . get ( '<STR_LIT>' , None ) <EOL> if not url : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> self . url = url <EOL> return self . url <EOL> def _get ( self , endpoint ) : <EOL> url = '<STR_LIT>' . join ( [ self . _url ( ) , endpoint ] ) <EOL> headers = self . _headers ( ) <EOL> return requests . get ( url , headers = headers ) . json ( ) <EOL> def _put ( self , endpoint , params ) : <EOL> url = '<STR_LIT>' . join ( [ self . _url ( ) , endpoint ] ) <EOL> headers = self . _headers ( ) <EOL> result = requests . put ( url , params = params , headers = headers ) <EOL> if not result . text : <EOL> return { "<STR_LIT:message>" : "<STR_LIT>" } <EOL> else : <EOL> return result . json ( ) </s>
