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

date_from and date_to request fails in API /rivers/river_id/drops request #55

Open
dan-king opened this issue Aug 22, 2013 · 1 comment

Comments

@dan-king
Copy link

The documentation at https://wiki.ushahidi.com/display/WIKI/SwiftRiver+API+River+Resources#SwiftRiverAPIRiverResources-GETrivers/:id/drops explains date_from and date_to parameters but doesn't describe the format.

The trends example uses the format YYYY-MM-DD but when I try this in the DROPS GET request I get the following error:

Fatal error: Uncaught exception 'Exception' with message 'An error occurred: array ( 'message' => 'Invalid parameter.', 'errors' => array ( 0 => array ( 'field' => 'date_from', 'code' => 'invalid', ), 1 => array ( 'field' => 'date_to', 'code' => 'invalid', ), ), )' in /opt/firsttosee/swift/api3.php:104 Stack trace: #0 /opt/firsttosee/swift/api3.php(120): API_Client->exec_api_request('/rivers/39/drop...', '', 'GET', Array) #1 {main} thrown in /opt/firsttosee/swift/api3.php on line 104

I get the same error when I try MM-DD-YYYY.

When I used RFC822 I get a different error:

$date_from = "Thu, 25 Jul 2013 15:12:33 -0700";
$date_to = "Thu, 15 Aug 2013 15:12:33 -0700";

Fatal error: Uncaught exception 'Exception' with message 'An error occurred: ''' in /opt/firsttosee/swift/api3.php:104 Stack trace: #0 /opt/firsttosee/swift/api3.php(120): API_Client->exec_api_request('/rivers/39/drop...', '', 'GET', Array) #1 {main} thrown in /opt/firsttosee/swift/api3.php on line 104

@dan-king
Copy link
Author

I have a workaround until the bug is fixed and/or documentation updated with working example.

The workaround is to query the database directly instead of using the api. The database schema is documented at https://wiki.ushahidi.com/display/WIKI/SwiftRiver+Database+Schema

The query I used is

SELECT
droplets.id, droplets.identity_id, droplets.droplet_orig_id, droplets.channel, droplets.droplet_type, droplets.droplet_title, droplets.droplet_content, droplets.droplet_date_pub, droplets.droplet_date_add, droplets.original_url,
rivers_droplets.droplet_id,
identities.identity_username, identities.identity_name, identities.identity_avatar
FROM $db.droplets , $db.rivers_droplets , $db.identities
WHERE
droplets.id = rivers_droplets.droplet_id
AND
droplets.identity_id = identities.id
AND
droplets.droplet_date_pub >= '$date_from 00:00:00'
AND
droplets.droplet_date_pub <= '$date_to 23:59:59'
AND
rivers_droplets.river_id = $river_id
ORDER BY droplets.id DESC LIMIT 500";

The variables $date_from and $date_to are in the format "yyyy-mm-dd".

Of course this kind of direct query is very unreliable because it will fail as soon as the schema changes. It would be better to get the result from the API.

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

No branches or pull requests

1 participant