Skip to content

Commit

Permalink
Authentication Integration Step 3.
Browse files Browse the repository at this point in the history
Add new API consumer class to call the client service and fetch the data.
  • Loading branch information
mohit-rocks committed May 15, 2020
1 parent 9f9816e commit 61713e2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Config/config.php
Expand Up @@ -37,6 +37,25 @@
'mautic.integrations.helper',
],
],
'helloworld.connection.client' => [
'class' => \MauticPlugin\HelloWorldBundle\Connection\Client::class,
'arguments' => [
'mautic.integrations.auth_provider.basic_auth',
'mautic.helper.cache_storage',
'router',
'monolog.logger.mautic',
'helloworld.integration.config',
],
],
'helloworld.connection.client.consumer' => [
'class' => \MauticPlugin\HelloWorldBundle\Connection\ApiConsumer::class,
'arguments' => [
'mautic.helper.cache_storage',
'monolog.logger.mautic',
'helloworld.connection.client',
'helloworld.integration.config',
],
],
]
],
];
49 changes: 49 additions & 0 deletions Connection/ApiConsumer.php
@@ -0,0 +1,49 @@
<?php

namespace MauticPlugin\HelloWorldBundle\Connection;

use Mautic\CoreBundle\Helper\CacheStorageHelper;
use MauticPlugin\HelloWorldBundle\Integration\Config;
use Monolog\Logger;

class ApiConsumer
{
/**
* @var \Mautic\CoreBundle\Helper\CacheStorageHelper
*/
private $cacheProvider;
/**
* @var \Monolog\Logger
*/
private $logger;
/**
* @var \MauticPlugin\HelloWorldBundle\Connection\Client
*/
private $client;
/**
* @var \MauticPlugin\HelloWorldBundle\Integration\Config
*/
private $config;

public function __construct(
CacheStorageHelper $cacheProvider,
Logger $logger,
Client $client,
Config $config
) {
$this->cacheProvider = $cacheProvider;
$this->logger = $logger;
$this->client = $client;
$this->config = $config;
}

/**
* Fetch the data from API endpoint.
*/
public function getSubscribers()
{
$users = $this->client->get('v2/api/fetch-dummy-users');
// Polish and manipulate the data.
return $users;
}
}

0 comments on commit 61713e2

Please sign in to comment.