worldia / textmaster-api

Simple PHP client for the Textmaster API
1 stars 5 forks source link

Error with Textmaster\Client #69

Closed jmleroux closed 8 years ago

jmleroux commented 8 years ago

Hello,

I want to use textmaster-api to build a connector between Textmaster and Akeneo.

I just started the project and made a basic command to test the API calls:

class ApiTestCommand extends ContainerAwareCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('pim:textmaster:api-test')
            ->setDescription('Test API calls');
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $client = $this->getContainer()->get('worldia.textmaster.api.client');
        $locales = $client->locales()->all();

        dump($locales);
    }
}

and declared my services in YAML:

    worldia.textmaster.api.httpclient:
        class: Textmaster\HttpClient\HttpClient
        arguments:
            - '%textmaster.api_key%'
            - '%textmaster.api_secret%'

    worldia.textmaster.api.client:
        class: Textmaster\Client
        arguments:
            - '@worldia.textmaster.api.httpclient'
            - '@event_dispatcher'

But the command does not work and i get this error:

[Textmaster\Exception\ErrorException]                                                                                                                                
  a:1:{s:4:"base";a:1:{i:0;s:127:"The URL you're requesting doesn't exist within the api. Make sure your URL begins with "http://api.textmaster.com/version_name"";}}  

I traced the error and it comes from here https://github.com/worldia/textmaster-api/blob/master/lib/Textmaster/HttpClient/HttpClient.php#L192 This method return this string : /v1/clients/public/locales and it seems that we expected http://api.textmaster.com/v1/clients/public/locales

Did i miss something in the configuration or in the instanciation ?

Best regards, JM

cdaguerre commented 8 years ago

@jmleroux I guess there's a mistake here. There shouldn't be a trailing /clients. Could you either:

    worldia.textmaster.api.httpclient:
        class: Textmaster\HttpClient\HttpClient
        arguments:
            - '%textmaster.api_key%'
            - '%textmaster.api_secret%'
            - [ base_uri: 'http://api.textmaster.com/%s' ]

Or use http://api.sandbox.textmaster.com/%s whilst testing ;)

jmleroux commented 8 years ago

Hi @cdaguerre ,

firstly, thank you for the quick answer.

The /clients could effectively be superfluous, but it's not the error source for sure. The error is raised because $this->client->getConfig('base_uri')->getPath() returns the path, without host and without scheme.

cdaguerre commented 8 years ago

The base_uri isn't added here, it's misleading. Actually it's added by the client when the request is sent, ie. here. Have you tested my suggestion?

jmleroux commented 8 years ago

It works with your last tag. Thanks !