Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

36 rader
1.4 KiB

import requests
# Querying which actions are available on resource 0 to user with ID 0
r_available = requests.get('http://localhost:8080/available/?resource=0&user=0')
# The result is a JSON object with a key for each action branch, and
# each branch consisting of an array of strings, each element being
# an action name available to that user
# Assuming this is the same resource as added in ** Populating Redis in
# docs/integration.org, the result would be:
# >>> print(ra.json())
# {u'data': [u'no-access', u'view']}
# To perform an action, we use the /run-action endpoint, which takes
# a branch name and action name in addition to the resource and user.
# The result of the /available query tells us exactly which branches and
# actions we can perform
r_view = requests.get('http://localhost:8080/run-action/?resource=0&user=0&branch=data&action=view')
# In this case, the output of the 'view' action is a JSON array representation of the SQL output
# Thus, each of the fields can be accessed as in any other array; for example
# we can retrieve the Phenotype.Pre_publication_description field:
r_na = requests.get('http://localhost:8080/run-action/?resource=0&user=0&branch=data&action=no-access')
# If the user doesn't have access, the string "no-action" is returned,
# as the no-access-action is used by default