2017 © Pedro Peláez
 

symfony-bundle recombeebundle

A bundle to interact with symfony and recombee API

image

obtao/recombeebundle

A bundle to interact with symfony and recombee API

  • Monday, July 16, 2018
  • by obtao
  • Repository
  • 2 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*1)

$ composer require "obtao/recombeebundle:dev-master"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*2)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles, in the app/AppKernel.php file of your project:, (*3)

This bundle rely on JMS serializer as dependency, so if you are not using it yet, you have to add it too., (*4)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new \Obtao\RecombeeBundle\ObtaoRecombeeBundle(),
            new \JMS\SerializerBundle\JMSSerializerBundle() // only if you are not using it yet
        );

        // ...
    }

    // ...
}

Step 3: Config the Bundle

// app/config.yml

obtao_recombee:
    recombee_database_name: "your-database-name"
    recombee_secret_token: "your-api-key"

Step 4: Usage

Below example of usage in symfony controller to create a user and related properties., (*5)

Bundle provide 2 custom model (for user and item), feel free to modify according your needs., (*6)

BatchBuilder helper will extract all properties of such item to guess the best type for recombee API (need to implements HasSkuInterface), (*7)

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use \Obtao\RecombeeBundle as ObtaoRecombee;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction()
    {
        // service to reach API
        $apiCaller = $this->get('obtao.recombee.api.caller');
        // Helper to build batch  of properties
        $batchBuilder = $this->get('obtao.recombee.batch.builder');

        // reset database first (be careful !) : expected response "ok"
        $reset = var_dump($apiCaller->sendToApi(new ObtaoRecombee\Model\ResetDatase()));

        // create a new User
        $user = new ObtaoRecombee\Model\User();
        $user->setSku(12345);
        $user->setNickName('JohnDoe');
        $user->setOriginCountry('FR');

        // use batch helper to build all properties for user above
        /** @var Batch $batch */
        $batch = $batchBuilder->buildBatchOfProperties($user, ObtaoRecombee\Model\AddUserProperty::class);

        // send batch of properties to API : expected response batch of "ok"
        var_dump($apiCaller->sendToApi($batch));

        // create user : expected response "ok"
        var_dump($apiCaller->sendToApi(new ObtaoRecombee\Model\SetUserValues($user)));

        die('that\'s all folks');
    }
}

The Versions

16/07 2018

dev-feat/camelCase

dev-feat/camelCase

A bundle to interact with symfony and recombee API

  Sources   Download

MIT

The Requires

 

27/06 2018

dev-master

9999999-dev

A bundle to interact with symfony and recombee API

  Sources   Download

MIT

The Requires