Esempio n. 1
0
 public function get_api()
 {
     $url = $this->app->config('prismic.url');
     $token = $this->app->config('prismic.token');
     if ($this->api == null) {
         $this->api = Api::get($url, $token);
     }
     return $this->api;
 }
Esempio n. 2
0
 protected function setUp()
 {
     $cache = new ApcCache();
     $cache->clear();
     $search = json_decode(file_get_contents(__DIR__ . '/../fixtures/search.json'));
     $this->document = Document::parse($search[0]);
     $this->micro_api = Api::get(self::$testRepository, null, null, $cache);
     $this->linkResolver = new FakeLinkResolver();
 }
Esempio n. 3
0
 public function testFileLinksWork()
 {
     $api = Api::get(self::$testRepository);
     $doc = $api->getByID("UssvNAEAAPvPpbr0");
     $linkExpected = 'https://prismic-io.s3.amazonaws.com/frontwebconf%2F48db2b33-5fd4-4cc5-809d-5ca76342beb4_become+a+sponsor+%28frontwebconf%29.pdf';
     $htmlExpected = '<a href="https://prismic-io.s3.amazonaws.com/frontwebconf%2F48db2b33-5fd4-4cc5-809d-5ca76342beb4_become+a+sponsor+%28frontwebconf%29.pdf">Become a sponsor (FrontWebConf).pdf</a>';
     $this->assertEquals($doc->get('footerlinks.link')->getUrl(), $linkExpected);
     $this->assertEquals($doc->get('footerlinks.link')->asText(), $linkExpected);
     $this->assertEquals($doc->get('footerlinks.link')->asHtml(), $htmlExpected);
 }
Esempio n. 4
0
 public function testFileLinksWork()
 {
     $api = Api::get(self::$testRepository);
     $masterRef = $api->master()->getRef();
     $results = $api->forms()->everything->query('[[:d = at(document.id, "UssvNAEAAPvPpbr0")]]')->ref($masterRef)->submit()->getResults();
     $linkExpected = 'https://prismic-io.s3.amazonaws.com/frontwebconf%2F48db2b33-5fd4-4cc5-809d-5ca76342beb4_become+a+sponsor+%28frontwebconf%29.pdf';
     $htmlExpected = '<a href="https://prismic-io.s3.amazonaws.com/frontwebconf%2F48db2b33-5fd4-4cc5-809d-5ca76342beb4_become+a+sponsor+%28frontwebconf%29.pdf">Become a sponsor (FrontWebConf).pdf</a>';
     $this->assertEquals($results[0]->get('footerlinks.link')->getUrl(), $linkExpected);
     $this->assertEquals($results[0]->get('footerlinks.link')->asText(), $linkExpected);
     $this->assertEquals($results[0]->get('footerlinks.link')->asHtml(), $htmlExpected);
 }
Esempio n. 5
0
 public function testValidApiCall()
 {
     $response = $this->getMockBuilder('Ivory\\HttpAdapter\\Message\\Response')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('getBody')->will($this->returnValue(file_get_contents(__DIR__ . '/../fixtures/data.json')));
     $httpAdapter = $this->getMock('Ivory\\HttpAdapter\\HttpAdapterInterface');
     $httpAdapter->expects($this->once())->method('get')->will($this->returnValue($response));
     $api = Api::get('don\'t care about this value', null, $httpAdapter);
     $this->assertInstanceOf('Prismic\\Api', $api);
     $this->assertEquals($httpAdapter, $api->getHttpAdapter());
     return $api;
 }
 /**
  * Return Prismic Api Client
  * @param  ServiceLocatorInterface $serviceLocator
  * @return Api
  * @throws \RuntimeException
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (!isset($config['prismic']['api'])) {
         throw new \RuntimeException('No configuration has been provided in order to retrieve a Prismic API Client');
     }
     $config = $config['prismic'];
     $httpClient = $cache = null;
     $url = $config['api'];
     $token = $configToken = isset($config['token']) ? $config['token'] : null;
     /**
      * Check the Session for a token and prefer that if it exists.
      * We cannot retrieve the Prismic Container from the service manager
      * because it depends on the Context, so we'd have a circular dependency
      */
     $session = new PrismicContainer('Prismic');
     if ($session->hasAccessToken()) {
         $token = $session->getAccessToken();
     }
     /**
      * See if a cache service name has been provided and wrap it in the facade
      * if required
      */
     if (!empty($config['cache'])) {
         $storage = $serviceLocator->get($config['cache']);
         if (!$storage instanceof CacheInterface) {
             $cache = new Facade($storage);
         } else {
             $cache = $storage;
         }
     }
     if (!empty($config['httpClient'])) {
         $httpClient = $serviceLocator->get($config['httpClient']);
     }
     /**
      * @see \Prismic\Api::get($apiUrl, $accesssToken, \Guzzle\Http\Client $client, \Prismic\Cache\CacheInterface $cache)
      */
     /**
      * Wrap api initialisation in a try/catch in case the temporary token we got from the session
      * has expired
      */
     try {
         $api = Api::get($url, $token, $httpClient, $cache);
     } catch (HttpAdapterException $e) {
         $api = Api::get($url, $configToken, $httpClient, $cache);
     }
     return $api;
 }
Esempio n. 7
0
 public function testCache()
 {
     // startgist:56e7aa7b1be64e09f76f:prismic-cache.php
     // You can pass any class implementing the CacheInterface to the Api creation
     // http://prismicio.github.io/php-kit/classes/Prismic.Cache.CacheInterface.html
     $fileCache = new ApcCache();
     $api = Api::get("https://lesbonneschoses.cdn.prismic.io/api", null, null, $fileCache);
     // endgist
     $this->assertNotNull($api);
 }
Esempio n. 8
0
 /**
  * {@inheritDoc}
  */
 public function login(CredentialsInterface $credentials = null, $workspaceName = null)
 {
     $this->credentials = $credentials;
     $this->workspaceName = $workspaceName ?: 'default';
     if (!$this->checkLoginOnServer) {
         return $this->workspaceName;
     }
     $apiEndpoint = $this->getApiEndpointUri($this->workspaceName);
     $accessToken = $this->accessToken;
     if ($credentials instanceof SimpleCredentials && null !== $credentials->getUserID()) {
         // TODO oauth login
         $clientId = $credentials->getUserID();
         $clientSecret = $credentials->getPassword();
         //$accessToken = ..
     }
     try {
         // TODO inject a factory to create Prismic\Api instances
         $this->api = Api::get($apiEndpoint, $accessToken);
     } catch (RequestException $e) {
         throw new NoSuchWorkspaceException("Requested workspace: '{$this->workspaceName}'", null, $e);
     } catch (\RuntimeException $e) {
         throw new RepositoryException("Could not connect to endpoint: '{$apiEndpoint}'", null, $e);
     }
     $this->ref = $this->api->master()->getRef();
     $this->bookmarksByName = (array) $this->api->bookmarks();
     $this->bookmarksByUuid = array_flip($this->bookmarksByName);
     $this->loggedIn = true;
     return $this->workspaceName;
 }
Esempio n. 9
0
<?php

include_once __DIR__ . '/../vendor/autoload.php';
use Prismic\Api;
$options = array('prismic.ref' => false, 'prismic.api' => "https://lesbonneschoses.prismic.io/api", 'prismic.token' => "Your permanent token");
// retrieve the main information from the api, form and repositories ...
$api = Api::get($options['prismic.api'], $options['prismic.token']);
// retrieve the main repository reference
$ref = $options['prismic.ref'] ?: $api->master()->getRef();
$searchForm = $api->forms()->everything->ref($ref);
// create a new search form with the search query
$queryForm = $searchForm->query('[[:d = at(document.type, "product")]]');
// retrieve the results from the API
$results = $queryForm->submit();
Esempio n. 10
0
 public function testGetLink()
 {
     $api = Api::get('http://micro.prismic.io/api');
     $masterRef = $api->master()->getRef();
     $documents = $api->forms()->everything->ref($masterRef)->query('[[:d = at(document.id, "UvLDWgEAABoHHn1R")]]')->submit()->getResults();
     $this->assertEquals($documents[0]->getLink('cta.link')->getId(), "U0w8OwEAACoAQEvB");
 }
Esempio n. 11
0
 /**
  * Prepare API for calls
  * @return \Prismic\Api
  */
 private function prepareApi()
 {
     return Api::get($this->model->endpoint, $this->model->token);
 }
 /**
  * @param string $customAccessToken
  * @return Api
  */
 public function getApiHome($customAccessToken = null)
 {
     return Api::get($this->apiEndpoint, $customAccessToken ? $customAccessToken : $this->accessToken, $this->client, $this->cache);
 }
 public static function apiHome($maybeAccessToken = null)
 {
     return Api::get(self::config('prismic.api'), $maybeAccessToken);
 }