Skip to content

Commit

Permalink
Merge pull request #3681 from nextcloud/fix/socialavatars/fix-http-cl…
Browse files Browse the repository at this point in the history
…ient-usage

fix(socialavatars): Fix HTTP client usage
  • Loading branch information
ChristophWurst authored Nov 30, 2023
2 parents 8a6cd9d + 687ab6b commit 8e016e9
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 23 deletions.
5 changes: 3 additions & 2 deletions lib/Service/Social/DiasporaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

namespace OCA\Contacts\Service\Social;

use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;

class DiasporaProvider implements ISocialProvider {
/** @var IClientService */
/** @var IClient */
private $httpClient;

/** @var bool */
Expand All @@ -36,7 +37,7 @@ class DiasporaProvider implements ISocialProvider {
public $name = 'diaspora';

public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
$this->httpClient = $httpClient->newClient();
$this->looping = false;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Service/Social/FacebookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@

namespace OCA\Contacts\Service\Social;

use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;

class FacebookProvider implements ISocialProvider {
/** @var IClientService */
/** @var IClient */
private $httpClient;

/** @var string */
public $name = 'facebook';

public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
$this->httpClient = $httpClient->newClient();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/Service/Social/InstagramProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
use GuzzleHttp\RequestOptions;
use OC\AppFramework\Http\Request;
use OCA\Contacts\AppInfo\Application;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use Psr\Log\LoggerInterface;

class InstagramProvider implements ISocialProvider {
/** @var IClientService */
/** @var IClient */
private $httpClient;

/** @var LoggerInterface */
Expand All @@ -42,7 +43,7 @@ class InstagramProvider implements ISocialProvider {

public function __construct(IClientService $httpClient,
LoggerInterface $logger) {
$this->httpClient = $httpClient->NewClient();
$this->httpClient = $httpClient->newClient();
$this->logger = $logger;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Service/Social/MastodonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@

namespace OCA\Contacts\Service\Social;

use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;

class MastodonProvider implements ISocialProvider {
/** @var IClientService */
/** @var IClient */
private $httpClient;

/** @var string */
public $name = 'mastodon';

public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
$this->httpClient = $httpClient->newClient();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/Service/Social/TelegramProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\RequestOptions;
use OCA\Contacts\AppInfo\Application;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use Psr\Log\LoggerInterface;

class TelegramProvider implements ISocialProvider {
/** @var IClientService */
/** @var IClient */
private $httpClient;

/** @var LoggerInterface */
Expand All @@ -41,7 +42,7 @@ class TelegramProvider implements ISocialProvider {

public function __construct(IClientService $httpClient,
LoggerInterface $logger) {
$this->httpClient = $httpClient->NewClient();
$this->httpClient = $httpClient->newClient();
$this->logger = $logger;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Service/Social/XingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@

namespace OCA\Contacts\Service\Social;

use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;

class XingProvider implements ISocialProvider {
/** @var IClientService */
/** @var IClient */
private $httpClient;

/** @var string */
public $name = 'xing';

public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
$this->httpClient = $httpClient->newClient();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SocialApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function updateContact(string $addressbookId, string $contactId, ?string

foreach ($urls as $url) {
try {
$httpResult = $this->clientService->NewClient()->get($url);
$httpResult = $this->clientService->newClient()->get($url);
$socialdata = $httpResult->getBody();
$imageType = $httpResult->getHeader('content-type');
if (isset($socialdata) && isset($imageType)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/Social/DiasporaProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp(): void {
$this->client = $this->createMock(IClient::class);

$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($this->client);

$this->provider = new DiasporaProvider(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/Social/FacebookProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp(): void {
$this->client = $this->createMock(IClient::class);

$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($this->client);

$this->provider = new FacebookProvider(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/Social/InstagramProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp(): void {
$this->logger = $this->createMock(LoggerInterface::class);

$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($this->client);

$this->provider = new InstagramProvider(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/Social/MastodonProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp(): void {
$this->client = $this->createMock(IClient::class);

$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($this->client);

$this->provider = new MastodonProvider(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/Social/TelegramProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp(): void {
$this->client = $this->createMock(IClient::class);

$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($this->client);

$this->provider = new TelegramProvider(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/Social/XingProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp(): void {
$this->client = $this->createMock(IClient::class);

$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($this->client);

$this->provider = new XingProvider(
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Service/SocialApiServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testUpdateContactWithoutNetwork($addressbooks, $providers, $body
->method('get')
->willReturn($response);
$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($client);
$this->imageResizer
->expects($body ? $this->once() : $this->never())
Expand Down Expand Up @@ -237,7 +237,7 @@ public function testUpdateContactWithNetworkVersion3() {
->method('get')
->willReturn($response);
$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($client);
$this->imageResizer
->expects($this->once())
Expand Down Expand Up @@ -310,7 +310,7 @@ public function testUpdateContactWithNetworkVersion4() {
->method('get')
->willReturn($response);
$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($client);
$this->imageResizer
->expects($this->once())
Expand Down Expand Up @@ -438,7 +438,7 @@ protected function setupAddressbooks() {
->method('get')
->willReturn($validResponse);
$this->clientService
->method('NewClient')
->method('newClient')
->willReturn($client);
$this->imageResizer
->method('resizeImage')
Expand Down

0 comments on commit 8e016e9

Please sign in to comment.