<commit_before>h1. acts_as_sdata

Ruby implementation of SData (Sage Data) protocol. Rails plugin which enables SData syndication and publishing.

h2. Demo

Let's consider we want to expose the list of US presidents in SData way (this is exactly what is done in "presidents":http://github.com/DanielVartanov/acts_as_sdata-examples/tree/master/presidents/ application in "acts_as_sdata-examples":http://github.com/DanielVartanov/acts_as_sdata-examples repository).

From client side it will look like this:

h3. Instance path

<code>http://localhost:3000/presidents/!Wilson</code>

<pre><?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:attributes="http://sdata.sage.com/schemes/attributes">
  <title><NAME></title>
  <summary><NAME> (1856-1924)</summary>
  <attributes:born_at>1856</attributes:born_at>
  <attributes:id>28</attributes:id>
  <attributes:first_name>Woodrow</attributes:first_name>
  <attributes:last_name>Wilson</attributes:last_name>
  <attributes:party>Democrat</attributes:party>
  <attributes:updated_at>Sat Jan 09 11:43:11 UTC 2010</attributes:updated_at>
  <attributes:died_at>1924</attributes:died_at>
  <attributes:order>28</attributes:order>
  <attributes:term_started_at>1913</attributes:term_started_at>
  <attributes:created_at>Sat Jan 09 11:43:11 UTC 2010</attributes:created_at>
  <attributes:country>USA</attributes:country>
  <attributes:term_ended_at>1921</attributes:term_ended_at>
</entry></pre>

h3. Collection path

<code>http://localhost:3000/presidents</code>

<pre><?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
  <title>List of US presidents</title>
  <updated>2009-11-17T10:55:28+06:00</updated>
  <link href="http://example.com/presidents"/>
  <author>
    <name>Sage</name>
  </author>
  <entry>
    <title>Washington, George</title>
    <summary>Washington, George (1732-1799)</summary>
  </entry>
  <entry>
    <title><NAME></title>
    <summary><NAME> (1735-1826)</summary>
  </entry>
.....
</pre>

h3. Predicate

<code>http://localhost:3000/presidents(born_at gt 1900)</code>

<pre><?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
  <title>List of US presidents</title>
  <updated>2009-11-17T10:58:15+06:00</updated>
  <link href="http://example.com/presidents"/>
  <author>
    <name>Sage</name>
  </author>
  <entry>
    <title><NAME></title>
    <summary><NAME> (1917-1963)</summary>
  </entry>
  <entry>
    <title><NAME></title>
    <summary><NAME> (1908-1973)</summary>
  </entry>
.....
</pre>

h3. Publishing

SData protocol supports data publishing (as Atom Publishing Protocol does)

Example:

<pre>require 'atom/pub'

collection = Atom::Pub::Collection.new(:href => 'http://localhost:3000/presidents')

entry = Atom::Entry.load_entry <<XML
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:attributes="http://sdata.sage.com/schemes/attributes">
  <attributes:born_at>1961</attributes:born_at>
  <attributes:first_name>Barack</attributes:first_name>
  <attributes:last_name>Obama</attributes:last_name>
  <attributes:party>Democrat</attributes:party>
  <attributes:died_at/>
  <attributes:order>44</attributes:order>
  <attributes:term_started_at>2009</attributes:term_started_at>
  <attributes:country>USA</attributes:country>
  <attributes:term_ended_at/>
</entry>
XML

collection.publish entry</pre>

The response will be:

<pre>
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:attributes="http://sdata.sage.com/schemes/attributes">
  <attributes:id>46</attributes:id>
  <attributes:created_at>Sat Jan 09 14:29:57 UTC 2010</attributes:created_at>
  <attributes:first_name>Barack</attributes:first_name>
  ...
</entry></pre>
_with status 201 (Created)_

h2. How to install

h3. Install Usher

_(Usher is an alternative router)_

It is better to refer to "User's page":http://github.com/joshbuddy/usher/, but usually installation of Usher plugin is just one commad:

<code>$ script/plugin install git://github.com/joshbuddy/usher.git</code>

h3. Install acts_as_sdata

<code>$ script/plugin install git://github.com/DanielVartanov/acts_as_sdata.git</code>

h2. How to use

In order to make application act as SData you should write the following.

h3. In router

<code>map.sdata_resource :presidents</code><commit_msg>Typo fixed<commit_after>h1. acts_as_sdata

Ruby implementation of SData (Sage Data) protocol. Rails plugin which enables SData syndication and publishing.

h2. Demo

Let's consider we want to expose the list of US presidents in SData way (this is exactly what is done in "presidents":http://github.com/DanielVartanov/acts_as_sdata-examples/tree/master/presidents/ application in "acts_as_sdata-examples":http://github.com/DanielVartanov/acts_as_sdata-examples repository).

From client side it will look like this:

h3. Instance path

<code>http://localhost:3000/presidents/!Wilson</code>

<pre><?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:attributes="http://sdata.sage.com/schemes/attributes">
  <title><NAME></title>
  <summary><NAME> (1856-1924)</summary>
  <attributes:born_at>1856</attributes:born_at>
  <attributes:id>28</attributes:id>
  <attributes:first_name>Woodrow</attributes:first_name>
  <attributes:last_name>Wilson</attributes:last_name>
  <attributes:party>Democrat</attributes:party>
  <attributes:updated_at>Sat Jan 09 11:43:11 UTC 2010</attributes:updated_at>
  <attributes:died_at>1924</attributes:died_at>
  <attributes:order>28</attributes:order>
  <attributes:term_started_at>1913</attributes:term_started_at>
  <attributes:created_at>Sat Jan 09 11:43:11 UTC 2010</attributes:created_at>
  <attributes:country>USA</attributes:country>
  <attributes:term_ended_at>1921</attributes:term_ended_at>
</entry></pre>

h3. Collection path

<code>http://localhost:3000/presidents</code>

<pre><?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
  <title>List of US presidents</title>
  <updated>2009-11-17T10:55:28+06:00</updated>
  <link href="http://example.com/presidents"/>
  <author>
    <name>Sage</name>
  </author>
  <entry>
    <title>Washington, George</title>
    <summary>Washington, George (1732-1799)</summary>
  </entry>
  <entry>
    <title><NAME></title>
    <summary><NAME> (1735-1826)</summary>
  </entry>
.....
</pre>

h3. Predicate

<code>http://localhost:3000/presidents(born_at gt 1900)</code>

<pre><?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
  <title>List of US presidents</title>
  <updated>2009-11-17T10:58:15+06:00</updated>
  <link href="http://example.com/presidents"/>
  <author>
    <name>Sage</name>
  </author>
  <entry>
    <title><NAME></title>
    <summary><NAME> (1917-1963)</summary>
  </entry>
  <entry>
    <title><NAME></title>
    <summary><NAME> (1908-1973)</summary>
  </entry>
.....
</pre>

h3. Publishing

SData protocol supports data publishing (as Atom Publishing Protocol does)

Example:

<pre>require 'atom/pub'

collection = Atom::Pub::Collection.new(:href => 'http://localhost:3000/presidents')

entry = Atom::Entry.load_entry <<XML
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:attributes="http://sdata.sage.com/schemes/attributes">
  <attributes:born_at>1961</attributes:born_at>
  <attributes:first_name>Barack</attributes:first_name>
  <attributes:last_name>Obama</attributes:last_name>
  <attributes:party>Democrat</attributes:party>
  <attributes:died_at/>
  <attributes:order>44</attributes:order>
  <attributes:term_started_at>2009</attributes:term_started_at>
  <attributes:country>USA</attributes:country>
  <attributes:term_ended_at/>
</entry>
XML

collection.publish entry</pre>

The response will be:

<pre>
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:attributes="http://sdata.sage.com/schemes/attributes">
  <attributes:id>46</attributes:id>
  <attributes:created_at>Sat Jan 09 14:29:57 UTC 2010</attributes:created_at>
  <attributes:first_name>Barack</attributes:first_name>
  ...
</entry></pre>
_with status 201 (Created)_

h2. How to install

h3. Install Usher

_(Usher is an alternative router)_

It is better to refer to "Usher's page":http://github.com/joshbuddy/usher/, but usually installation of Usher plugin is just one commad:

<code>$ script/plugin install git://github.com/joshbuddy/usher.git</code>

h3. Install acts_as_sdata

<code>$ script/plugin install git://github.com/DanielVartanov/acts_as_sdata.git</code>

h2. How to use

In order to make application act as SData you should write the following.

h3. In router

<code>map.sdata_resource :presidents</code>
{'fraction_non_alphanumeric': 0.1641323792486583, 'fraction_numerical': 0.059033989266547404, 'mean_word_length': 5.53874269005848, 'pattern_counts': {'":': 6, '<': 285, '<?xml version=': 10, '>': 283, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3164583', 'n_tokens_mistral': 3547, 'n_tokens_neox': 3162, 'n_words': 562}