CS-4431: Newscoop REST API - part3.

test, publicationService, router factory, new resources in API.
CS-4431: Newscoop REST API - part3.

new resources: slideshows, topics.
CS-4431: Newscoop REST API - part3.

resources: user, sections, articles-list, fix for pagination links.
CS-4431: Newscoop REST API - part3.

tests, rest of resources.
CS-4431: Newscoop REST API - part3.

fixes in docs.
CS-4431: Newscoop REST API - part3.

remove articles option resource and tests for it, fix get single article resource without specified language when translations exists.
CS-4431: Newscoop REST API - part3.

First unit tests, and small fixes.
diff --git a/features/7_section.feature b/features/7_section.feature
index 9393d21..2df4572 100644
--- a/features/7_section.feature
+++ b/features/7_section.feature
@@ -1,13 +1,13 @@
 Feature: Sections
   I need to be able list and get sections

-  Scenario: Get single slideshow from gimme
+  Scenario: Get single section from gimme
     When I send a GET request to "/sections"
     Then the response code should be 200
     And response should have "items" with elements
     And response should have item with keys "number, title, articlesLink"

-  Scenario: Get single slideshow from gimme
+  Scenario: Get single section from gimme
     When I send a GET request to "/sections/20/en/articles"
     Then the response code should be 200
     And response should have keys "id, title, items"
diff --git a/gimme/app/config/config.yml b/gimme/app/config/config.yml
index 3de6054..0f31b3a 100644
--- a/gimme/app/config/config.yml
+++ b/gimme/app/config/config.yml
@@ -75,4 +75,8 @@ knp_paginator:
         distinct: true                 # ensure distinct results, useful when ORM queries are using GROUP BY statements
     template:
         pagination: KnpPaginatorBundle:Pagination:sliding.html.twig     # sliding pagination controls template
-        sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
\ No newline at end of file
+        sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
+
+newscoop_gimme:
+    allow_origin:
+        - "*"
\ No newline at end of file
diff --git a/gimme/src/Newscoop/GimmeBundle/DependencyInjection/NewscoopGimmeExtension.php b/gimme/src/Newscoop/GimmeBundle/DependencyInjection/NewscoopGimmeExtension.php
index 3417d7b..967695c 100644
--- a/gimme/src/Newscoop/GimmeBundle/DependencyInjection/NewscoopGimmeExtension.php
+++ b/gimme/src/Newscoop/GimmeBundle/DependencyInjection/NewscoopGimmeExtension.php
@@ -27,8 +27,12 @@ class NewscoopGimmeExtension extends Extension
     {
         $this->loadNewscoop($configs, $container);

-        $configuration = new Configuration();
-        $config = $this->processConfiguration($configuration, $configs);
+        $config = array();
+        foreach ($configs as $subConfig) {
+            $config = array_merge($config, $subConfig);
+        }
+
+        $container->setParameter('newscoop.gimme.allow_origin', $config['allow_origin']);

         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
         $loader->load('services.yml');
diff --git a/gimme/src/Newscoop/GimmeBundle/EventListener/AllowOriginListener.php b/gimme/src/Newscoop/GimmeBundle/EventListener/AllowOriginListener.php
new file mode 100644
index 0000000..e166b0f
--- /dev/null
+++ b/gimme/src/Newscoop/GimmeBundle/EventListener/AllowOriginListener.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @package Newscoop\Gimme
+ * @author Paweł Mikołajczuk <pawel.mikolajczuk@sourcefabric.org>
+ * @copyright 2012 Sourcefabric o.p.s.
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ */
+namespace Newscoop\GimmeBundle\EventListener;
+
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Newscoop\Gimme\Json;
+
+/**
+ * Add Access-Control-Allow-Origin header to response.
+ */
+class AllowOriginListener
+{
+    private $container;
+
+    public function __construct($container)
+    {
+        $this->container = $container;
+    }
+
+    public function onResponse(FilterResponseEvent $event)
+    {
+        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+            return;
+        }
+
+        $response = $event->getResponse();
+        $request = $event->getRequest();
+        $alowedHosts = $this->container->getParameter('newscoop.gimme.allow_origin');
+
+        if (count($alowedHosts) == 0) {
+            return false;
+        }
+
+        if (in_array('*', $alowedHosts)) {
+            $response->headers->set('Access-Control-Allow-Origin', '*');
+            $event->setResponse($response);
+        } else {
+            foreach ($alowedHosts as $host) {
+                if ($request->server->get('HTTP_ORIGIN') == $host) {
+                    $response->headers->set('Access-Control-Allow-Origin', $host);
+                    $event->setResponse($response);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/gimme/src/Newscoop/GimmeBundle/EventListener/FormatJsonResponseListener.php b/gimme/src/Newscoop/GimmeBundle/EventListener/FormatJsonResponseListener.php
index c3401f8..11f71bb 100644
--- a/gimme/src/Newscoop/GimmeBundle/EventListener/FormatJsonResponseListener.php
+++ b/gimme/src/Newscoop/GimmeBundle/EventListener/FormatJsonResponseListener.php
@@ -5,11 +5,11 @@
  * @copyright 2012 Sourcefabric o.p.s.
  * @license http://www.gnu.org/licenses/gpl-3.0.txt
  */
-
 namespace Newscoop\GimmeBundle\EventListener;

 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
 use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
 use Newscoop\Gimme\Json;

 /**
@@ -19,9 +19,15 @@ class FormatJsonResponseListener
 {
     public function onResponse(FilterResponseEvent $event)
     {
+        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+            return;
+        }
+
         $responseData = $event->getResponse()->getContent();

         $formatedJson = Json::indent($responseData);
-        $event->setResponse(new Response($formatedJson));
+        $newResponse = new Response($formatedJson);
+
+        $event->setResponse($newResponse);
     }
 }
\ No newline at end of file
diff --git a/gimme/src/Newscoop/GimmeBundle/Resources/config/services.yml b/gimme/src/Newscoop/GimmeBundle/Resources/config/services.yml
index b8a3088..32b3884 100644
--- a/gimme/src/Newscoop/GimmeBundle/Resources/config/services.yml
+++ b/gimme/src/Newscoop/GimmeBundle/Resources/config/services.yml
@@ -30,6 +30,11 @@ services:
         class: Newscoop\GimmeBundle\EventListener\FormatJsonResponseListener
         tags:
             - { name: kernel.event_listener, event: kernel.response, method: onResponse }
+    newscoop.gimme.listener.allow_origin:
+        class: Newscoop\GimmeBundle\EventListener\AllowOriginListener
+        arguments:  ["@service_container"]
+        tags:
+            - { name: kernel.event_listener, event: kernel.response, method: onResponse }
     newscoop.gimme.listener.override_method:
         class: Newscoop\GimmeBundle\EventListener\OverrideMethodListener
         tags:
diff --git a/gimme/src/Newscoop/GimmeBundle/Serializer/Article/FieldsHandler.php b/gimme/src/Newscoop/GimmeBundle/Serializer/Article/FieldsHandler.php
index 6b62714..bd744b0 100644
--- a/gimme/src/Newscoop/GimmeBundle/Serializer/Article/FieldsHandler.php
+++ b/gimme/src/Newscoop/GimmeBundle/Serializer/Article/FieldsHandler.php
@@ -26,13 +26,13 @@ class FieldsHandler implements SerializationHandlerInterface
         $GLOBALS['g_campsiteDir'] = realpath(__DIR__ . '/../../../../../../newscoop/');

         $articleData = new \ArticleData($data->getType(), $data->getNumber(), $data->getLanguageId());
-        if(count($articleData->getUserDefinedColumns()) == 0) {
+        if (count($articleData->getUserDefinedColumns()) == 0) {
             $data->setFields(null);
             return;
         }

         $fields = array();
-        foreach($articleData->getUserDefinedColumns() as $column) {
+        foreach ($articleData->getUserDefinedColumns() as $column) {
             $fields[$column->getPrintName()] = $articleData->getFieldValue($column->getPrintName());
         }

diff --git a/gimme/src/Newscoop/GimmeBundle/Serializer/Article/TranslationsHandler.php b/gimme/src/Newscoop/GimmeBundle/Serializer/Article/TranslationsHandler.php
index 5381582..0d33196 100644
--- a/gimme/src/Newscoop/GimmeBundle/Serializer/Article/TranslationsHandler.php
+++ b/gimme/src/Newscoop/GimmeBundle/Serializer/Article/TranslationsHandler.php
@@ -36,7 +36,7 @@ class TranslationsHandler implements SerializationHandlerInterface
             ->getResult();

         $articleTranslationsArray = array();
-        foreach($articleTranslations as $article) {
+        foreach ($articleTranslations as $article) {
             $articleTranslationsArray[$article->getLanguageCode()] = $this->router->generate('newscoop_gimme_articles_getarticle', array('number' => $article->getNumber(), 'language' => $article->getLanguageCode()), true);
         }
CS-4431: Newscoop REST API - part3.

Change /slideshows/{id}/items to slideshows/{id}, fix cs, add new AllowOrigin listener and configuration for it.
CS-4431: Newscoop REST API - part3.

Add some checks for bundle configuration
Merge branch 'gimme_on_top_symfony' into next