Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordered queries #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

TerrorBite
Copy link

The Routerboard API documentation states that query parameter order is significant, however the kwargs method was being used to send query parameters, and dict is inherently unordered, meaning that order of query parameters was not preserved.

The API uses a stack-based method for applying boolean operators. The result of each query parameter is pushed onto the stack in the order they were specified, then operators can be specified which operate on the stack. Without correct order of query parameters, complex queries cannot be made.

It should be noted that the kwargs method also prevented multiple values being sent for a single query parameter, since keys in a dict are unique, meaning that the following example query found in the documentation could not be made using this library:

/interface/print
?type=ether
?type=vlan
?#|!

This pull request resolves these issues by introducing a new syntax for the .get() and .detailed_get() methods of a RouterboardResource. In addition to the previous syntax, which is still supported for backwards compatibility, a new syntax is introduced as follows:

# Old syntax, doesn't preserve parameter order, no multiple values for parameters
# Still supported for backwards compatibility
resource.get(param1='value1', param2='value2')

# New syntax, order is preserved, multiple values can be specified for one parameter
# Example: Select interfaces which are !(type==ether || type==vlan)
resource.get( ('type', 'ether'), ('type', 'vlan'), ('#|!', None) )

This syntax, although not as nice to look at, preserves ordering and allows for multiple values to be passed for a single query parameter by specifying it multiple times.

Move away from using kwargs for query parameters, since dicts are
unordered. kwargs syntax is still supported for backwards compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant