• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

webeweb / pexels-library / 8264931651

13 Mar 2024 12:50PM UTC coverage: 97.216%. Remained the same
8264931651

push

github

webeweb
Update CHANGELOG

419 of 431 relevant lines covered (97.22%)

34.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
/src/Provider/ApiProvider.php
1
<?php
2

3
/*
4
 * This file is part of the pexels-library package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace WBW\Library\Pexels\Provider;
13

14
use GuzzleHttp\Exception\GuzzleException;
15
use InvalidArgumentException;
16
use WBW\Library\Pexels\Api\PaginateResponseInterface;
17
use WBW\Library\Pexels\Request\AbstractRequest;
18
use WBW\Library\Pexels\Response\AbstractResponse;
19
use WBW\Library\Pexels\Response\PhotosResponse;
20
use WBW\Library\Pexels\Response\VideosResponse;
21
use WBW\Library\Provider\Exception\ApiException;
22

23
/**
24
 * API provider.
25
 *
26
 * @author webeweb <https://github.com/webeweb>
27
 * @package WBW\Library\Pexels\Provider
28
 */
29
class ApiProvider extends AbstractProvider {
30

31
    /**
32
     * Populate a response.
33
     *
34
     * @param AbstractResponse $response The response.
35
     * @return AbstractResponse Returns the response.
36
     */
37
    protected function populateResponse(AbstractResponse $response): AbstractResponse {
38

39
        $response->setLimit($this->getLimit());
8✔
40
        $response->setRemaining($this->getRemaining());
8✔
41
        $response->setReset($this->getReset());
8✔
42

43
        return $response;
8✔
44
    }
45

46
    /**
47
     * Request a next page.
48
     *
49
     * @param PaginateResponseInterface $response The response.
50
     * @return PhotosResponse|VideosResponse Returns the response.
51
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
52
     * @throws GuzzleException Throws a Guzzle exception if an error occurs.
53
     * @throws ApiException Throws an API exception if an error occurs.
54
     */
55
    public function requestNextPage(PaginateResponseInterface $response): AbstractResponse {
56

57
        $rawResponse = $this->callApiWithResponse($response);
×
58

59
        /** @var PhotosResponse|VideosResponse */
60
        return $this->populateResponse($response->deserializeResponse($rawResponse));
×
61
    }
62

63
    /**
64
     * Request a previous page.
65
     *
66
     * @param PaginateResponseInterface $response The response.
67
     * @return PhotosResponse|VideosResponse Returns the response.
68
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
69
     * @throws GuzzleException Throws a Guzzle exception if an error occurs.
70
     * @throws ApiException Throws an API exception if an error occurs.
71
     */
72
    public function requestPrevPage(PaginateResponseInterface $response): AbstractResponse {
73

74
        $rawResponse = $this->callApiWithResponse($response, false);
×
75

76
        /** @var PhotosResponse|VideosResponse */
77
        return $this->populateResponse($response->deserializeResponse($rawResponse));
×
78
    }
79

80
    /**
81
     * Send a request.
82
     *
83
     * @param AbstractRequest $request The request.
84
     * @return AbstractResponse Returns the response.
85
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
86
     * @throws GuzzleException Throws a Guzzle exception if an error occurs.
87
     * @throws ApiException Throws an API exception if an error occurs.
88
     */
89
    public function sendRequest(AbstractRequest $request): AbstractResponse {
90

91
        $queryData   = $request->serializeRequest();
112✔
92
        $rawResponse = $this->callApiWithRequest($request, $queryData);
112✔
93

94
        return $this->populateResponse($request->deserializeResponse($rawResponse));
×
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc