Пример #1
0
 /**
  * Create Bpi Client
  *
  * @param string $endpoint URL
  * @param string $agency_id Agency ID
  * @param string $api_key App key
  * @param string $secret_key
  */
 public function __construct($endpoint, $agency_id, $api_key, $secret_key)
 {
     $this->client = new \Goutte\Client();
     $this->authorization = new \Bpi\Sdk\Authorization($agency_id, $api_key, $secret_key);
     $this->current_document = $this->endpoint = $this->createDocument();
     $this->endpoint->loadEndpoint($endpoint);
 }
Пример #2
0
 protected function createMockDocument($fixture)
 {
     $client = $this->getMock('Goutte\\Client');
     $client->expects($this->at(0))->method('request')->will($this->returnValue(new Crawler(file_get_contents(__DIR__ . '/Fixtures/' . $fixture . '.bpi'))));
     $client->expects($this->any())->method('getResponse')->will($this->returnValue(new Response()));
     $doc = new Document($client, new Authorization(mt_rand(), mt_rand(), mt_rand()));
     $doc->loadEndpoint('http://example.com');
     return $doc;
 }
Пример #3
0
 public function testAuthorization()
 {
     $agency_id = mt_rand();
     $public_key = mt_rand();
     $secret_key = mt_rand();
     $authorization = new Authorization($agency_id, $public_key, $secret_key);
     $client = $this->getMock('Goutte\\Client');
     $client->expects($this->at(0))->method('request')->with($this->equalTo('GET'), $this->equalTo('http://example.com'), $this->equalTo(array()), $this->equalTo(array()), $this->equalTo(array('HTTP_Auth' => $authorization->toHTTPHeader(), 'HTTP_Content_Type' => 'application/vnd.bpi.api+xml')))->will($this->returnValue(new Crawler(file_get_contents(__DIR__ . '/Fixtures/Node.bpi'))));
     $client->expects($this->once())->method('getResponse')->will($this->returnValue(new Response()));
     $doc = new Document($client, $authorization);
     $doc->loadEndpoint('http://example.com');
 }
Пример #4
0
 public function testPropertiesOfFirstItem()
 {
     $self = $this;
     $this->item->walkProperties(function ($e) use($self) {
         $self->assertTrue(in_array($e['name'], $self->valid_fields), $e['name'] . ' is not valid property name');
         $self->assertTrue(isset($e['@value']));
     });
     $properties = $this->item->propertiesToArray();
     $this->assertEquals('Winter', $properties['yearwheel']);
     $this->assertEquals('All', $properties['audience']);
     $this->assertEquals('Event', $properties['category']);
     $this->assertEquals('article', $properties['type']);
     $this->assertEquals('<p>alpha_body unicode(❶)</p><p>Originally published by George Bush, Aarhus Kommunes Biblioteker.</p>', $properties['body'], 'Body or copyleft doesn\'t match');
 }
Пример #5
0
 /**
  *
  * @return integer
  */
 function count()
 {
     return $this->document->count();
 }
Пример #6
0
 /**
  * Get facets.
  *
  * @return Facets
  */
 public function getFacets()
 {
     return $this->document->getFacets();
 }
Пример #7
0
 /**
  * Perform HTTP PUT for given URI
  *
  * @param \Bpi\Sdk\Document $document
  */
 public function put(Document $document)
 {
     $document->request('PUT', $this->crawler->attr('href'));
 }
Пример #8
0
 /**
  *
  * @param \Bpi\Sdk\Document $document
  */
 public function post(Document $document)
 {
     $document->request('POST', $this->crawler->attr('href'), $this->render());
 }