Skip to content

[CS] Refactor #8

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

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/Builder/SocialPostBuilder.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Builder;

use Carbon\Carbon;
use SocialData\Connector\LinkedIn\Client\LinkedInClient;
use SocialDataBundle\Dto\BuildConfig;
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
use SocialData\Connector\LinkedIn\Model\FeedConfiguration;
use SocialDataBundle\Connector\SocialPostBuilderInterface;
use SocialDataBundle\Dto\BuildConfig;
use SocialDataBundle\Dto\FetchData;
use SocialDataBundle\Dto\FilterData;
use SocialDataBundle\Dto\TransformData;
Expand Down Expand Up @@ -192,7 +203,6 @@ protected function findThumbnail(mixed $media): ?string
$thumbnail = null;

foreach ($media as $shareMedia) {

if (!isset($shareMedia['thumbnails']) || !is_array($shareMedia['thumbnails'])) {
continue;
}
Expand All @@ -210,6 +220,7 @@ protected function findThumbnail(mixed $media): ?string

if (isset($index[0], $validThumbs[$index[0]]['url'])) {
$thumbnail = $validThumbs[$index[0]]['url'];

break;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Client/LinkedInClient.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Client;

use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
Expand Down
45 changes: 25 additions & 20 deletions src/Client/LinkedInSDK.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Client;

/**
* Adapted from https://github.com/ashwinks/PHP-LinkedIn-SDK
* Adapted from https://github.com/ashwinks/PHP-LinkedIn-SDK.
*/
class LinkedInSDK
{
protected const API_BASE = 'https://api.linkedin.com/v2';
protected const OAUTH_BASE = 'https://www.linkedin.com/oauth/v2';

public const R_AD_CAMPAIGNS = 'r_ad_campaigns'; // View advertising campaigns you manage
public const R_ADS = 'r_ads'; // Retrieve your advertising accounts
public const R_ADS_LEADGEN_AUTOMATION = 'r_ads_leadgen_automation'; // Access your Lead Gen Forms and retrieve leads
Expand All @@ -26,7 +36,6 @@ class LinkedInSDK
public const RW_ORGANIZATION = 'rw_organization'; // Manage your organization's page and post updates
public const W_MEMBER_SOCIAL = 'w_member_social'; // Post, comment and like posts on your behalf
public const W_ORGANIZATION_SOCIAL = 'w_organization_social'; // Post, comment and like posts on your organization's behalf

protected const HTTP_METHOD_GET = 'GET';
protected const HTTP_METHOD_POST = 'POST';
protected const HTTP_METHOD_PUT = 'PUT';
Expand Down Expand Up @@ -67,7 +76,7 @@ public function __construct(array $config)
}

/**
* Get the login url, pass scope to request specific permissions
* Get the login url, pass scope to request specific permissions.
*
* @param array $scope - an array of requested permissions (can use scope constants defined in this class)
* @param string|null $state - a unique identifier for this user, if none is passed, one is generated via uniqid
Expand All @@ -89,7 +98,7 @@ public function getLoginUrl(array $scope = [], ?string $state = null): string
}

/**
* Exchange the authorization code for access token
* Exchange the authorization code for access token.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -127,15 +136,15 @@ public function getAccessToken(?string $authorization_code = null): string|bool
}

/**
* This timestamp is "expires in". In other words, the token will expire in now() + expires_in
* This timestamp is "expires in". In other words, the token will expire in now() + expires_in.
*/
public function getAccessTokenExpiration(): ?string
{
return $this->accessTokenExpires;
}

/**
* Set the access token manually
* Set the access token manually.
*
* @throws \InvalidArgumentException
*/
Expand All @@ -152,7 +161,7 @@ public function setAccessToken(string $token): self
}

/**
* Set the state manually. State is a unique identifier for the user
* Set the state manually. State is a unique identifier for the user.
*
* @throws \InvalidArgumentException
*/
Expand All @@ -169,31 +178,31 @@ public function setState(string $state): self
}

/**
* Get state
* Get state.
*/
public function getState(): ?string
{
return $this->state;
}

/**
* GET an authenticated API endpoind w/ payload
* GET an authenticated API endpoind w/ payload.
*/
public function get(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
{
return $this->fetch($endpoint, $payload, self::HTTP_METHOD_GET, $headers, $curlOptions);
}

/**
* GET an authenticated API endpoind w/ payload
* GET an authenticated API endpoind w/ payload.
*/
public function getEncoded(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
{
return $this->fetch($endpoint, $payload, self::HTTP_METHOD_GET, $headers, $curlOptions, true);
}

/**
* POST to an authenticated API endpoint w/ payload
* POST to an authenticated API endpoint w/ payload.
*/
public function post(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
{
Expand All @@ -203,7 +212,7 @@ public function post(string $endpoint, array $payload = [], array $headers = [],
}

/**
* PUT to an authenticated API endpoint w/ payload
* PUT to an authenticated API endpoint w/ payload.
*/
public function put(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
{
Expand All @@ -230,15 +239,15 @@ public function fetchOAuth(string $endpoint, array $payload = [], string $method
}

/**
* Get debug info from the CURL request
* Get debug info from the CURL request.
*/
public function getDebugInfo(): ?array
{
return $this->debugInfo;
}

/**
* Make a CURL request
* Make a CURL request.
*
* @throws \JsonException
*/
Expand All @@ -250,7 +259,6 @@ protected function _makeRequest(
array $curlOptions = [],
bool $useEncodedQuery = false
): array {

$ch = $this->_getCurlHandle();

$options = [
Expand All @@ -264,14 +272,12 @@ protected function _makeRequest(

if (!empty($payload)) {
if (in_array($options[CURLOPT_CUSTOMREQUEST], [self::HTTP_METHOD_POST, self::HTTP_METHOD_PUT], true)) {

$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = http_build_query($payload);

$headers[] = 'Content-Length: ' . strlen($options[CURLOPT_POSTFIELDS]);

$options[CURLOPT_HTTPHEADER] = $headers;

} else {
$query = http_build_query($payload);
$options[CURLOPT_URL] = sprintf('%s&%s', $options[CURLOPT_URL], ($useEncodedQuery ? urldecode($query) : $query));
Expand Down Expand Up @@ -314,5 +320,4 @@ public function __destruct()
curl_close($this->curlHandle);
}
}

}
}
14 changes: 12 additions & 2 deletions src/Controller/Admin/LinkedInController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Controller\Admin;

use Carbon\Carbon;
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
use SocialData\Connector\LinkedIn\Client\LinkedInClient;
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
use SocialDataBundle\Connector\ConnectorDefinitionInterface;
use SocialDataBundle\Controller\Admin\Traits\ConnectResponseTrait;
use SocialDataBundle\Service\ConnectorServiceInterface;
Expand Down Expand Up @@ -95,7 +106,6 @@ public function debugTokenAction(Request $request): JsonResponse
}

try {

$payload = [
'client_id' => $connectorEngineConfig->getClientId(),
'client_secret' => $connectorEngineConfig->getClientSecret(),
Expand Down
13 changes: 12 additions & 1 deletion src/Definition/ConnectorDefinition.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Definition;

use SocialData\Connector\LinkedIn\Client\LinkedInSDK;
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
use SocialData\Connector\LinkedIn\Model\FeedConfiguration;
use SocialDataBundle\Connector\ConnectorEngineConfigurationInterface;
use SocialDataBundle\Connector\ConnectorDefinitionInterface;
use SocialDataBundle\Connector\ConnectorEngineConfigurationInterface;
use SocialDataBundle\Connector\SocialPostBuilderInterface;
use SocialDataBundle\Model\ConnectorEngineInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand Down
11 changes: 11 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down
15 changes: 13 additions & 2 deletions src/DependencyInjection/SocialDataLinkedInConnectorExtension.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;

class SocialDataLinkedInConnectorExtension extends Extension
{
Expand Down
11 changes: 11 additions & 0 deletions src/EventListener/Admin/AssetListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\EventListener\Admin;

use Pimcore\Event\BundleManager\PathsEvent;
Expand Down
11 changes: 11 additions & 0 deletions src/Form/Admin/Type/LinkedInEngineType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Form\Admin\Type;

use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
Expand Down
13 changes: 12 additions & 1 deletion src/Form/Admin/Type/LinkedInFeedType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace SocialData\Connector\LinkedIn\Form\Admin\Type;

use SocialData\Connector\LinkedIn\Model\FeedConfiguration;
Expand All @@ -21,7 +32,7 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'csrf_protection' => false,
'data_class' => FeedConfiguration::class
'data_class' => FeedConfiguration::class
]);
}
}
Loading
Loading