/** * Execute the given http request. * * @param Request $request * @param callable|null $processor * * @throws RateLimitedReached * * @return Response The response. */ public function execute(Request $request, $processor = null) { $response = $this->auth->execute($request); if ($response->rateLimited()) { throw new RateLimitedReached($response); } if (is_callable($processor)) { $response = $this->processResponse($response, $processor); } return $response; }
public function testGetAuthenticationUrl() { $auth = new Authentication($this->getHttpClient(), 'client-id', 'client-secret'); $authUrl = $auth->getAuthenticationUrl('http://localhost', array(Scope::READ_PUBLIC), 'random'); $excepted = 'https://api.pinterest.com/oauth/?response_type=code&redirect_uri=http%3A%2F%2Flocalhost&client_id=client-id&scope=read_public&state=random'; $this->assertSame($excepted, $authUrl); $this->setExpectedException('Pinterest\\Api\\Exceptions\\InvalidScopeException'); $auth->getAuthenticationUrl('http://localhost', array('not-valid'), 'random'); $this->setExpectedException('Pinterest\\Api\\Exceptions\\TooManyScopesGiven'); $auth->getAuthenticationUrl('http://localhost', array(Scope::READ_PUBLIC, Scope::READ_PUBLIC, Scope::READ_PUBLIC, Scope::READ_PUBLIC, Scope::READ_PUBLIC), 'random'); $this->setExpectedException('Pinterest\\Api\\Exceptions\\AtLeastOneScopeNeeded'); $auth->getAuthenticationUrl('http://localhost', array(), 'random'); }
public function setUp() { $cacheDir = sprintf('%s/responses', __DIR__); if (!is_dir($cacheDir)) { throw new RuntimeException('The cache directory does not exist or is not a directory'); } $client = new BuzzClient(); $mocked = new MockClient($client, $cacheDir); $auth = Authentication::withAccessToken($mocked, null, null, getenv('ACCESS_TOKEN')); $this->api = new Api($auth); $this->boardId = getenv('BOARD_ID'); }