Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrive/Search Provinces failes #22

Open
kamyweb opened this issue Sep 17, 2024 · 1 comment
Open

Retrive/Search Provinces failes #22

kamyweb opened this issue Sep 17, 2024 · 1 comment

Comments

@kamyweb
Copy link

kamyweb commented Sep 17, 2024

webleit/revisoapi version 2.0.0 with illuminate/collections v8.83.27 on PHP 8.1.27

$reviso->provinces->get();

launch an exception:

PHP Fatal error:  Uncaught Error: Object of class stdClass could not be converted to string in /opt/project/vendor/illuminate/collections/Collection.php:508
Stack trace:
#0 /opt/project/vendor/webleit/revisoapi/src/Collection.php(17): Illuminate\Support\Collection->keyBy(Object(Closure))
#1 /opt/project/vendor/webleit/revisoapi/src/Endpoint/ListEndpoint.php(48): Weble\RevisoApi\Collection::create(Object(Weble\RevisoApi\Client), Object(stdClass), 'countryCode')
#2 /opt/project/vendor/webleit/revisoapi/src/Endpoint/Endpoint.php(43): Weble\RevisoApi\Endpoint\ListEndpoint->get()

Problem is inside illuminate/collections/Collection.php on function keyBy that try to cast the StdClass object as string.

public function keyBy($keyBy)
    {
        $keyBy = $this->valueRetriever($keyBy);

        $results = [];

        foreach ($this->items as $key => $item) {
            $resolvedKey = $keyBy($item, $key);

            if (is_object($resolvedKey)) {
                $resolvedKey = (string) $resolvedKey;
            }

            $results[$resolvedKey] = $item;
        }

        return new static($results);
    }

The json received from reviso is the following:

{
  "collection" : [ {
    "code" : "1",
    "name" : "Araba/Álava",
    "countryCode" : {
      "code" : "ES",
      "self" : "https://rest.reviso.com/country-codes/ES"
    },
    "provinceNumber" : 1,
    "self" : "https://rest.reviso.com/provinces/ES/1"
  }, ..... ],
  "metaData" : { },
  "pagination" : {
    "maxPageSizeAllowed" : 10000,
    "pageSize" : 20,
    "skipPages" : 0,
    "results" : 166,
    "resultsWithoutFilter" : 166,
    "firstPage" : "https://rest.reviso.com/provinces?skippages=0&pagesize=20",
    "lastPage" : "https://rest.reviso.com/provinces?skippages=8&pagesize=20",
    "nextPage" : "https://rest.reviso.com/provinces?skippages=1&pagesize=20"
  },
  "self" : "https://rest.reviso.com/provinces?skippages=0&pagesize=20"
}

The same if I try to filter/search a single province.
$reviso->provinces->where('code', '=', 'MI')->get();

How can I retrive information for this endpoint?

@Skullbock
Copy link
Contributor

Hi, that's an endpoint we don't yet use.
We deduce how to read from the api endpoints from the json resources schema reviso provides, and automatically deduce how they work

Provinces is an experimental endpoint according to reviso, and it does seem that it doesn't follow the rest of the endpoints.
If you can / want you can PR a fix. This consists in creating a dedicated Endpoint class that fixes the differences, usually either the route lists method or the resource key one.

You can check the ProjectsEndpoint class for an example

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

No branches or pull requests

2 participants