Difference between revisions of "Sugar Network/API"
m (→Overview) |
|||
Line 23: | Line 23: | ||
== Objects == | == Objects == | ||
− | + | === Common actions === | |
− | + | Actions might be restricted for particular object, see the corresponding section for detailed information. | |
+ | |||
+ | * {{Code|/<OBJECT>/'''create'''}} | ||
Create new ''OBJECT'' item. | Create new ''OBJECT'' item. | ||
+ | |||
Inputs: | Inputs: | ||
− | :* {{Code|ctime}} ''int'' | + | :* {{Code|ctime}}, ''int''<br>the UNIX seconds time of entry creation; optional, will be set on a server side otherwise; |
− | :* {{Code|mtime}} ''int'' | + | :* {{Code|mtime}}, ''int''<br>the UNIX seconds time of entry modification; optional, will be set on a server side otherwise; |
+ | |||
Returns: | Returns: | ||
− | :* {{Code|guid}} ''str'' | + | :* {{Code|guid}}, ''str''<br>globally unique identifier that specifies created item; |
− | /'''update'''?guid=<> | + | /<OBJECT>/'''update'''?guid=<> |
− | Modify the specified item. | + | Modify the specified ''OBJECT'' item. |
Inputs: | Inputs: | ||
: Keys that need to be modified. | : Keys that need to be modified. | ||
− | /'''delete'''?guid=<> | + | /<OBJECT>/'''delete'''?guid=<> |
+ | |||
+ | Delete the specified ''OBJECT'' item. The real destroying won't happen, the item will be hidden. The garbage collection of hidden items will be processed by Network administrators. | ||
− | + | /<OBJECT>/'''find'''?[query=<>][&offset=<>][&limit=<>][&properties=<PROP>[,..]][&order_by=<nowiki>[+|-]</nowiki><PROP>[,..]] | |
− | + | Find ''OBJECT'' items. | |
− | |||
Where: | Where: | ||
− | :* {{Code|query}} ''str'' | + | :* {{Code|query}}, ''str''<br>search request in [http://xapian.org/docs/queryparser.html Xapian] notation; |
− | :* {{Code|offset}} ''int'' | + | :* {{Code|offset}}, ''int''<br>start index to return entries from; |
− | :* {{Code|limit}} ''int'' | + | :* {{Code|limit}}, ''int''<br>do not return more then specified value; |
− | :* {{Code|properties}} ''str'' | + | :* {{Code|properties}}, ''str''<br>coma separated list of ''OBJECT'' properties to return; by default, return all properties; |
− | :* {{Code|order_by}} ''str'' | + | :* {{Code|order_by}}, ''str''<br>coma separated list of ''OBJECT'' properties to sort the resulting list; if an property starts with the {{Code|-}}, the order is descending, otherwise it is ascending; |
+ | |||
Inputs: | Inputs: | ||
:* A dictionary with ''OBJECT'''s properties to restrict the resulting list. | :* A dictionary with ''OBJECT'''s properties to restrict the resulting list. | ||
+ | |||
Returns: | Returns: | ||
:* An array of dictionaries with ''OBJECT'' properties, dictionaries contain at least {{Code|guid}} property. | :* An array of dictionaries with ''OBJECT'' properties, dictionaries contain at least {{Code|guid}} property. | ||
− | /'''get'''?guid=<>[&properties=<PROP>[,..]] | + | /<OBJECT>/'''get'''?guid=<>[&properties=<PROP>[,..]] |
+ | |||
+ | Return ''OBJECT'' properties the of particular item. | ||
− | |||
Where: | Where: | ||
− | :* {{Code|properties}} ''str'' | + | :* {{Code|properties}}, ''str''<br>coma separated list of ''OBJECT'' properties to return; by default, return all properties. |
+ | |||
Returns: | Returns: | ||
:* A dictionary with ''OBJECT'' properties that contains at least {{Code|guid}} property. | :* A dictionary with ''OBJECT'' properties that contains at least {{Code|guid}} property. | ||
− | === | + | === player === |
+ | |||
+ | Properties: | ||
+ | :* {{Code|nickname}}, ''str'', ''read''<br>set by Sugar Shell; | ||
+ | :* {{Code|color}}, ''str'', ''read''<br>colors pair in format {{Code|#RRGGBB,#RRGGBB}}, set by Sugar Shell. | ||
+ | |||
+ | Calculated properties: | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current ''player'''s reputation based on: | ||
+ | :** direct votes from other players, | ||
+ | :** votes given to objects where the ''player'' is a creator; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
+ | |||
+ | Events: | ||
+ | |||
+ | Actions: | ||
+ | |||
+ | * '''create''' and '''destroy''' are not allowed; | ||
+ | * '''update''' is allowed only for a user who is associated with a ''player''. | ||
+ | |||
+ | /player/'''send'''?guid=<PLAYER> | ||
+ | |||
+ | Send private message to the ''PLAYER'', sender should be different to the ''PLAYER''. | ||
+ | |||
+ | Inputs: | ||
+ | : A dictionary with [[#event|event]] properties. | ||
+ | |||
+ | === project === | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for the team members<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for the team members<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|type}}, ''str'', ''read'', ''write'' only for the team members<br>the project type: | ||
+ | :** {{Code|general}}, | ||
+ | :** {{Code|activity}}, | ||
+ | :** {{Code|wiki}}, | ||
+ | :** {{Code|gallery}}; | ||
+ | :* {{Code|zoom}}, ''str'', ''read'', ''write'' only for the team members<br>Network Zoom level that project belongs: | ||
+ | :** {{Code|worldwide}}, | ||
+ | :** {{Code|neighbourhood}}, | ||
+ | :** {{Code|private}}. | ||
+ | |||
+ | Calculated properties: | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current ''project'''s reputation based on: | ||
+ | :** direct votes from other players, | ||
+ | :** votes given to related objects if theirs ''respect'' property is empty; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not. | ||
+ | |||
+ | Many-to-many relations: | ||
+ | :* ''team'', relates to ''player''. | ||
+ | |||
+ | Actions: | ||
+ | |||
+ | * right after '''create''' call, the creator ''player'' will be the only ''team'' member; | ||
+ | * '''update''' and '''destroy''' are allowed only for ''team'' members. | ||
+ | |||
+ | /project/'''add_member'''?guid=<PROJECT>&member=<PLAYER> | ||
+ | |||
+ | Make a ''PLAYER'' the ''team'' member. Only ''team'' members can call this action. | ||
+ | |||
+ | /project/'''remove_member'''?guid=<PROJECT>&member=<PLAYER> | ||
+ | |||
+ | Remove ''PLAYER'' from the to the ''team''. Only ''team'' member can call this action if he is not the ''PLAYER'' and ''PLAYER'' is not the same as ''creator''. | ||
+ | |||
+ | === question === | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for creator<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted; | ||
+ | :* {{Code|solution}}, ''guid'', ''read'', ''write'' only by creator<br>the ''solution'' which solves the object. | ||
+ | |||
+ | Calculated properties: | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
+ | :* {{Code|implementation_status}}, ''str'', ''read''<br>if ''question'' has an associated ''objective'', this ''objective'''s status is a status of the ''question'', otherwise the property is empty. | ||
+ | |||
+ | === idea === | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for creator<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted. | ||
+ | |||
+ | Calculated properties: | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
+ | :* {{Code|implementation_status}}, ''str'', ''read''<br>if ''idea'' has an associated ''objective'', this ''objective'''s status is a status of the ''idea'', otherwise the property is empty. | ||
+ | |||
+ | === problem === | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for creator<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted; | ||
+ | :* {{Code|solution}}, ''guid'', ''read'', ''write'' only by creator<br>the ''solution'' which solves the object. | ||
+ | |||
+ | Calculated properties: | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
+ | :* {{Code|implementation_status}}, ''str'', ''read''<br>if ''problem'' has an associated ''objective'', this ''objective'''s status is a status of the ''problem', otherwise the property is empty. | ||
+ | |||
+ | === solution === | ||
+ | |||
+ | The solution for ''question''/''idea''/''problem'' objects. | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|text}}, ''wikitext'', ''read'', ''write'' only for creator<br>solution text; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted. | ||
+ | |||
+ | Calculated properties: | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not. | ||
+ | |||
+ | === wiki === | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for creator<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted; | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
+ | |||
+ | === gallery === | ||
+ | |||
+ | Properties: | ||
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for creator<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted; | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
− | === | + | === objective === |
− | + | Properties: | |
+ | :* {{Code|title}}, ''str'', ''read'', ''write'' only for the team members<br>one line title; | ||
+ | :* {{Code|description}}, ''str'', ''read'', ''write'' only for the team members<br>multi lined description; | ||
+ | :* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object; | ||
+ | :* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the ''project'' itself will be voted; | ||
+ | :* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation; | ||
+ | :* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not; | ||
− | === | + | === release === |
− | === | + | === comment === |
− | === | + | === event === |
− | |||
− | == | + | == Many-to-many relations == |
− | == | + | == Changelog == |
− | + | This section shows how API is evolving. The API state is being described by a version. The major number is being changed only if backwards compatibility was broken. | |
− | + | '''1.0''' | |
+ | : Not yet released API. | ||
== Notifications == | == Notifications == |
Revision as of 01:07, 19 December 2011
This page describes the APi that Sugar Network clients use to interact with Sugar Network server. See also technical introduction page.
Overview
The API is RESTful and being served via HTTP(S) using JSON notation.
The common RESTful url format is:
http[s]://<SERVER>/<OBJECT>/<ACTION>?<AUTH-TOKEN>=<VALUE>[&<ARG>=<VALUE>]..]
For the beginning, API is not secure for reasons:
- Implement initial version in short period of time;
- The only users, for the beginning, are teachers and students from one-teacher scholls.
In particular:
- API is being provided only via HTTP;
- The AUTH-TOKEN is the
uid
which is a hashed value from Sugar profile public SSH key (the same as JID value in Sugar Shell but without the domain part) that does not require any handshake procedures.
The OBJECT value is one of the following objects. When ACTION and a set of ARGs depend on OBJECT. Besides, particular ACTION can input and return data in JSON notation. If ACTION was failed, it returns the JSON directory that contains error
key with error message.
Objects
Common actions
Actions might be restricted for particular object, see the corresponding section for detailed information.
/<OBJECT>/create
Create new OBJECT item.
Inputs:
ctime
, int
the UNIX seconds time of entry creation; optional, will be set on a server side otherwise;mtime
, int
the UNIX seconds time of entry modification; optional, will be set on a server side otherwise;
Returns:
guid
, str
globally unique identifier that specifies created item;
/<OBJECT>/update?guid=<>
Modify the specified OBJECT item.
Inputs:
- Keys that need to be modified.
/<OBJECT>/delete?guid=<>
Delete the specified OBJECT item. The real destroying won't happen, the item will be hidden. The garbage collection of hidden items will be processed by Network administrators.
/<OBJECT>/find?[query=<>][&offset=<>][&limit=<>][&properties=<PROP>[,..]][&order_by=[+|-]<PROP>[,..]]
Find OBJECT items.
Where:
query
, str
search request in Xapian notation;offset
, int
start index to return entries from;limit
, int
do not return more then specified value;properties
, str
coma separated list of OBJECT properties to return; by default, return all properties;order_by
, str
coma separated list of OBJECT properties to sort the resulting list; if an property starts with the-
, the order is descending, otherwise it is ascending;
Inputs:
- A dictionary with OBJECT's properties to restrict the resulting list.
Returns:
- An array of dictionaries with OBJECT properties, dictionaries contain at least
guid
property.
- An array of dictionaries with OBJECT properties, dictionaries contain at least
/<OBJECT>/get?guid=<>[&properties=<PROP>[,..]]
Return OBJECT properties the of particular item.
Where:
properties
, str
coma separated list of OBJECT properties to return; by default, return all properties.
Returns:
- A dictionary with OBJECT properties that contains at least
guid
property.
- A dictionary with OBJECT properties that contains at least
player
Properties:
nickname
, str, read
set by Sugar Shell;color
, str, read
colors pair in format#RRGGBB,#RRGGBB
, set by Sugar Shell.
Calculated properties:
reputation
, int, read
current player's reputation based on:- direct votes from other players,
- votes given to objects where the player is a creator;
vote
, bool, read, write
did url requester voted for the current object or not;
Events:
Actions:
- create and destroy are not allowed;
- update is allowed only for a user who is associated with a player.
/player/send?guid=<PLAYER>
Send private message to the PLAYER, sender should be different to the PLAYER.
Inputs:
- A dictionary with event properties.
project
Properties:
title
, str, read, write only for the team members
one line title;description
, str, read, write only for the team members
multi lined description;creator
, guid, read
the player who created the object;type
, str, read, write only for the team members
the project type:general
,activity
,wiki
,gallery
;
zoom
, str, read, write only for the team members
Network Zoom level that project belongs:worldwide
,neighbourhood
,private
.
Calculated properties:
reputation
, int, read
current project's reputation based on:- direct votes from other players,
- votes given to related objects if theirs respect property is empty;
vote
, bool, read, write
did url requester voted for the current object or not.
Many-to-many relations:
- team, relates to player.
Actions:
- right after create call, the creator player will be the only team member;
- update and destroy are allowed only for team members.
/project/add_member?guid=<PROJECT>&member=<PLAYER>
Make a PLAYER the team member. Only team members can call this action.
/project/remove_member?guid=<PROJECT>&member=<PLAYER>
Remove PLAYER from the to the team. Only team member can call this action if he is not the PLAYER and PLAYER is not the same as creator.
question
Properties:
title
, str, read, write only for creator
one line title;description
, str, read, write only for creator
multi lined description;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted;solution
, guid, read, write only by creator
the solution which solves the object.
Calculated properties:
reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not;implementation_status
, str, read
if question has an associated objective, this objective's status is a status of the question, otherwise the property is empty.
idea
Properties:
title
, str, read, write only for creator
one line title;description
, str, read, write only for creator
multi lined description;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted.
Calculated properties:
reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not;implementation_status
, str, read
if idea has an associated objective, this objective's status is a status of the idea, otherwise the property is empty.
problem
Properties:
title
, str, read, write only for creator
one line title;description
, str, read, write only for creator
multi lined description;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted;solution
, guid, read, write only by creator
the solution which solves the object.
Calculated properties:
reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not;implementation_status
, str, read
if problem has an associated objective, this objectives status is a status of the problem', otherwise the property is empty.
solution
The solution for question/idea/problem objects.
Properties:
text
, wikitext, read, write only for creator
solution text;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted.
Calculated properties:
reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not.
wiki
Properties:
title
, str, read, write only for creator
one line title;description
, str, read, write only for creator
multi lined description;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted;reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not;
gallery
Properties:
title
, str, read, write only for creator
one line title;description
, str, read, write only for creator
multi lined description;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted;reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not;
objective
Properties:
title
, str, read, write only for the team members
one line title;description
, str, read, write only for the team members
multi lined description;creator
, guid, read
the player who created the object;respect
, guid, read, create
what player needs to be respected on getting vote to this object, if empty, the project itself will be voted;reputation
, int, read
current object's reputation;vote
, bool, read, write
did url requester voted for the current object or not;
release
comment
event
Many-to-many relations
Changelog
This section shows how API is evolving. The API state is being described by a version. The major number is being changed only if backwards compatibility was broken.
1.0
- Not yet released API.