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

add ResultLimit feature, implements ideas from #29 #57

Merged
merged 8 commits into from May 1, 2012
Merged

add ResultLimit feature, implements ideas from #29 #57

merged 8 commits into from May 1, 2012

Conversation

benib
Copy link
Contributor

@benib benib commented Apr 9, 2012

this implements some things discussed in issue #29.
default is to return all fields. if fields parameter is set, only the defined fields are returned as long as there is a check in the code, where the field is added to the result. this can be done like:

if (ResultLimit::includeField('from')) {
    // add from stuff to result
}

these checks are implemented in Transport\Entity\Schedule\Connection for the fields "from", "to" and "journey" to show how this works.

Tree like fields are also possible, eg:

http://sbb.local/v1/connections?from=008501120&to=008501008&fields[]=to&fields[]=from/geo

in that case, ResultLimit::includeField('from') returnes true, as there is a more specific field set.

any comments are appreciated.

@rndstr
Copy link
Member

rndstr commented Apr 10, 2012

Quick feedback:

  • Why not make everything static in ResultLimit, get rid of the Singleton, and add a private ctor? Although I would prefer seeing it as an instance passed around or even better pass the $request somehow. Haven't yet thought it through, though.
  • You should put open parentheses of classes and methods on their own line (see rest of codebase)
  • Tests? ;)

@benib
Copy link
Contributor Author

benib commented Apr 10, 2012

  • i agree about making everything static.
  • also agree about coding styles
  • personally i like the approach with the static function includeField(), that way, we can just add this call where some data is added to the request and don't have to worry about passing instances around. the information which fields to include is static and only set once with the request sent to the API.

{
}

public static function setFields($fields)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest doing type hinting here array $fields instead of the is_array() check below

@benib
Copy link
Contributor Author

benib commented Apr 10, 2012

@rndstr: i sticked to isFieldSet as isFieldIncluded seems to be confusing to me, as the field is not yet included, we want to know if it should be or not.

@rndstr
Copy link
Member

rndstr commented Apr 10, 2012

Thanks for the changes! I'm okay with ResultLimit being static for now I guess.

But looking at the code, I see you are only checking for the from, to and journey parts in the Connection resource. What is your idea about the other resources and their fields?

@benib
Copy link
Contributor Author

benib commented Apr 11, 2012

  • checks are now implemented for /connections and /stationboard
  • if no fields are set, everything is returned
  • if any field is set, only the specified fields are returned
  • fields are specified in a path like model
  • if eg. connections/from is set, only the from element and everything below is returned
  • if eg. connections/from/station is set, only the from element containing only the station is returned
  • this can be combined to something like fields[]=connections/from/station&fields[]=connections/to/arrival

@fabian fabian merged commit 43e97eb into OpendataCH:master May 1, 2012
@fabian
Copy link
Member

fabian commented May 1, 2012

Merged, thanks!

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

3 participants