canihavesomecoffee / theTVDbAPI

PHP implementation for the 2nd version of the TheTVDb API
ISC License
11 stars 8 forks source link

Issue with search #24

Closed DariusIII closed 3 years ago

DariusIII commented 3 years ago

I am trying to implement V4 API but i have hit a wall with simple search. When i do:

$client = new \CanIHaveSomeCoffee\TheTVDbAPI\TheTVDbAPI();

$token = $client->authentication()->login(config('tvdb.api_key'), config('tvdb.user_pin'));

$client->setToken($token);

Auth is fine and token is set.

Next thing is:

$series = $client->search()->search('Arrow');

Issue begins here, as i receive the following error:

Symfony\Component\Serializer\Exception\NotNormalizableValueException

  The type of the key "ara" must be "int" ("string" given).

  at vendor/symfony/serializer/Normalizer/ArrayDenormalizer.php:54
    50|
    51|         $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null;
    52|         foreach ($data as $key => $value) {
    53|             if (null !== $builtinType && !('is_'.$builtinType)($key)) {
  > 54|                 throw new NotNormalizableValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, get_debug_type($key)));
    55|             }
    56|
    57|             $data[$key] = $this->denormalizer->denormalize($value, $type, $format, $context);
    58|         }

Testing on TheTVDB swagger works properly.

canihavesomecoffee commented 3 years ago

That it works fine on theTVDb is no surprise, it's not parsed into a data class over there :)

Looks like some field in one of the models isn't set correctly, or the returned information structure deviates from the models they gave.

I'm looking into it and will let you know when I fixed it.

canihavesomecoffee commented 3 years ago

Found it...

Models says:

translations: [TranslationSimple]

TranslationsSimple { language: string }

So, the normalizer expects JSON like this:

      "translations": [{"language": "Translation in Dutch"}, {"language": "Translation in French"}]

What we get back though is:

      "translations": {
        "ara": "السهم",
        "bul": "Стрелата",
        "ces": "Arrow",
        "dan": "Arrow",
        "deu": "Arrow",
        "ell": "Arrow",
        "eng": "Arrow",
        "est": "Vibukütt",
        "fin": "Arrow",
        "fra": "Arrow",
        "heb": "החץ",
        "hun": "A zöld íjász",
        "ita": "Arrow",
        "kor": "애로우",
        "lit": "Arrow",
        "nld": "Arrow",
        "pol": "Arrow",
        "por": "Arrow",
        "pt": "Arqueiro",
        "rus": "Стрела",
        "spa": "Arrow",
        "swe": "Arrow",
        "tur": "Ok",
        "zho": "綠箭俠"
      }

I'll find a better method for those translations then...

canihavesomecoffee commented 3 years ago

2.0.8 should fix your issue :tada:

DariusIII commented 3 years ago

Issue has been fixed. Thank you!

canihavesomecoffee commented 3 years ago

If you notice other things, don't hesitate to open new issues :)