elgg-gitbot / test2

0 stars 0 forks source link

Web Services: if a parameter is not passed, the following parameter takes its place (Trac #4399) #16

Closed elgg-gitbot closed 11 years ago

elgg-gitbot commented 11 years ago

Original ticket http://trac.elgg.org/ticket/4399 on 2012-03-06 by trac user markharding, assigned to unknown.

Elgg version: 1.8.1b1

I am having a problem with web services. If a parameter is not passed and it is listed in the exposed function higher, its value is taken by a lower one. Basically, the parameters don't seem to be matching their values if one is missing.

For example. My function

function file_get_files($username, $context,  $limit = 10, $offset = 0) 

and my expose function.

expose_function('file.get_files',
                "file_get_files",
                array('username' => array ('type' => 'string', 'required' => false),
                                         'context' => array ('type' => 'string', 'required' => false),
                      'limit' => array ('type' => 'int', 'required' => false),
                      'offset' => array ('type' => 'int', 'required' => false),
                    ),
                "Get file uploaded by all users",
                'GET',
                false,
                false);

If $username is not passed but $context is then the context value actually becomes the $username value.

I don't know if there are any plans for this but I think it would be great if there could be a simple $params array that we could post instead of having to manually list them all.

elgg-gitbot commented 11 years ago

cash wrote on 2012-03-06

PHP is not Python so we cannot skip optional functional parameters. You need to set the default value in expose_function(). Someday, we'll have a better web services API that uses a params array.

elgg-gitbot commented 11 years ago

trac user markharding wrote on 2012-03-06

Suppose $username is not being passed because they are wanting to get the logged in users values, how would you go about that?

elgg-gitbot commented 11 years ago

cash wrote on 2012-03-08

The problem is with your function. If username is an optional parameter, it should occur after context in the list.