ndex_helper_encodeParams: Adds Parameters to an url

Description Usage Arguments Details Value Note Examples

View source: R/ndex_helper.r

Description

Encodes a given parameter within the url accordingly to the parameter configuration for the api.

Usage

1

Arguments

url

character

params

(nested) list; "params" section of a api function definition in the api configuration (See ndex_config)

...

parameters defined by name used in the config

Details

The single parameter definitions are given as list by the "params" parameter. Each parameter is defined by a method, and, if applicable, a tag, a default value and/or an optional flag. There are three keywords defining the method: replace, append or parameter.

replace: The String defined by "tag" can be found within the url and will be replaced by the given value of the parameter. E.g. the tag "#NETWORKID#" in the url "/network/#NETWORKID#/provenance" is replaced by a value (e.g. "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") given as network id, which leads to the url "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/provenance".

append: The given value of the parameter is appended to an url. Therefore the order of the parameters in the params definition is used. E.g. the url "/network/search" and the given values for "start" = 0 and "size" = 100 generates the following url: "/network/search/0/100"

parameter: Encodes the given parameters as url parameter using the specified tag as parameter descriptor. E.g. a parameter with the tag "username" and the value "SomeName" is encoded in the url "/user" as follows: "/user?username=SomeName"

It is also possible to set parameter as optional (except for replace), or define default values. Values are assigned to the parameters using the parameter name in the ... parameter.

Value

URL with encoded parameters as character

Note

This function is internal.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
## replace
url = "http://en.wikipedia.org/#NETWORKID#/index.php"
params = list(    network=list(    tag="#NETWORKID#", method="replace"))
values = c(network='aaaa-bb-cc-dddddd', bla='This is not used!')
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/aaaa-bb-cc-dddddd/index.php"

params = list( network=list( tag="#NETWORKID#", method="replace", default="xxxx-xx-xx-xxxxxx"))
values = c(bla='This is not used!')
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/xxxx-xx-xx-xxxxxx/index.php"
 
## parameter
url = "http://en.wikipedia.org/w/index.php"
params = list(    network=list(    tag="network", method="parameter"))
values = c(network='aaaa-bb-cc-dddddd', bla='This is not used!')
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php?network=aaaa-bb-cc-dddddd"
  
values = c(bla='This is not used!')
params = list(    network=list(    tag="network", method="parameter", optional=TRUE))
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php"
  
params = list(  network=list(  tag="network", method="parameter", default="xxxx-xx-xx-xxxxxx"))
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php?network=xxxx-xx-xx-xxxxxx"
  
ndexr:::ndex_helper_encodeParams(url, params=params, values)
values = c(network='aaaa-bb-cc-dddddd', bla='This is not used!')
## "http://en.wikipedia.org/w/index.php?network=aaaa-bb-cc-dddddd"
  
## append
url = "http://en.wikipedia.org/w/index.php"
params = list(    network=list(    method="append"))
values = c(network='aaaa-bb-cc-dddddd', bla='This is not used!')
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php/aaaa-bb-cc-dddddd"
  
values = c(bla='This is not used!')
params = list(    network=list(    method="append", optional=TRUE))
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php"
  
params = list(    network=list(    method="append", default="xxxx-xx-xx-xxxxxx"))
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php/xxxx-xx-xx-xxxxxx"
  
values = c(network='aaaa-bb-cc-dddddd', bla='This is not used!')
ndexr:::ndex_helper_encodeParams(url, params=params, values)
## "http://en.wikipedia.org/w/index.php/aaaa-bb-cc-dddddd"

ndexr documentation built on March 13, 2021, 2 a.m.