Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

Params not interpolating? #55

Open
HelloGrayson opened this issue Jan 18, 2013 · 2 comments
Open

Params not interpolating? #55

HelloGrayson opened this issue Jan 18, 2013 · 2 comments

Comments

@HelloGrayson
Copy link
Contributor

Trying to rig up an api call like so:

http://www.wanikani.com/api/user/bb4ab76bd4a5cacf78bd2415a1b447a8/user-information

But my command appears to be calling the following, triggering a 404:

http://www.wanikani.com/api/user//user-information

Here is my config:

guzzle:
  services:
    WaniKaniService:
      class: App\AppBundle\Services\WaniKaniService
      params:
        base_url: http://www.wanikani.com/

The command:

<?php

namespace App\AppBundle\Services;

use Orkestra\Bundle\GuzzleBundle\Services\Service as AbstractService;
use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Command;
use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Doc;
use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Param;
use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Headers;
use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Type;

class WaniKaniService extends AbstractService
{
    /**
     * @Command(name="user_information", method="GET", uri="/api/user/{api_key}/user-information")
     * @Doc("Get User Information")
     * @Param(name="api_key", type="string", required="true")
     */
    public function getUserInformationCommand()
    {
        //Here you can manipulate the response, you can bind it to an object for example
        return $this->getResponse();
    }
}

And some client code:

<?php

namespace App\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
{
    /**
     * @Route("/")
     * @Template()
     */
    public function indexAction()
    {
        $guzzle = $this->get('guzzle');

        $user = $guzzle->getService('WaniKaniService')->execute('user_information', array(
            'api_key' => 'bb4ab76bd4a5cacf78bd2415a1b447a8'
        ));

        var_dump($user);
        exit;
    }
}

Where I finally get the following output:

array(1) { ["error"]=> array(2) { ["code"]=> string(14) "user_not_found" ["message"]=> string(20) "User does not exist." } }

Am I doing something wrong? What is the best way to debug this?

Thanks much

@zachbadgett
Copy link
Contributor

It looks like you have everything set up correctly in your code, I would make sure to have the latest version of both Guzzle and this bundle. Guzzle 3 inserts params differently from previous versions; you would use double brackets {{api_key}} for guzzle versions less than 3.

I will need to update my version requirement in composer! Let me know if you found the solution to this! Thanks

@alexgalkin
Copy link

Please advise if there is a workaround for this. Have the same issue - cannot pass any parameters.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants