I've been trying to get this working all day so this is my last resort.
I am trying to call an api using guzzle, and this drupal_symfony_inject module: https://github.com/Capgemini/drupal_symfony_inject
I have the following config in hook_symfony_yaml_config_params():
// Assets client.
$assets_resources_file = $resources_folder . '/moderation.json';
$param_array['bubl_api_assets_service_client.service.description'] = $assets_resources_file;
$param_array['bubl_api_assets_client.class'] = 'BUBL\Clients\Assets\Client';
And this in my service definition:
{
"name": "BUBL moderation client",
"apiVersion": "v1",
"description": "BUBL moderation REST API client",
"operations": {
"getAllBubls": {
"httpMethod": "GET",
"uri": "/su/bubls",
"responseModel": "getJSONResponse",
"parameters": {
"before": {
"location": "uri",
"type": "integer",
"required": false
},
"after": {
"location": "uri",
"type": "integer",
"required": false
},
"max": {
"location": "uri",
"type": "integer",
"required": false
}
}
}
},
"models": {
"getJSONResponse": {
"type": "object",
"additionalProperties": {
"location": "json"
}
},
"getHTMLResponse": {
"type": "object",
"properties": {
"html": {
"location": "body",
"type": "string"
}
}
}
}
}
I have a client with the operations simply returning the response from guzzle, for example:
public function getAllBubls($before = NULL, $after = NULL) {
$response = $this->client->sendRequest('getAllBubls', ['before' => $before, 'after' => $after]);
return $response;
}
And when using it it works absolutely fine, like so:
global $_drupal_symfony_di_container;
/** @var BUBL\Clients\Moderation\Client $client */
$client = $_drupal_symfony_di_container->get('bubl_api_moderation_client');
if (is_callable(array($client, $service_name))) {
$response = $client->{$service_name}();
return $data_source = $response['bubls'];
}
Now, my problem is that the response is ran through json_decode before I get hold of it, and giving me an array, which is causing me all kinds of problems with the migrate module. I know that it is because of the responseModel set at
"responseModel": "getJSONResponse",
However, I can't find a way to simply request a raw response. I have tried (as was alluded to in the documentation), removing the responseModal altogether and adding in:
"responseType": "primitive",
and (separately I mean)
"responseModel": "getHTMLResponse",
But unfortunately I wouldn't receive any data back with either - just an empty array. I just can't seem to find a way to ignore all of the parsing and just get the response back in JSON? Is it possible? I've also tried to create another Model to use, but the types are either array or object, and the rest of the properties are really confusing to me in the documentation, so nothing I've tried is helping. It doesn't seem like it shouldn't go through a Model or Response Class at all, and that there is some way to bypass it perhaps ("primitive" would make sense to me, but alas not).
BTW I'm new to guzzle, and I know this seems a bit over engineered for this one call, but it is important for elsewhere, it's in place and I would like to get my head round it if it's possible to use it.
Thanks.