Skip to content

How do I filter the result of the parser? #42

@troccoli

Description

@troccoli

I'm writing an API that calls an external API. The external API returns data as XML, and my API needs to return data as JSON. I have the following code that works fine

$client = new Client(['base_uri' => $this->baseUri]);
$response = $client->request(
     'GET',
     'GetCAPMan',
     $this->buildQuery([
         'Database'                 => 'CAR',
         'JustCurrentManufacturers' => 'true',
         'BodyStyleFilter'          => '',
    ])
);

    if ($response->getStatusCode() != 200) {
        return false;
    }

    return $this->parser->xml($response->getBody());

I then include this data into my JSON response like the following

return response()->json(['status' => 'success', 'brands' => $brands]);

This, as I said, works fine.

Now, however, I want to filter the XML response from the external API as I'm not interested in all the fields that it returns. I thought I could use the mask() method but I don't know how.

Since the methods are not fluent I thought I set the mask before parsing the payload, thinking that would apply the mask

$this->parser->mask(['Returned_DataSet' => '*']);

return $this->parser->xml($response->getBody());

But that doesn't work.

This is one reason I want to use this package, the ability to filter the output, but how to do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions