@@ 17-42 (lines=26) @@ | ||
14 | use Psr\Http\Message\RequestInterface; |
|
15 | use Psr\Http\Message\ResponseInterface; |
|
16 | ||
17 | final class AddThis implements Service |
|
18 | { |
|
19 | public function getCode(): string |
|
20 | { |
|
21 | return 'addthis'; |
|
22 | } |
|
23 | ||
24 | public function createRequest(RequestFactoryInterface $factory, string $url): RequestInterface |
|
25 | { |
|
26 | return $factory->createRequest( |
|
27 | 'GET', |
|
28 | 'http://api-public.addthis.com/url/shares.json?url='.urlencode($url) |
|
29 | ); |
|
30 | } |
|
31 | ||
32 | public function count(ResponseInterface $response): int |
|
33 | { |
|
34 | $json = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); |
|
35 | ||
36 | if (!\array_key_exists('shares', $json)) { |
|
37 | throw new FetchException('The "shares" attributes could not be found', $response->getBody()->getContents()); |
|
38 | } |
|
39 | ||
40 | return (int) $json['shares']; |
|
41 | } |
|
42 | } |
|
43 |
@@ 17-42 (lines=26) @@ | ||
14 | use Psr\Http\Message\RequestInterface; |
|
15 | use Psr\Http\Message\ResponseInterface; |
|
16 | ||
17 | final class Buffer implements Service |
|
18 | { |
|
19 | public function getCode(): string |
|
20 | { |
|
21 | return 'buffer'; |
|
22 | } |
|
23 | ||
24 | public function createRequest(RequestFactoryInterface $factory, string $url): RequestInterface |
|
25 | { |
|
26 | return $factory->createRequest( |
|
27 | 'GET', |
|
28 | 'https://api.bufferapp.com/1/links/shares.json?url='.urlencode($url) |
|
29 | ); |
|
30 | } |
|
31 | ||
32 | public function count(ResponseInterface $response): int |
|
33 | { |
|
34 | $json = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); |
|
35 | ||
36 | if (!\array_key_exists('shares', $json)) { |
|
37 | throw new FetchException('The "shares" attributes could not be found', $response->getBody()->getContents()); |
|
38 | } |
|
39 | ||
40 | return (int) $json['shares']; |
|
41 | } |
|
42 | } |
|
43 |
@@ 17-42 (lines=26) @@ | ||
14 | use Psr\Http\Message\RequestInterface; |
|
15 | use Psr\Http\Message\ResponseInterface; |
|
16 | ||
17 | final class Xing implements Service |
|
18 | { |
|
19 | public function getCode(): string |
|
20 | { |
|
21 | return 'xing'; |
|
22 | } |
|
23 | ||
24 | public function createRequest(RequestFactoryInterface $factory, string $url): RequestInterface |
|
25 | { |
|
26 | return $factory->createRequest( |
|
27 | 'POST', |
|
28 | 'https://www.xing-share.com/spi/shares/statistics?url='.urlencode($url) |
|
29 | ); |
|
30 | } |
|
31 | ||
32 | public function count(ResponseInterface $response): int |
|
33 | { |
|
34 | $json = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); |
|
35 | ||
36 | if (!\array_key_exists('share_counter', $json)) { |
|
37 | throw new FetchException('The "share_counter" attributes could not be found', $response->getBody()->getContents()); |
|
38 | } |
|
39 | ||
40 | return (int) $json['share_counter']; |
|
41 | } |
|
42 | } |
|
43 |