Changes

Jump to navigation Jump to search
3,828 bytes added ,  08:56, 27 September 2014
Line 1: Line 1: −
This page describes the API that Sugar Network clients use to interact with Sugar Network server. See also a guide to basic Sugar Network [[Sugar_Network/Concept|concepts]] and [[Platform_Team/Sugar_Network/Architecture|its twin page]] from technical point of view. Besides, visit the [[Sugar_Network|introduction page]].
+
This page describes the API that Sugar Network clients use to interact with a Sugar Network server. See also a guide to basic Sugar Network [[Sugar_Network/Concept|concepts]] and [[Platform_Team/Sugar_Network/Architecture|its twin page]] for a technical point of view. In addition, visit the [[Sugar_Network|introduction page]].
 +
 
 +
{{Note/warning|Note|Until announcing API freeze, this document describes the most recent development version of the API.<br>You can find its implementation on the [[#API servers|node-devel.sugarlabs.org]] server.}}
    
== Overview ==
 
== Overview ==
   −
To better understand this API, see technical explanation of the [[Platform_Team/Sugar_Network/Architecture#Conceptual_level|conceptual level]] and [[Platform_Team/Sugar_Network/Objects_model|objects model]] in particular.
+
To better understand this API, see a technical explanation of its [[Platform_Team/Sugar_Network/Architecture#Conceptual_level|conceptual level]] and [[#Sugar_Network_resources|objects model]] in particular.
   −
The API operates with [[Sugar Network]] [[#Sugar_Network_resources|resources]] that are collections of objects. All objects are identified by global unique identifiers, GUIDs. Resources might support [[#Common_actions|common actions]]. While processing requests, server might generate [[#Notifications|events]]. Besides, API provides [[#Additional_resources|extra resources]] that are not [[Sugar Network]] objects.
+
The API operates with [[Sugar Network]] [[#Sugar_Network_resources|resources]], which are collections of objects. All objects are identified by globally unique identifiers, GUIDs, and available for operation via [[#Base_API|basic actions]]. The API is being provided from a [[#API_servers|node server]] or a [[#Client_API|client]]. While processing requests, API providers generate [[#Notifications|events]].
   −
The API is [[Wikipedia:Restful|RESTful]] and being served via HTTP(S) using [[Wikipedia:Json|JSON]] notation. The common RESTful request url format is:
+
The API is [[Wikipedia:Restful|RESTful]], and is served via HTTP(S) using [[Wikipedia:Json|JSON]] notation. The common request url format is:
   −
  http[s]://<SERVER>[/<RESOURCE>[/<GUID>[/<PROPERTY>]]][?[cmd=<COMMAND>][&<ARGUMENT>=<VALUE>..]]
+
  http[s]://''SERVER''[/''RESOURCE''[/''GUID''[/''PROPERTY'']]][?[cmd=''COMMAND''][&''ARGUMENT''=''VALUE''..]]
    
When:
 
When:
    
* {{Code|SERVER}}, [[#API_servers|particular]] Sugar Network API server;
 
* {{Code|SERVER}}, [[#API_servers|particular]] Sugar Network API server;
* {{Code|RESOURCE}}, name one of the [[#Resources|existing]] resources;
+
* {{Code|RESOURCE}}, name one of the [[#Sugar_Network_resources|existing]] resources;
 
* {{Code|GUID}}, the {{Code|RESOURCE}}'s particular object;
 
* {{Code|GUID}}, the {{Code|RESOURCE}}'s particular object;
 
* {{Code|PROPERTY}}, particular property of {{Code|GUID}} object;
 
* {{Code|PROPERTY}}, particular property of {{Code|GUID}} object;
 
* {{Code|COMMAND}}, optional command name; combination of HTTP request method ({{Code|GET}}, {{Code|POST}}, {{Code|PUT}}, or, {{Code|DELETE}}) and [possibly empty] {{Code|COMMAND}} composes the requested [[#Actions|action]];
 
* {{Code|COMMAND}}, optional command name; combination of HTTP request method ({{Code|GET}}, {{Code|POST}}, {{Code|PUT}}, or, {{Code|DELETE}}) and [possibly empty] {{Code|COMMAND}} composes the requested [[#Actions|action]];
* {{Code|ARGUMENT}}s and {{Code|VALUE}}s depend on particular [[#Actions|action]].
+
* {{Code|ARGUMENT}}s and {{Code|VALUE}}s depend on the particular [[#Actions|action]].
   −
If request needs to send data, it should send Python dictionary converted to [[Wikipedia:Json|JSON]] notation.
+
In most cases, the server replies in JSON notation. If a request fails, the replied JSON object will contain a {{Code|request}} key, with the original request, and {{Code|error}} key, with an error message.
   −
In [[#Common_actions|most cases]], server replies with dictionary in JSON notation. If request was failed, the replied dictionary will contain {{Code|request}}, with original request, and {{Code|error}}, with error message, keys. In the rest of cases, response might be variable.
+
== API version ==
   −
== API servers ==
+
Sugar Network nodes might support multiple API versions at once but only one of them is default, i.e., the one which is in use if clients do not specify particular API version. To specify API versions in client request, setup the {{Code|X-API}} HTTP header with chosen version. If such header is omitted, default version will be used by the node;
 +
 
 +
Currently available API versions:
 +
 
 +
* ''0.1'' initial API implementation, should not be used;
 +
* ''0.2'' the most recent version, the rest of the document describes exactly this version.
 +
 
 +
== Nodes ==
    
These are standard Sugar Network API servers publicly available.
 
These are standard Sugar Network API servers publicly available.
   −
* [http://api-devel.network.sugarlabs.org/ api-devel.network.sugarlabs.org]<br>Development server that is being updated to keep it synchronized with this document; it does not contain important data and free for any experiments;
+
* [http://node-devel.sugarlabs.org/ node-devel.sugarlabs.org]<br>Development server which does not contain important data and is free for any experiments (administrative privileges for anonymous users); default API version is ''0.2'';
   −
* [http://api-testing.network.sugarlabs.org/ api-testing.network.sugarlabs.org]<br>Recent stable release with data that is being used in pilots; do not create temporal content here, use devel server instead;
+
* [http://node-testing.sugarlabs.org/ node-testing.sugarlabs.org]<br>Recent stable release with regular data import from the production server; is still free for any experiments; default API version is ''0.1'';
   −
* [http://localhost:5001/ localhost:5001]<br>default url to get access to [[#Local_access|local data]] served from local application.
+
* [http://node.sugarlabs.org/ node.sugarlabs.org]<br>Production server;
   −
== Sugar Network resources ==
+
* [http://localhost:5001/ localhost:5001]<br>default url to get access to [[#Client_API|local proxy]] provided from user side application; ; default API version is ''0.1''.
   −
{{:Platform_Team/Sugar_Network/Objects_model}}
+
== Resources ==
   −
=== Authentication ===
+
{{:Sugar_Network/Resources}}
   −
Right now, the only way to be authenticated on a Sugar Network server is running {{Code|sugar-network-service}} on client side and use API it [[#Local_access|provides]].
+
== Base API ==
   −
''TODO''
+
List of actions common of all API providers.
   −
=== Authorization ===
+
<div id="POST"></div>
   −
Read-only access is available for anonymous requests, except special content like machine serial numbers. But to proceed any changes, clients need to be authenticated.
+
'''POST''' /''RESOURCE''
   −
Right after creating any Sugar Network object, its author becomes the only user who can process any object modifications afterwards. Authority information will be auto set in [[#Sugar_Network_resources|authority]] property which is a dictionary of ''User'' guids and integers with roles information. Authority can be changed (by users already mentioned in the {{Code|authority}} property) by the following commands:
+
Create new resource object.
   −
'''PUT''' /''RESOURCE''/''GUID''?cmd='''useradd'''&user=''USER''&role=''ROLE''
+
JSON object keys to send:
 +
* {{Code|''RESOURCE}}'s properties.
   −
Add another user who can modify the corresponding object.
+
JSON object keys to receive:
 +
* {{Code|guid}}, with globally unique identifier that specifies the created object.
   −
'''PUT''' /''RESOURCE''/''GUID''?cmd='''userdel'''&user=''USER''
+
<div id="PUT"></div>
   −
Remove user from the authority list. It is not possible to remove yourself.
+
'''PUT''' /''RESOURCE''/''GUID''
   −
''TODO''
+
Modify resource object. By default, might be called only by {{Code|GUID}} creator.
   −
=== Common actions ===
+
JSON object keys to send:
 +
* {{Code|RESOURCE}}'s properties to modify.
   −
List of actions common of all resources.
+
<div id="DELETE"></div>
   −
  '''POST''' /<RESOURCE>
+
  '''DELETE''' /''RESOURCE''/''GUID''
   −
Create new resource object.
+
Delete resource object. Actual object destruction won't happen, the object will be hidden. Garbage collection of hidden objects will be processed by Network administrators. By default, this action may be called only by the {{Code|GUID}} creator.
   −
Dictionary to send:
+
<div id="GET"></div>
: {{Code|''RESOURCE}}'s properties.
     −
Dictionary keys to receive:
+
'''GET''' /''RESOURCE''[?offset=''INTEGER''][&limit=''INTEGER''][&query=''STRING''][&reply=''PROP''][&order_by=<nowiki>[+|-]</nowiki>''PROP''][&group_by=''PROP''][&''PROP''=''VALUE''][&''!PROP''=''VALUE'']
:* {{Code|guid}}, with globally unique identifier that specifies created object.
     −
'''PUT''' /<RESOURCE>/<GUID>
+
Find resource objects.
   −
Modify resource object. By default, might be called only by {{Code|GUID}} creator.
+
Where:
 +
* {{Code|offset}}, ''int''<br>start index to return entries from, the default value is {{Code|0}};
 +
* {{Code|limit}}, ''int''<br>do not return more then specified value, maximal and default values are being setup on server side;
 +
* {{Code|query}}, ''str''<br>search request in [http://xapian.org/docs/queryparser.html Xapian] notation; if property is boolean, integer or datetime, it supports searching by ranges, i.e., {{Code|''PROP'':[''START'']..[''END'']}};
 +
* {{Code|PROP}}, ''str''<br>supplements {{Code|query}} with filtering by exact value of the {{Code|PROP}} property; the resulting query string will be {{Code|''PROP''<nowiki>=</nowiki>''VALUE'' AND (''QUERY'')}}; argument is multiple;
 +
* {{Code|!PROP}}, ''str''<br>supplements {{Code|query}} by excluding exact value of the {{Code|PROP}} property; the resulting query string will be {{Code|NOT ''PROP''<nowiki>=</nowiki>''VALUE'' AND (''QUERY'')}}; argument is multiple;
 +
* {{Code|reply}}, ''str''<br>''RESOURCE'' properties to return; by default, return only {{Code|guid}} property; argument is multiple;
 +
* {{Code|order_by}}, ''str''<br>property to sort the resulting list by; if starts with the {{Code|-}}, the order is descending, otherwise it is ascending;
 +
* {{Code|group_by}}, ''str''<br>property name to group resulting list by.
   −
Dictionary to send:
+
JSON object keys to receive:
: {{Code|RESOURCE}}'s properties to modify.
+
* {{Code|total}}, total number in requested query (the reply might contain only the portion restricted by {{Code|limit}} request argument);
 +
* {{Code|result}}, an array of dictionaries with resource object properties, dictionaries contain at least {{Code|guid}} property.
   −
'''DELETE''' /<RESOURCE>/<GUID>
+
<div id="GET-resource"></div>
   −
Delete resource object. The real destroying won't happen, the object will be hidden. The garbage collection of hidden objects will be processed by Network administrators. By default, might be called only by {{Code|GUID}} creator.
+
'''GET''' /''RESOURCE''/''GUID''[?reply=''PROP'']
   −
'''GET''' /<RESOURCE>?offset=<INTEGER>&limit=<INTEGER>[&query=<STRING>][&reply=<PROP>[,..]][&order_by=<nowiki>[+|-]</nowiki><PROP>][&group_by=<PROP>][&<QUERY_PROP>=<VALUE>[&...]]
+
Where:
 +
* {{Code|reply}}, ''str''<br>''RESOURCE'' properties to return; by default, return only {{Code|guid}} property; argument is multiple;
   −
Find resource objects.
+
Return properties for a particular resource object.
   −
Where:
+
JSON object keys to receive:
:* {{Code|offset}}, ''int''<br>start index to return entries from;
+
* properties that were specified in {{Code|reply}} argument(s), at least {{Code|guid}}.
:* {{Code|limit}}, ''int''<br>do not return more then specified value;
  −
:* {{Code|query}}, ''str''<br>search request in [http://xapian.org/docs/queryparser.html Xapian] notation with the following additions:
  −
:** if property is boolean, integer or datetime, it supports searching by ranges: {{Code|<PROP>:[<START>]..[<END>]}};
  −
:** the statement {{Code|<nowiki><PROP>:=["]<VALUE>["]</nowiki>}} means {{Code|(<THE-REST_QUERY>) AND <EXACT-PROP-SEARCH>}} with searching {{Code|PROP}} for exact {{Code|VALUE}}; it is different to regular {{Code|<PROP>:<VALUE>}} where {{Code|VALUE}} might be a substring of exact {{Code|PROP}} value;
  −
:* {{Code|QUERY_PROP}}, ''str''<br>supplement {{Code|query}} with filtering by property value, the resulting query string will be {{Code|<nowiki>QUERY_PROP=VALUE AND (query)</nowiki>}};
  −
:* {{Code|reply}}, ''str''<br>coma separated list of ''RESOURCE'' properties to return; by default, return only {{Code|guid}} property;
  −
:* {{Code|order_by}}, ''str''<br>property to sort the resulting list by; if starts with the {{Code|-}}, the order is descending, otherwise it is ascending;
  −
:* {{Code|group_by}}, ''str''<br>property name to group resulting list by.
     −
Dictionary keys to receive:
+
<div id="PUT-property"></div>
:* {{Code|total}}, total number in requested query (the reply might contain only portion restricted by {{Code|limit}} request argument);
  −
:* {{Code|result}}, an array of dictionaries with resource object properties, dictionaries contain at least {{Code|guid}} property.
     −
  '''GET''' /<RESOURCE>/<GUID>[?reply=<PROP>[,..]]
+
  '''PUT''' /''RESOURCE''/''GUID''/''PROP''
   −
Return properties for particular resource object.
+
Modify particular resource property. By default, might be called only by {{Code|GUID}} creator.
   −
Dictionary keys to receive:
+
<div id="GET-property"></div>
:* properties that were specified in {{Code|reply}} argument(s), at least {{Code|guid}}.
     −
  '''GET''' /<RESOURCE>/<GUID>/<PROPERTY>
+
  '''GET''' /''RESOURCE''/''GUID''/''PROP''
    
Return property value for particular resource object.
 
Return property value for particular resource object.
    
Data to receive:
 
Data to receive:
:* property value in JSON notation.
+
* property value in JSON notation for regular properties;
 +
* raw data or redirection for BLOB properties.
 +
 
 +
=== Aggregated properties ===
 +
 
 +
[[#resource-types|Aggregated]] properties have special API to treat their content.
 +
 
 +
<div id="POST-aggproperty"></div>
 +
 
 +
'''POST''' /''RESOURCE''/''GUID''/''PROP''
 +
 
 +
Submit new item. The command returns an id for newly created aggregated item. Depending on particular property, new items might be created not only by object's authors.
 +
 
 +
<div id="PUT-aggproperty"></div>
   −
=== Download activities ===
+
'''PUT''' /''RESOURCE''/''GUID''/''PROP''/''ID''
   −
To download Sugar Activity bundle from the Sugar Network, it is required to find out the GUID of ''Implementation'' with needed activity version. To make this process more convenient for users, there is special command that requires only ''Context'' GUID (which is, in most cases, equal to Sugar Activity bundle id).
+
Update existing aggregated item. Depending on particular property, the command is allowed either to object's authors or to aggregated item submitter.
   −
'''GET''' /context/''GUID''?cmd='''clone'''[&version=''VERSION''][&stability=''STABILITY''][&requires=''REQUIRES'',..]
+
<div id="DELETE-aggproperty"></div>
   −
This command finds out required ''Implementation'', using passed parameters, and returns its bundle. Command parameters are:
+
'''DELETE''' /''RESOURCE''/''GUID''/''PROP''/''ID''
   −
* {{Code|VERSION}}<br>Version to download; if omitted, most recent will be used;
+
Delete existing aggregated item. Depending on particular property, the command is allowed either to object's authors or to aggregated item submitter.
* {{Code|STABILITY}}<br>[[#Sugar_Network_resources|stability]] ''Implementation'' value; if omitted, ''stable'' will be used;
  −
* {{Code|REQUIRES}}<br>while uploading new versions, system will keep dependency information in ''requires'' property of ''Implementations'' resources; it is not strict information and is not being used for processing dependencies while launching, ''requires'' property exists only to simplify users driven searching; {{Code|REQUIRES}} specifies ''requires'' property to search versions (option might be multiple); for the first time, the only guarantied ''requires'' values are {{Code|sugar-''VERSION''}} with information what Sugar Shell required.
      
=== Notifications ===
 
=== Notifications ===
Line 136: Line 156:  
To start subscription, send the following request:
 
To start subscription, send the following request:
   −
  '''GET''' /?cmd='''subscribe'''[&only_commits=1]
+
  '''GET''' /?cmd='''subscribe'''
 
  −
Where:
  −
* {{Code|only_commits}},<br>subscribers can be notified only with ''commit'' events; that is useful to minimize interactions between server and clients.
      
Response will be served with ''text/event-stream'' MIME type for default SSE message type. SSE message will be a JSONified object with the following, at least, attributes:
 
Response will be served with ''text/event-stream'' MIME type for default SSE message type. SSE message will be a JSONified object with the following, at least, attributes:
Line 145: Line 162:  
* {{Code|event}}<br>event type.
 
* {{Code|event}}<br>event type.
   −
=== Usage statistics ===
+
== Node API ==
   −
In order to collect [[Platform_Team/Usage_Statistics|usage statistics]] gathered in local users' environment by [[Platform_Team/Server_Kit/sugar-client|sugar-client]], API provides related commands for ''User'' [[Sugar Network]] resource.
+
This is an API provided by Sugar Network nodes on top of [[#Base_API|base one]].
   −
'''GET''' /user/''GUID''?cmd='''stats-info'''
+
=== Authentication ===
   −
Returns a dictionary with RRD configuration settings for local stats collecting process that user side should use to avoid problems while uploading stats to the server.
+
Right now, the only way to be authenticated on a Sugar Network server is by running a [[Platform_Team/Sugar_Network/Implementation#sugar-network-client|local application]] on the client side and using the API it [[#Client_API|provides]].
   −
'''POST''' /user/''GUID''?cmd='''stats-upload'''
+
''TODO''
   −
Upload statistics. Request content should be in JSON notation and be a dictionary of:
+
=== Authorization ===
   −
* {{Code|name}} name of RRD database to upload stats to;
+
Read-only access is available for anonymous requests, except special content like machine serial numbers. But to process any changes, clients need to be authenticated.
* {{Code|values}} an array of {{Code|timestamp, row}} tuples when {{Code|row}} is a dictionary of database field names and values.
     −
=== GNU/Linux packages metadata ===
+
Right after creating any Sugar Network object, its author becomes the only user who can process any object modifications afterwards. Authority information will be kept in the [[#Sugar_Network_resources|author]] property and can be modified using the following commands.
   −
There is a special Project resource, ''Packages''. This project is intended to support a metadata ''database'' for all GNU/Linux packages that are being used as dependencies for activities Sugar Network provides.
+
'''PUT''' /''RESOURCE''/''GUID''?cmd='''useradd'''&user=''USER''&role=''ROLE''
   −
Every entry in the ''Packages'' project is a map of native package names to a particular GNU/Linux distribution. So, activities mention only ''Packages'' entry name as a dependency. Afterwards, on a client side, a ''Packages'' entry name will be resolved to a package name according to the local distribution and it will be passed to the PackageKit to install corresponding dependency.
+
Add another user who can modify the corresponding object. ''USER'' argument should be either ''User'' guid (for authors registered in the Sugar Network), or, full author name.
   −
''Packages'' project might be considered as a temporal solution when, and if, [http://distributions.freedesktop.org/wiki/AppStream/MetadataNotes AppStream's MetadataNotes] will be reused in the future.
+
'''PUT''' /''RESOURCE''/''GUID''?cmd='''userdel'''&user=''USER''
   −
== Additional resources ==
+
Remove user from the authority list. It is not possible to remove yourself. ''USER'' argument should be either ''User'' guid (for authors registered in the Sugar Network), or, full author name.
   −
In addition to direct Sugar Network [[#Resources|resources]], API provides related content.
+
''TODO''
   −
=== packagekit-backend-presolve ===
+
=== Retrieving releases ===
   −
In order to provide GNU/Linux-distribution-agnostic launches of activities, Sugar Network API supports [[Platform_Team/packagekit-backend-presolve|packagekit-backend-presolve]] users.
+
To easy download Context [[#context-releases|releases]] and avoid reading raw ''Context.releases'' property, there are special high-level API commands.
   −
API server provides the following kinds of urls:
+
<div id="GET-solve"></div>
   −
* {{Code|'''GET''' /packages}}<br>list all supported platforms;
+
'''GET''' /context/''GUID''?cmd='''solve'''[&lsb_id=''LSB_ID''][&lsb_release=''LSB_RELEASE''][&assume=''DEPENDENCY''-''VERSION'']
* {{Code|'''GET''' /packages/<PLATFORM>}}<br>list all supported packages for a particular platform;
+
 
* {{Code|'''GET''' /packages/<PLATFORM>/<PACKAGE>}}<br>pre-solved dependency graph for a particular package.
+
The command returns information about what particular releases should be downloaded depending on provided requirements. This command might return not only one release, e.g., activities might have dependencies either system packages or another Sugar Network Contexts.
 +
 
 +
Solving requirements might be:
 +
 
 +
* {{Code|LSB_ID}}, if Context releases depend on system packages, specify the [[Wikipedia:Linux_Standard_Base|LSB]] distributor id to consider while choosing particular packages;
 +
* {{Code|LSB_RELEASE}}, if Context releases depend on system packages, specify the [[Wikipedia:Linux_Standard_Base|LSB]] release number of the distribution to consider while choosing particular packages;
 +
* {{Code|DEPENDENCY-VERSION}}, the {{Code|assume}} argument instructs server to assume that specified [[Sugar_Network/Recipe_Specification#Dependencies|dependency]] is already available on client side and should be taken into account while solving; this is especially important for package dependencies when server considers packages available only from official repositories but users might have more recent package versions installed in local system; e.g., the above example request will fail without {{Code|sugar-0.94}} because neither {{Code|lsb_id}} nor {{Code|lsb_release}} were specified (even if LSB information is passed, server might not have information about what package versions come from official repositories).
 +
 
 +
The resulting info is a JSON object with keys equal to Context guids and value objects for chosen release with the following keys:
 +
 
 +
* {{Code|blob}}, bundle [[#resource-types|digest]] to download;
 +
* {{Code|version}}, chosen version number;
 +
* {{Code|title}}, the ''Context.title'' value;
 +
* {{Code|command}}, a command to launch the bundle, only for Sugar activities.
 +
 
 +
For example, the {{Code|'''GET''' <nowiki>/context/org.laptop.TurtleArtActivity?cmd=solve&assume=sugar-0.94</nowiki>}} request returns:
 +
 
 +
{
 +
  "org.laptop.TurtleArtActivity": {
 +
    "title": "Turtle Blocks",
 +
    "version": "202",
 +
    "blob": "http://download.sugarlabs.org/activities/4027/turtleblocks-202.xo",
 +
    "content-type": "application/vnd.olpc-sugar",
 +
    "size": 4715955,
 +
    "unpack_size": 12873871,
 +
    "command": "sugar-activity TurtleArtActivity.TurtleArtActivity",
 +
  },
 +
  "sugar": {
 +
    "version": "0.94",
 +
  },
 +
}
 +
 
 +
<div id="GET-clone"></div>
 +
 
 +
Like the [[#GET-solve|solve]] command, ''clone'' makes a solution but returns bundle itself, so, there is no way to get information about possible dependencies.
 +
 
 +
'''GET''' /context/''GUID''?cmd='''clone'''[&lsb_id=''LSB_ID''][&lsb_release=''LSB_RELEASE''][&assume=''DEPENDENCY''-''VERSION'']
 +
 
 +
=== Upload releases ===
 +
 
 +
To easy upload Context [[#context-releases|releases]] and avoid writing to raw ''Context.releases'' property, there is a special high-level API command.
 +
 
 +
'''POST''' /context?cmd='''submit'''[&''PROP''=''VALUE''][&initial]
 +
 
 +
Where the {{Code|PROP}} arguments are optional release properties. The {{Code|initial}} argument asks the system to create new Context resource new release will belong to.
 +
 
 +
The posting data might be two types,
 +
 
 +
* Sugar activities in .xo bundles,<br>there is no need in {{Code|PROP}} arguments, all properties will be populated basing on metadata from a .xo bundle; including release notes from the {{Code|CHANGELOG}} file in [[Wikipedia:Markdown|Markdown]] notation; besides, only in this case {{Code|initial}} makes sense because it is the only way to get Context properties;
 +
 
 +
* Arbitrary data,<br>all required release properties should be specified in {{Code|PROP}} arguments, at least ''context'' and ''version''; ''license'' should be specified only if there are no existing releases to pickup license from.
 +
 
 +
=== Node statistics ===
 +
 
 +
The node statistics are about the entire server and depersonalized. Statistics are being collected by analyzing regular requests to an API server and stored for each Sugar Network node. To read such info, call the command:
 +
 
 +
'''GET''' /?cmd='''stats'''[&start=''SECONDS''][&end=''SECONDS''][&event=''EVENT''][&limit=''NUMBER'']
    
Where:
 
Where:
   −
* {{Code|PLATFORM}}<br>one of supported packagekit-backend-presolve platforms, e.g., OLPC-13.0.1;
+
* {{Code|start}} and {{Code|end}} is a time interval to get statistics for; if omitted, the beginning and the end of entire life cycle will be used;
* {{Code|PACKAGE}}<br>a name of the particular package.
+
* {{Code|event}}, multiple argument to specify what stats should be returned; if omitted, return all sources;
 +
* {{Code|limit}}, number of stat records to return for the {{Code|start}}-{{Code|end}} interval; note that this amount is not precise, the final resultset might be smaller or bigger depending on chosen resolution; stats resolution depends on node configuration, default values are 1 day, 10 days, 30 days, 365 days; if omitted, return {{Code|end}} record only.
 +
 
 +
Possible events are:
 +
 
 +
* {{Code|users}}, total number of existing ''User'' objects;
 +
* {{Code|contexts}}, total number of existing ''Context'' objects;
 +
* {{Code|released}}, average number of newly uploaded ''Context.releases'' for specified time frame;
 +
* {{Code|solved}}, average number of requested ''Context'' [[#GET-solve|solutions]] for specified time frame; note that this value does not equal to the number of solution usages on client side since solutions might be cached;
 +
* {{Code|reported}}, average number of newly uploaded failure ''Report'' objects for specified time frame;
 +
* {{Code|topics}}, total number of top-level ''Post'' objects;
 +
* {{Code|posts}}, total number of dependent ''Post'' objects.
 +
 
 +
== Client API ==
 +
 
 +
The reasons to proxy Sugar Network data on users side:
   −
Using [[#GNU/Linux packages metadata|Packages]]' metadata, [[Sugar Network]] will automatically generate dependency graphs for packagekit-backend-presolve.
+
* Seamless support [[#Offline mode|offline workflow]];
 +
* [[#Launching|One-click launch]] Sugar activities hosted on Sugar Network.
   −
== Local access ==
+
Proxying happens by providing the same Sugar Network API (with some extra functionality, see below) from
 +
[[Platform_Team/Sugar_Network/Implementation#sugar-network-client|local process]] launched beforehand.
   −
If [[#Sugar_Network_resources|already mentioned]] resources are being provided from a network server, it is possible to get access to localhost resources served using the same API by local process launched beforehand. The reasons to provide API from local host:
+
=== Offline mode ===
   −
* Provide assess to [[#Mountpoints|original local]] Sugar Network data;
+
Being connected to a Sugar Network node, local proxy provides [[#Node_API|original API]] from the node. If the connection is lost, the proxy will switch to local Sugar Network storage and continue working providing only [[#Base_API|base API]]. Any content created in offline mode will be uploaded to the node after getting a connection back.
* Transparent treating of [[#Cloned_resources|offline accessible]] Sugar Network remote data;
  −
* Be a unified (with network server API) [[wikipedia:Inter-process_communication|IPC]] method to Sugar Network client process.
     −
=== Mountpoints ===
+
Besides, local Sugar Network storage will be reused to keep users preferences, such as:
   −
To differentiate what particular Sugar Network source is needed, requests might have {{Code|mountpoint}} argument which can be one of the following values:
+
* Favorited Contexts<br>to select preferred ''Context'' resources; these Contexts will be marked by {{Code|favorite}} value in the ''Context.layer'' property;
   −
* {{Code|/}}<br>Default mountpoint if argument was not specified; get access to remote resources, i.e., local API provider is a kind of proxy to a network server; before proxying client requests, local API provider authenticates users on a network server (for now, it is the only way to be authenticated on remote server);
+
* Checked-in Contexts<br>to keep most recent Context (for ''activity'' and ''book'' types) version in local storage to make it available in offline; note that there is no need in checking-in to speedup online lunch, versions are being [[#Launching|cached]] anyway; these Contexts will be marked by {{Code|checkin}} value in the ''Context.layer'' property.
* {{Code|~}}<br>Local Sugar Network content located in {{Code|~/.sugar/''PROFILE''/network}} directory;
  −
* {{Code|''PATH''}}<br>Absolute path in local files system to a directory with Sugar Network content, e.g., it might be content on mounted disk, {{Code|/media/DISK}}.
     −
There are the following mountpoints related commands:
+
To control users preferences there are special API commands:
   −
'''GET''' /?cmd='''mounts'''
+
<div id="PUT_favorite"></div>
   −
Returns a list of all accessible mountpoints. List items are dictionaries with the following keys:
+
'''PUT''' /context/''GUID''?cmd='''favorite'''
   −
* {{Code|mountpoint}}, mountpoint;
+
Set favorite status.
* {{Code|name}}, i18n name of the mountpoint;
  −
* {{Code|private}}, boolean flag; {{Code|True}} if the mountpoint is accessible only from localhost.
     −
=== Cloned resources ===
+
<div id="DELETE_favorite"></div>
   −
{{Code|/}} mountpoint resources might be cloned to local storage to be available in offline and out of
+
'''DELETE''' /context/''GUID''?cmd='''favorite'''
Sugar Network.
     −
Cloning is available only for the following resources:
+
Unset favorite status.
   −
* ''Context'' with ''type'' property equals to ''activity''<br>most recent activity ''Implementation'' will be placed to {{Code|~/Activities}} directory; note that there is no need in cloning activities before starting, it is possible to [[#Launch_activities|launch]] them directly;
+
<div id="PUT_checkin"></div>
* ''Context'' with ''type'' property equals to ''content''<br>most recent content ''Implementation'' will be stored in Sugar Journal;
  −
* ''Artifact'' resources<br>artifact will be stored in Sugar Journal.
     −
To track what data is cloned, there are read-only resource properties (for both {{Code|/}} and {{Code|~}} mountpoints) that make sense only for API provided from the local process:
+
'''PUT''' /context/''GUID''?cmd='''checkin'''[&spawn]
   −
* {{Code|favorite}} ''bool''<br>resources bookmarked by local user; bookmarked [and cloned] activities will appear in Home View in Sugar Shell;
+
Check-in the specified Context. By default, the command will return streamed ''text/event-stream'' MIME type data to monitor the progress. If the {{Code|spawn}} argument is specified, the command will exit immediately with [[#Notifications|asynchronous sending]] progress events.
* {{Code|clone}} ''int''<br>cloning status: {{Code|0}}, not cloned; {{Code|1}}, cloning is in progress; {{Code|2}} resource is cloned.
     −
To control cloning, there are API commands:
+
<div id="DELETE_checkin"></div>
   −
  '''PUT''' /''RESOURCE''/''GUID''?cmd='''favorite'''
+
  '''DELETE''' /context/''GUID''?cmd='''checkin'''
   −
Change favorite status. {{Code|PUT}} content should be favorite status.
+
Checkout the Context.
   −
'''PUT''' /''RESOURCE''/''GUID''?cmd='''clone'''[&force=FORCE]
+
=== Launching ===
   −
Change cloning status for the specified resource. {{Code|PUT}} content should be cloning status. If {{Code|FORCE}} is passed, cloning will happen even if local copy already exists.
+
Sugar Network Contexts (for ''activity'' and ''book'' types) can be launched as-is. The launching process is implicit and includes selecting the most recent (and appropriate for software contexts) version, downloading bundles from the Sugar Network, installing missed [[Sugar_Network/Recipe_Specification#Dependencies|software dependencies]], execution itself. All downloaded bundles will be cached [with further garbage collecting] to speedup further launching.
   −
=== Launch activities ===
+
Sugar activities will be directly executed. Book Contexts will be opened in the proper application according to its MIME type.
   −
All activities, not only from {{Code|~}} mountpoint, can be launched as-is.
+
'''GET''' /context/''GUID''?cmd='''launch'''[&args=''ARG''][&activity_id=''ACTIVITY_ID''][&object_id=''OBJECT_ID''][&uri=''URI''][&app=''APP''][&spawn]
   −
'''GET''' /context/''GUID''?cmd='''launch'''[&args=''ARG''][&activity_id=''ACTIVITY_ID''][&object_id=''OBJECT_ID''][&uri=''URI''][&color=''COLOR''][&no_spawn=''NO_SPAWN'']
+
Arguments that make sense only for Sugar activities:
    
* {{Code|ARG}}, command line argument to pass to launched activities, repeat {{Code|ARG}} for each argument;
 
* {{Code|ARG}}, command line argument to pass to launched activities, repeat {{Code|ARG}} for each argument;
 
* {{Code|ACTIVITY_ID}}, internal activity id which will be auto set if omitted;
 
* {{Code|ACTIVITY_ID}}, internal activity id which will be auto set if omitted;
 
* {{Code|OBJECT_ID}}, Journal object id to resume;
 
* {{Code|OBJECT_ID}}, Journal object id to resume;
* {{Code|URI}}, URL to resume if activity supports this functionality;
+
* {{Code|URI}}, URL to resume if activity supports this functionality.
* {{Code|COLOR}}, coma separated pair of Sugar colors to assign to activity object;
+
 
* {{Code|NO_SPAWN}}, if specified, HTTP connection will not be closed until exiting activity process.
+
Arguments that make sense only for books:
 +
 
 +
* {{Code|APP}}, specify application Context to open the book by; if omitted, the system will try to find most appropriate option, among all existing software Contexts.
 +
 
 +
Common arguments:
 +
 
 +
* {{Code|spawn}}, by default, the command will return streamed ''text/event-stream'' MIME type data to monitor the whole launching process until exiting the application; if the {{Code|spawn}} argument is specified, the command will exit immediately with [[#Notifications|asynchronous sending]] launching events.
 +
 
 +
== Experimental API ==
   −
{{Code|~}} mountpoint activities will be launched as-is from {{Code|~/Activities}} directory. For {{Code|/}} mountpoint, activities will be downloaded from the server and kept in cache directory [with further garbage collecting]. It is possible that during preparing for launching will be installed activity dependencies.
+
There is no guaranty that the following API will be stated as stable or frozen sometime.
   −
=== Access to the Journal ===
+
=== Access to Sugar Journal ===
   −
It is possible to get access to local Sugar Journal using special, ''journal'', resource. API to Journal is restricted only to read-only access:
+
It is possible to get access to local Sugar Journal using special, ''journal'', resource provided from [[#Client_API|client API]]. This kind of access might be useful when local applications cannot use DBus sugar-datastore API, e.g., [[wikipedia:Javascript|Javascript]] applications. API to Journal is restricted only to read-only access:
    
  '''GET''' /journal?offset=''INTEGER''&limit=''INTEGER''[&query=''STRING''][&order_by=<nowiki>[+|-]</nowiki>''PROP''][&''QUERY_PROP''=''VALUE''[&...]]
 
  '''GET''' /journal?offset=''INTEGER''&limit=''INTEGER''[&query=''STRING''][&order_by=<nowiki>[+|-]</nowiki>''PROP''][&''QUERY_PROP''=''VALUE''[&...]]
 
  '''GET''' /journal/''JOURNAL_ID''[?reply=''PROP''[,..]]
 
  '''GET''' /journal/''JOURNAL_ID''[?reply=''PROP''[,..]]
 
  '''GET''' /journal/''JOURNAL_ID''/''PROPERTY''
 
  '''GET''' /journal/''JOURNAL_ID''/''PROPERTY''
  −
This kind of access might be useful when local applications cannot use DBus sugar-datastore API, e.g., [[wikipedia:Javascript|Javascript]] applications.
      
== Usage ==
 
== Usage ==
   −
Being a [[Wikipedia:Restful|RESTful]], Sugar Network API can be used in any way how regular HTTP requests can be handled. But for command-line access, there is a handy tool, {{Code|sugar-network}}, that takes care about Sugar Network specific like lunching local API (if it is not already available) to get access to [[#Local_access|local data]].
+
Being HTTP based, Sugar Network API can be used in any manner regular HTTP requests can be handled. But for command-line access, there is a handy tool, {{Code|sugar-network}}, which takes care about Sugar Network specific like launching local API (if it is not already available) to get access to [[#Client_API|local proxy]].
   −
The sugar-network command-line format is, call {{Code|sugar-network --help}} for more detailed info:
+
The sugar-network command-line format is below. Call {{Code|sugar-network --help}} for more detailed info.
    
  sugar-network GET|POST|PUT|DELETE ''PATH'' ''ARG=VALUE'' [..]
 
  sugar-network GET|POST|PUT|DELETE ''PATH'' ''ARG=VALUE'' [..]
Line 276: Line 361:  
* {{Code|PATH}}, is an url path;
 
* {{Code|PATH}}, is an url path;
 
* {{Code|ARG<nowiki>=</nowiki>VALUE}}, request arguments as they being passed to in url.
 
* {{Code|ARG<nowiki>=</nowiki>VALUE}}, request arguments as they being passed to in url.
 +
 +
{{Code|POST}} and {{Code|PUT}} commands require data to pass, use the following command-line arguments:
 +
 +
* {{Code|-f FILE}} to specify the file to pass;
 +
* {{Code|-d DATA}} to specify string to pass;
 +
* {{Code|-j}} posted data should be encoded into JSON before posting.
    
== Getting involved ==
 
== Getting involved ==
    
{{:Sugar_Network/Feedback}}
 
{{:Sugar_Network/Feedback}}

Navigation menu