Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,44 @@ pip install wayscript
from wayscript import WayScript

api_key = 'YOUR_API_KEY'

wayscript = WayScript( api_key )

# Run a program by id
program_id = 1234
wayscript.run_program( program_id )

# Pass variables to a program
# Pass variables to a program (optional)
variables = [ 'one', 'two', 'three' ]
wayscript.run_program( program_id, variables = variables )

# Run a program asynchronously
# Run a specific function within your program (optional)
function = 'My Function'
wayscript.run_program( program_id, variables = variables, function = function )

# Run a program asynchronously (optional)
wayscript.run_program( program_id, run_async = True )
wayscript.run_program( program_id, variables = variables, run_async = True )
wayscript.run_program( program_id, variables = variables, function = function, run_async = True )

# Get the response from the server
response = wayscript.run_program( program_id )
```

⭐ In order to run a program using the WayScript Python API, you must first add an active [Webhook Trigger](https://wayscript.com/documentation/trigger/webhook_trigger) to that program.

### Running a specific function

- The function you specify MUST have an active [Webhook Trigger](https://wayscript.com/documentation/trigger/webhook_trigger).
- If you do not specify a function name in your request and your program has ***one*** function with a Webhook Trigger, the function with the Webhook Trigger will run.
- If you do not specify a function name in your request and your program has ***multiple*** functions with Webhook Triggers, you will be asked to specify which function you would like to run.

## Run a WayScript program from command line
```sh
WS_API_KEY="YOUR_API_KEY"
PROGRAM_ID=1234
ARGUMENT="whatever"
FUNCTION="My Function"

python -c "from wayscript import WayScript; WayScript('$WS_API_KEY').run_program($PROGRAM_ID, '$ARGUMENT')"
python -c "from wayscript import WayScript; WayScript('$WS_API_KEY').run_program($PROGRAM_ID, '$ARGUMENT', '$FUNCTION')"
```

If you don't want to use Python on the command line, you can use `curl`. (See the WayScript [REST API documentation](https://wayscript.com/documentation/apis/rest_api).)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setuptools.setup(
name="wayscript",
version="0.0.1",
version="0.0.2",
author="Team WayScript",
author_email="founders@wayscript.com",
description="WayScript gives you flexible building blocks to seamlessly integrate, automate and host tools in the cloud.",
Expand Down
23 changes: 23 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def test_run_program( self ):
'run_async': False },
headers = self.headers )

def test_run_program_function( self ):
wayscript = WayScript( self.dummy_api_key )

with patch( 'requests.post' ) as post_request:
wayscript.run_program( self.program_id, function = 'My Function' )
post_request.assert_called_once_with( self.api_url, params = { 'api_key': self.dummy_api_key,
'program_id': self.program_id,
'function': 'My Function',
'run_async': False },
headers = self.headers )

def test_run_program_with_variables( self ):
wayscript = WayScript( self.dummy_api_key )

Expand All @@ -45,6 +56,18 @@ def test_run_program_with_variables( self ):
'variables': self.variables },
headers = self.headers )

def test_run_program_function_with_variables( self ):
wayscript = WayScript( self.dummy_api_key )

with patch( 'requests.post' ) as post_request:
wayscript.run_program( self.program_id, variables = self.variables, function = 'My Function' )
post_request.assert_called_once_with( self.api_url, params = { 'api_key': self.dummy_api_key,
'program_id': self.program_id,
'run_async': False,
'variables': self.variables,
'function': 'My Function'},
headers = self.headers )

def test_run_program_async( self ):
wayscript = WayScript( self.dummy_api_key )

Expand Down
10 changes: 8 additions & 2 deletions wayscript/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def __init__( self, api_key):
self._api_key = api_key
self._api_url = 'https://wayscript.com/api'

def run_program( self, program_id, variables = None, run_async = False ):
def run_program( self, program_id, variables = None, function = None, run_async = False ):
"""Runs a WayScript program.
:param program_id: The id of the program you want to run.
:param variables: (optional) An array of arguments to pass to your program.
:param function: (optional) The name of the function within your program that you would like to run.
:param run_async: (optional) Run this program asyncronously.
If False, this command will block until your program has finished running.
:return: Response object
Expand All @@ -33,7 +34,9 @@ def run_program( self, program_id, variables = None, run_async = False ):
>>> api_key = 'YOUR_API_KEY'
>>> wayscript = WayScript( api_key )
>>> program_id = 1234
>>> response = wayscript.run_program( program_id, variables = variables, run_async = True )
>>> variables = [ 'one', 'two', 'three' ]
>>> function = 'My Function'
>>> response = wayscript.run_program( program_id, variables = variables, function = function, run_async = True )
<Response [200]>
"""

Expand All @@ -44,6 +47,9 @@ def run_program( self, program_id, variables = None, run_async = False ):
if variables and len( variables ):
params[ 'variables' ] = variables

if function and len( function ):
params[ 'function' ] = function

return self._post( params )

def _post( self, params ):
Expand Down