public function testFilterStream()
 {
     $client = $this->getMockBuilder('CvoTechnologies\\Twitter\\Network\\Http\\StreamClient')->setMethods(['post'])->getMock();
     $responseGenerator = function () {
         (yield new Response(['HTTP/1.1 200 Ok'], json_encode(['id' => 1, 'text' => 'Status 1'])));
         (yield new Response(['HTTP/1.1 200 Ok'], json_encode(['id' => 2, 'text' => 'Status 2'])));
         (yield new Response(['HTTP/1.1 200 Ok'], json_encode(['id' => 3, 'text' => 'Status 3'])));
     };
     $client->expects($this->once())->method('post')->with('/1.1/statuses/filter.json', ['track' => 'twitter', 'follow' => '1', 'locations' => '123,123'])->willReturn($responseGenerator());
     $this->webservice->driver()->streamClient($client);
     $query = new Query($this->webservice, new Endpoint());
     $query->read();
     $query->where(['word' => 'twitter', 'user' => 1, 'location' => '123,123']);
     $query->applyOptions(['streamEndpoint' => 'filter']);
     $resultSet = $this->webservice->execute($query);
     $this->assertInstanceOf('Cake\\Datasource\\ResultSetDecorator', $resultSet);
     $this->assertEquals('Status 1', $resultSet->first()->text);
     foreach ($resultSet as $resource) {
         $this->assertInstanceOf('Muffin\\Webservice\\Model\\Resource', $resource);
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 protected function _executeReadQuery(Query $query, array $options = [])
 {
     $vars = [];
     foreach ($query->where() as $k => $v) {
         if ($k == 'actual' || $k == 'unplanned') {
             $vars[$k] = is_string($v) ? $v : ($v ? 'true' : 'false');
         } else {
             $vars[$k] = $v;
         }
     }
     $response = $this->driver()->client()->get('/ns-api-storingen', $vars);
     if (!$response->isOk()) {
         return false;
     }
     $xmlData = $response->xml;
     $disruptions = [];
     $keys = ['Ongepland', 'Gepland'];
     foreach ($keys as $key) {
         foreach ($xmlData->{$key}->Storing as $disruption) {
             $disruptions[] = ['id' => !empty($disruption->id) ? (string) $disruption->id : null, 'planned' => $key == 'Gepland', 'route' => !empty($disruption->Traject) ? (string) $disruption->Traject : null, 'reason' => !empty($disruption->Oorzaak) ? (string) $disruption->Oorzaak : null, 'advice' => !empty($disruption->Advies) ? (string) $disruption->Advies : null, 'message' => !empty($disruption->Bericht) ? (string) $disruption->Bericht : null, 'delay' => !empty($disruption->Vertraging) ? (string) $disruption->Vertraging : null, 'period' => !empty($disruption->Periode) ? (string) $disruption->Periode : null];
         }
     }
     return new ResultSet($this->_transformResults($disruptions, $options['resourceClass']));
 }
 /**
  * {@inheritDoc}
  */
 protected function _executeDeleteQuery(Query $query, array $options = [])
 {
     if (!isset($query->where()['id']) || is_array($query->where()['id'])) {
         return false;
     }
     $url = $this->_baseUrl() . '/destroy/' . $query->where()['id'] . '.json';
     /* @var Response $response */
     $response = $this->driver()->client()->post($url);
     if (!$response->isOk()) {
         throw new Exception($response->json['errors'][0]['message']);
     }
     return true;
 }
 public function testDelete()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function (RequestInterface $request) {
         $this->assertEquals('POST', $request->getMethod());
         $this->assertEquals('/1.1/statuses/destroy/2.json', $request->getUri()->getPath());
         return new \GuzzleHttp\Psr7\Response(200, [], json_encode(['id' => 2, 'text' => 'Status 2?']));
     }));
     $query = new Query($this->webservice, new Endpoint(['endpoint' => 'statuses', 'connection' => $this->webservice->driver()]));
     $query->action(Query::ACTION_DELETE);
     $query->where(['id' => 2]);
     $this->assertTrue($this->webservice->execute($query));
 }
Ejemplo n.º 5
0
 /**
  * Logs a query to the specified logger
  *
  * @param \Muffin\Webservice\Query $query The query to log
  * @param \Psr\Log\LoggerInterface $logger The logger instance to use
  *
  * @return void
  */
 protected function _logQuery(Query $query, LoggerInterface $logger)
 {
     if (!$this->driver()->logQueries()) {
         return;
     }
     $logger->debug($query->endpoint(), ['params' => $query->where()]);
 }
 /**
  * Find the retweets of the specified tweet.
  *
  * @param \Muffin\Webservice\Query $query The query to modify.
  * @param array $options The options to pass, including the tweet to get the retweets from.
  * @return \Muffin\Webservice\Query The modified query.
  */
 public function findRetweets(Query $query, array $options)
 {
     return $query->where(['retweeted_status_id' => $options['status']]);
 }
 public function testCustomFieldSearch()
 {
     $this->webservice->driver()->client($this->_clientMock('get', '/issues.json', ['cf_1' => true], ['issues' => []]));
     $query = new Query($this->webservice, new Endpoint(['connection' => new Connection(['name' => 'redmine', 'driver' => 'CvoTechnologies\\Redmine\\Webservice\\Driver\\Redmine']), 'endpoint' => 'issues', 'schema' => new Schema('issues', ['custom_bool_field' => ['type' => 'boolean', 'custom_field_id' => 1, 'custom_field_filterable' => true]])]));
     $query->read();
     $query->where(['custom_bool_field' => true]);
     $resultSet = $this->webservice->execute($query);
     $this->assertEquals(0, $resultSet->total());
     $this->assertInstanceOf('Muffin\\Webservice\\ResultSet', $resultSet);
 }