public function testGetBasicToken() { if (file_exists(__DIR__ . '/testuser.php')) { $testUser = (require_once __DIR__ . '/testuser.php'); } else { throw new Exception('No testUser'); } $bitly = new BitlyClient($testUser['client_id'], $testUser['client_secret']); $accessToken = $bitly->getAccessTokenViaBasicAuth($testUser['username'], $testUser['password']); $this->assertEquals(strlen($accessToken), 40); }
public static function bitlyGet($url, array $params) { $client = BitlyClient::getSecureClient(); $request = $client->get("/v3/{$url}"); $query = $request->getQuery(); foreach ($params as $key => $value) { $query->set($key, $value); } $response = $request->send(); $jsonString = (string) $response->getBody(); $body = json_decode($jsonString); if ($body && property_exists($body, 'status_txt')) { self::throwBitlyError($body->status_txt); } if ($body && property_exists($body, 'data')) { return $body->data; } else { throw new BitlyRequestException('Invalid request.'); } }