Servicios REST - lacoderia/momentosdeverdad GitHub Wiki
#General
##Response
The response for all services is a JSON object with the following structure:
- success = true or false
- result = if success is true, this contains the result object
- error = if success is false, this contains the error message
Examples:
{"success":true, "result":{}}
{"success":false, "error": "Some error"}
#Services
GET /places/available.json
http://localhost:3000/places/available.json
Get all the places that are marked as active
Returns an array of place objects
Result data structure:
- place object
- id (integer)
- category (string)
- description (string)
- name (string)
- longitude (float)
- latitude (float)
- active (boolean)
- ratio (float)
GET /places/nearest_by_lat_long.json
http://localhost:3000/places/nearest_by_lat_long.json
Get the nearest places from a lat, long coordinate
Parameters
- lat (float, query param required)
- long (float, query param required)
Returns an array of place objects, null ONLY if no places are saved in the database. Result data structure:
- place object
- id (integer)
- category (string)
- description (string)
- name (string)
- longitude (float)
- latitude (float)
- active (boolean)
- ratio (float)
GET /places/by_lat_long.json
http://localhost:3000/places/by_lat_long.json
Get the place(s) that are inside a place's radius
Parameters
- lat (float, query param required)
- long (float, query param required)
Returns an array of place objects, null if no match was found.
Result data structure:
- place object
- id (integer)
- category (string)
- description (string)
- name (string)
- longitude (float)
- latitude (float)
- active (boolean)
- ratio (float)
GET /stories/ID.json
http://localhost:3000/stories/ID.json
Gets stories by id
Parameters:
- ID (integer, required)
Result data structure:
- story object
- id (integer)
- description (string)
- vote_plus (integer)
- vote_minus (integer)
- active (boolean)
- picture (string)
- author_name (string)
- author_email (string)
- place (object):
- id (integer)
- description (string)
- name (string)
- longitude (float)
- latitude (float)
- ratio (float)
GET /stories/by_place.json?place_id=ID
http://localhost:3000/stories/by_place.json?place_id=ID
Gets stories by place
Parameters:
- place_id (integer, required)
Returns an array of story objects
Result data structure:
- story object
- id (integer)
- place_id (integer)
- description (string)
- vote_plus (integer)
- vote_minus (integer)
- active (boolean)
- picture (string)
- author_name (string)
- author_email (string)
POST /stories/ID/mark.json
http://localhost:3000/stories/ID/mark.json
Marks a story as true or false, increasing its vote_plus or vote_minus value
URL Parameters:
- ID: story's id (integer)
Body Parameters:
- real: true or false (string)
Returns the updated story object
Result data structure:
- story object
- id (integer)
- place_id (integer)
- description (string)
- vote_plus (integer)
- vote_minus (integer)
- active (boolean)
- picture (string)
- author_name (string)
- author_email (string)
POST /stories.json
http://localhost:3000/stories.json
Creates a story
Body Parameters:
- story object
- place_id (integer, required)
- description (text, required)
- picture (picture base 64 object, required)
- user_attributes (user object, required)
- name (string, required)
- email (string, required)
Returns a story object
Result data structure:
- story object
- id (integer)
- place_id (integer)
- description (string)
- vote_plus (integer)
- vote_minus (integer)
- picture object
- uid (string)
- source (complete URL - string)
- user object
- id (integer)
- name (string)
- email (string)
Add the following script after the opening tag on each page you want to load it:
window.fbAsyncInit = function() {
FB.init({
appId : '907881252606673',
xfbml : true,
version : 'v2.3'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Use the following JS function:
function shareFB() {
FB.ui({
method: 'feed',
name: Name,
caption: Caption,
description: Description,
link: URL
,
picture: Picture
,
}, function(response){
});
}
Parameters:
- Name: Momentos de Verdad: + Venue's name (string)
- Caption: Use author's name (string)
- Description: Use story's description (string)
- URL: Use story's URL. (string)
- Picture: Use story's picture URL (string)