1
0
Fork 0
forked from lino/radar-wp

Upgrading to 1.0.0-beta1 version of the API PHP implementation.

This commit is contained in:
ekes 2017-06-09 13:30:20 +01:00
parent 4424f09f06
commit 4ed51243b5
56 changed files with 1330 additions and 824 deletions

View file

@ -44,7 +44,7 @@ class Connect {
$this->apiUrl = $configuration['api_url'];
}
else {
$this->apiUrl = 'https://new-radar.squat.net/api/1.0/';
$this->apiUrl = 'https://radar.squat.net/api/1.0/';
}
$this->debug = !empty($configuration['debug']);
}

View file

@ -16,8 +16,17 @@ require('radar_client.php');
// Shared radar connect client.
$client = radar_client();
// Basic cache for output.
$cache = radar_cache();
// If you want to empty the cache completely
//$cache->flushAll();
// If you want to remove one item like the stored HTML for evets.php
$cache->delete('events.php');
// Add a prefered language for requests. If none is set 'und' is used and
// content is returned in its original language, first language posted..
$client->setLanguage('de');
// Check to see if there is a copy in the cache.
if ($cache->contains('events.php') && $page = $cache->fetch('events.php')) {
@ -25,15 +34,14 @@ if ($cache->contains('events.php') && $page = $cache->fetch('events.php')) {
print $page['html'];
// If it's more than an hour old, get a new one.
if ($page['created'] + 60 * 60 < time()) {
$events = radar_events_retrieve($client);
$html = radar_events_format($client, $events);
$html = radar_events_page_html($client);
$cache->delete('events.php');
}
}
else {
// Generate the page and output it.
$events = radar_events_retrieve($client);
$html = radar_events_format($client, $events, true);
$html = radar_events_page_html($client);
print $html;
}
if (!empty($html)) {
@ -42,6 +50,17 @@ if (!empty($html)) {
$cache->save('events.php', $page);
}
/**
* Make HTML page.
*/
function radar_events_page_html($client) {
$request = radar_prepare_events_request($client);
$response = $client->retrieveResponse($request);
$events = $client->parseResponse($response);
$metadata = $client->parseResponseMeta($response);
return radar_events_format($client, $events, $metadata);
}
/**
* Set a filter and retrieve events matching the filter.
*
@ -51,14 +70,19 @@ if (!empty($html)) {
* @return Radar\Connect\Event[]
* Array of radar connect events.
*/
function radar_events_retrieve(\Radar\Connect\Connect $client) {
function radar_prepare_events_request(\Radar\Connect\Connect $client) {
$filter = new \Radar\Connect\Filter;
$filter->addCity('Berlin');
// Alternatives:-
//$filter->addCity('Amsterdam');
//$filter->addDate(new DateTime('tomorrow'));
//$filter->addDay();
//$filter->addCategory('music');
//Some filters don't have explicit methods to set them so for tags...
//$filter->add('tag', 'Punk');
// See docs/classes/Radar.Connect.Filter.html for full list of methods.
// You can also see all the filter values and their counts in the metadata
// returned. See the examples at the top of radar_events_format().
// Get the request.
// arguments:
@ -66,6 +90,9 @@ function radar_events_retrieve(\Radar\Connect\Connect $client) {
// $fields - array of field names to collect, empty for default
// $limit - maximum number of events to return.
$request = $client->prepareEventsRequest($filter, array(), 50);
return $request;
// Execute request.
return $client->retrieve($request);
}
@ -77,17 +104,43 @@ function radar_events_retrieve(\Radar\Connect\Connect $client) {
* The connect client.
* @param \Radar\Connect\Event[] $events
* Array of Event entities, for example response to events request.
* @param bool $output
* If HTML output should also be sent to stdout.
* @param array $metadata
* Array of counts and facets.
*
* @return string
* The HTML output.
*/
function radar_events_format(\Radar\Connect\Connect $client, array $events, $output = FALSE) {
function radar_events_format(\Radar\Connect\Connect $client, array $events, array $metadata) {
ob_start();
ob_implicit_flush(TRUE);
$html = '';
// Metadata includes the result count.
print "<p>There are {$metadata['count']} results for the query</p>\n";
// Retrieve some facets. Summaries of filters you can use
// in further narrowed queries, and their result counts.
print '<h1>Forthcoming days</h1><ul>';
foreach ($metadata['facets']['date'] as $facet) {
print '<li>' . date('Y-m-d', $facet['formatted']) . " has {$facet['count']} events</li>\n";
}
print "</ul>\n";
// For other factets it's even more convenient. The 'filter' value is also the value you set to filter the query.
print "<h1>Categories</h1><ul>\n";
foreach ($metadata['facets']['category'] as $facet) {
print "<li>{$facet['formatted']} has {$facet['count']} events you could add a filter for them with the \$filter->addCategory('{$facet['filter']}');</li>\n";
}
print "<ul>\n";
// There's no direct method to set the tag filter. They can all be set using the key that is in this array - here tag.
// So in the example above instead of $filter->addCategory you could have equally $filter->add('category', $facet['filter']);
print "<h1>Tags</h1><ul>\n";
foreach ($metadata['facets']['tag'] as $facet) {
print "<li>{$facet['formatted']} has {$facet['count']} events you could add a filter for them with the \$filter->add('tag', '{$facet['filter']}');</li>\n";
}
print "<ul>\n";
foreach ($events as $event) {
// Title and date.
print '<h1>' . $event->getTitle() . '</h1>';
@ -98,20 +151,24 @@ function radar_events_format(\Radar\Connect\Connect $client, array $events, $out
// The groups are references. If we want to get details about
// them we actually load the group itself as well.
$groups = $client->retrieveEntityMultiple($event->getGroups());
$groups = $event->getGroups();
$groups = $client->retrieveEntityMultiple($groups);
foreach ($groups as $group) {
print '<p><strong>' . $group->getTitle() . '</strong></p>';
print '<p>' . var_dump($group->getLink(), true) . ' ' . var_dump($group->getLinkRaw(), true) . '</strong></p>';
}
// Just as with the groups the locations are just the references.
// So we load them here.
$locations = $client->retrieveEntityMultiple($event->getLocations());
$locations = $event->getLocations();
$locations = $client->retrieveEntityMultiple($locations);
foreach ($locations as $location) {
print '<p>' . $location->getAddress() . '</p>';
}
// Yep and the categories, and topics.
$categories = $client->retrieveEntityMultiple($event->getCategories());
$categories = $event->getCategories();
$categories = $client->retrieveEntityMultiple($categories);
$category_names = array();
foreach ($categories as $category) {
$category_names[] = $category->getTitle();
@ -120,7 +177,8 @@ function radar_events_format(\Radar\Connect\Connect $client, array $events, $out
print '<p>Categories: ' . implode(', ', $category_names);
}
$topics = $client->retrieveEntityMultiple($event->getTopics());
$topics = $event->getTopics();
$topics = $client->retrieveEntityMultiple($topics);
$topic_names = array();
foreach ($topics as $topic) {
$topic_names[] = $topic->getTitle();
@ -131,12 +189,7 @@ function radar_events_format(\Radar\Connect\Connect $client, array $events, $out
// Outputs the HTML if requested.
$html .= ob_get_contents();
if ($output) {
ob_flush();
}
else {
ob_clean();
}
ob_clean();
}
ob_end_clean();

View file

@ -5,7 +5,7 @@
* Helper functions to create radar connect classes.
*/
require 'vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';
use Radar\Connect\Connect;
use Radar\Connect\Filter;

View file

@ -20,15 +20,15 @@ class Cache {
$this->cache = $cache;
}
public function contains(Entity $entity) {
return $this->cache->contains($entity->apiUri());
public function contains($uri) {
return $this->cache->contains($uri);
}
public function fetch(Entity $entity) {
return $this->cache->fetch($entity->apiUri());
public function fetch($uri) {
return $this->cache->fetch($uri);
}
public function save(Entity $entity) {
public function save($uri, Entity $entity) {
// TODO Make configurable.
$ttl = array(
'group' => 60 * 60,
@ -36,11 +36,12 @@ class Cache {
'event' => 60 * 5,
'location' => 60 * 60 * 24,
'taxonomy_term' => 60 * 60 * 24 * 30,
'file' => 60 * 60,
);
return $this->cache->save($entity->apiUri(), $entity, $ttl[$entity->type]);
return $this->cache->save($uri, $entity, $ttl[$entity->type]);
}
public function delete(Entity $entity) {
return $this->cache->delete($entity->apiUri());
public function delete($uri) {
return $this->cache->delete($uri);
}
}

View file

@ -29,6 +29,11 @@ class Connect {
*/
public $debug;
/**
* @var string ISO 639-1 code.
*/
public $language;
/**
* Constructor.
*
@ -44,7 +49,7 @@ class Connect {
$this->apiUrl = $configuration['api_url'];
}
else {
$this->apiUrl = 'https://radar.squat.net/api/1.0/';
$this->apiUrl = 'https://radar.squat.net/api/1.1/';
}
$this->debug = !empty($configuration['debug']);
}
@ -65,6 +70,36 @@ class Connect {
$this->cache = $cache;
}
/**
* Set, default, language for queries.
*/
public function setLanguage($langcode) {
$this->language = $langcode;
}
/**
* Retrieve language code.
*/
public function getLanguage() {
if (!empty($this->language)) {
return $this->language;
}
else {
return 'und';
}
}
/**
* Compute url for cache storage.
*
* Language is for the language requested, not necessarily the language of
* the entity, as different language requests can return different
* langage entities (not necessarity corresponding) based on fallback.
*/
public function cacheUri($entity) {
return $entity->apiUri() . '?language=' . $this->getLanguage();
}
/**
* Retrieve all fields for single entity.
*
@ -80,13 +115,18 @@ class Connect {
* The loaded entity.
*/
public function retrieveEntity(Entity $entity) {
if (!empty($this->cache) && $this->cache->contains($entity)) {
return $this->cache->fetch($entity);
$cacheUri = $this->cacheUri($entity);
if (!empty($this->cache) && $this->cache->contains($cacheUri)) {
return $this->cache->fetch($cacheUri);
}
$request = $this->client->get($entity->apiUri());
$entity = $this->parseResponse($response);
if ($this->getLanguage() != 'und') {
$query = $request->getQuery();
$query->set('language', $this->getLanguage());
}
$entity = $this->retrieve($request);
if (!empty($this->cache)) {
$this->cache->save($entity);
$this->cache->save($cacheUri, $entity);
}
return $entity;
}
@ -106,8 +146,8 @@ class Connect {
$cached = array();
if (!empty($this->cache)) {
foreach($entities as $key => $entity) {
if ($this->cache->contains($entity)) {
$cached[] = $this->cache->fetch($entity);
if ($this->cache->contains($this->cacheUri($entity))) {
$cached[] = $this->cache->fetch($this->cacheUri($entity));
unset($entities[$key]);
}
}
@ -115,13 +155,18 @@ class Connect {
$requests = array();
foreach ($entities as $entity) {
$requests[] = $this->client->get($entity->apiUri());
$request = $this->client->get($entity->apiUri());
if ($this->getLanguage() != 'und') {
$query = $request->getQuery();
$query->set('language', $this->getLanguage());
}
$requests[] = $request;
}
$retrieved = $this->retrieveMultiple($requests);
if (!empty($this->cache)) {
foreach ($retrieved as $entity) {
$this->cache->save($entity);
$this->cache->save($this->cacheUri($entity), $entity);
}
}
@ -136,8 +181,6 @@ class Connect {
}
/**
* Prepare a request to retrieve events.
*
@ -148,14 +191,27 @@ class Connect {
* A list of fields to load. Optional, default is most available fields.
* @param int $limit
* How many events to return.
* @param array $sort
* Optional array ['field_name' => 'order'], where order is ASC or DESC.
* @param array $keys
* Values for full text search ['search', 'words'] for OR ['search words'] for AND.
*
* @return \Guzzle\Http\Message\Request
* Request object to retrieve.
*/
public function prepareEventsRequest(Filter $filter, $fields = array(), $limit = 500) {
public function prepareEventsRequest(Filter $filter, $fields = array(), $limit = 500, $sort = array(), $keys = array()) {
$request = $this->client->get($this->apiUrl . 'search/events.json');
$query = $request->getQuery();
$query->set('facets', $filter->getQuery());
if ($this->getLanguage() != 'und') {
$query->set('language', $this->getLanguage());
}
if (!empty($sort)) {
$query->set('sort', $sort);
}
if (!empty($keys)) {
$query->set('keys', $keys);
}
if (! empty($fields)) {
// Always retrieve type.
$fields = array_merge($fields, array('type'));
@ -165,11 +221,13 @@ class Connect {
'title',
'type',
'uuid',
'nid',
'og_group_ref',
'date_time',
'offline',
'category',
'topic',
'price_category',
'price',
'link',
'phone',
@ -196,27 +254,42 @@ class Connect {
* A list of fields to load. Optional, default is most available fields.
* @param int $limit
* How many groups to return.
* @param array $sort
* Optional array ['field_name' => 'order'], where order is ASC or DESC.
* @param array $keys
* Values for full text search ['search', 'words'] for OR ['search words'] for AND.
*
* @return \Guzzle\Http\Message\Request
* Request object to retrieve.
*/
public function prepareGroupsRequest(Filter $filter, $fields = array(), $limit = 500) {
public function prepareGroupsRequest(Filter $filter, $fields = array(), $limit = 500, $sort = array(), $keys = array()) {
$request = $this->client->get($this->apiUrl . 'search/groups.json');
$query = $request->getQuery();
if ($this->getLanguage() != 'und') {
$query->set('language', $this->getLanguage());
}
$query->set('facets', $filter->getQuery());
if (!empty($sort)) {
$query->set('sort', $sort);
}
if (!empty($keys)) {
$query->set('keys', $keys);
}
if (! empty($fields)) {
$fields += array('type');
}
else {
$fields = array(
'uuid',
'title',
'type',
'nid',
'category',
'offline',
'topic',
'body',
'email',
'weblink',
'link',
'offline',
'opening_times',
'phone',
@ -228,6 +301,22 @@ class Connect {
return $request;
}
/**
* Retrieve API response from a prepared request.
*
* @param \Guzzle\Http\Message\RequestInterface $request
*
* @return \Guzzle\Http\Message\Response
*/
public function retrieveResponse(RequestInterface $request) {
$response = $this->client->send($request);
if ($this->debug) {
var_export($response->getHeaders());
var_export($response->getBody());
}
return $response;
}
/**
* Retrieve entities from a prepared request.
*
@ -241,7 +330,9 @@ class Connect {
var_export($response->getHeaders());
var_export($response->getBody());
}
return $this->parseResponse($response);
$items = $this->parseResponse($response);
$entity = reset($items);
return $entity;
}
/**
@ -277,24 +368,52 @@ class Connect {
*
* TODO this doesn't need to be in here.
*/
protected function parseResponse(Response $response) {
public function parseResponse(Response $response) {
$items = array();
$content = $response->json();
if (isset($content['type'])) {
// Single item response.
$class = __NAMESPACE__ . '\\Entity\\' . Entity::className($content['type']);
$content['apiBase'] = $this->apiUrl;
$items[] = new $class($content);
}
else {
foreach ($content as $key => $item) {
$class = __NAMESPACE__ . '\\Entity\\' . Entity::className($item['type']);
$item['apiBase'] = $this->apiUrl;
$items[] = new $class($item);
$result = empty($content['result']) ? array() : $content['result'];
$first_content_item = current($result);
if (!empty($first_content_item)) {
// List response, that is non-empty.
foreach ($result as $key => $item) {
$class = __NAMESPACE__ . '\\Entity\\' . Entity::className($item['type']);
$item['apiBase'] = $this->apiUrl;
$items[] = new $class($item);
}
}
else {
// Empty response.
$items = array();
}
}
return $items;
}
/**
* Parse response metadata.
*/
public function parseResponseMeta(Response $response) {
$output = [];
$content = $response->json();
if (isset($content['count'])) {
$output['count'] = $content['count'];
}
if (isset($content['facets'])) {
$output['facets'] = $content['facets'];
}
return $output;
}
}

View file

@ -27,6 +27,7 @@ abstract class Entity {
'category' => 'TaxonomyTerm',
'topic' => 'TaxonomyTerm',
'price' => 'TaxonomyTerm',
'file' => 'RadarFile',
);
return $classes[$type];
}

View file

@ -87,11 +87,21 @@ class Event extends Node {
/**
* Return image field data.
*
* TODO API isn't putting the data into the output.
*/
public function getImageRaw() {
return $this->image;
return $this->image['file'];
}
/**
* Return image file object.
*
* @return RadarFile|NULL
*/
public function getImage() {
if (!empty($this->image['file'])) {
return new RadarFile($this->image['file']);
}
return NULL;
}
public function getPriceCategoryRaw() {

View file

@ -17,17 +17,42 @@ class Group extends Node {
}
/**
* TODO not appearing in the API output.
* Logo raw data.
*/
public function getGroupLogoRaw() {
return $this->group_logo;
}
/**
* TODO not appearing in the API output.
* Logo file object.
*
* @return File|NULL
*/
public function getGroupLogo() {
if (!empty($this->group_logo)) {
return new RadarFile($this->group_logo);
}
return NULL;
}
/**
* Raw image entity array.
*/
public function getImageRaw() {
return $this->image->file;
return $this->image;
}
/**
* Return image entity object.
*
* @return RadarFile|NULL
*/
public function getImage() {
if (!empty($this->image->file)) {
return new RadarFile($this->image);
}
return NULL;
}
/**

View file

@ -65,7 +65,11 @@ class Node extends Entity {
}
public function getCategoriesRaw() {
return $this->category;
$categories = array();
foreach ($this->category as $category) {
$categories[$category['id']] = $category;
}
return $category;
}
/**
@ -77,14 +81,18 @@ class Node extends Entity {
$categories = array();
if (is_array($this->category)) {
foreach ($this->category as $category) {
$categories[] = new TaxonomyTerm($category);
$categories[$category['id']] = new TaxonomyTerm($category);
}
}
return $categories;
}
public function getTopicsRaw() {
return $this->topics;
$topics = array();
foreach ($this->topic as $topic) {
$topics[$topic['id']] = $topic;
}
return $topics;
}
/**
@ -96,7 +104,7 @@ class Node extends Entity {
$topics = array();
if (is_array($this->topic)) {
foreach ($this->topic as $topic) {
$topics[] = new TaxonomyTerm($topic);
$topics[$topic['id']] = new TaxonomyTerm($topic);
}
}
return $topics;

View file

@ -0,0 +1,67 @@
<?php
namespace Radar\Connect\Entity;
class RadarFile extends Entity {
public $title;
public $mime;
public $size;
public $url;
function __construct($data = array()) {
$this->set($data);
$this->type = 'file';
}
public function set($data) {
$data = (array) $data;
parent::set($data);
if (isset($data['fid'])) {
$this->drupalId = $data['fid'];
}
}
public function apiUri() {
if (isset($this->apiUri)) {
return $this->apiUri;
}
elseif (isset($this->uuid)) {
return $this->apiBase . 'file/' . $this->uuid;
}
throw new Exception();
}
/**
* Title is usually filename.
*/
public function getTitle() {
return $this->title;
}
/**
* Mimetype, eg image/jpeg
*/
public function getImageRaw() {
return $this->mime;
}
/**
* URL to the file itself.
*
* @return string
*/
public function getUrl() {
return $this->url;
}
/**
* Size, in bytes.
*
* @return int
*/
public function getSize() {
return $this->size;
}
}

View file

@ -9,6 +9,18 @@ class Filter {
*/
private $query;
/**
* Add arbitary filter, knowing key.
*
* If you add something that doesn't work it usually just returns no results.
*
* @param string key
* @param string value
*/
public function add($key, $value) {
$this->query[$key][] = $value;
}
/**
* Filter by group.
*
@ -43,7 +55,7 @@ class Filter {
/**
* Filter by year.
*
* @param string $year.
* @param string $year
* Optional: year in YYYY format. Default current year.
*/
public function addYear($year = 'now') {
@ -128,4 +140,5 @@ class Filter {
public function getQuery() {
return $this->query;
}
}

View file

@ -17,22 +17,24 @@ class EventTest extends EntityTestCase {
$this->assertEquals($event->getInternalId(), '9171');
$this->assertEquals($event->getInternalVid(), '9680');
// Node level fields
$this->assertEquals($event->apiUri(), 'https://new-radar.squat.net/api/1.0/node/69300100-b104-4c37-b651-48351543e8a6');
$this->assertEquals($event->apiUri(), 'https://radar.squat.net/api/1.1/node/69300100-b104-4c37-b651-48351543e8a6');
$body_text = "<p>This is a handy event that site devs are using.</p>\n";
$this->assertEquals($event->getBody(), $body_text);
$this->assertEquals($event->getBodyRaw(), array('value' => $body_text, 'summary' => '', 'format' => 'rich_text_editor'));
$this->assertEquals($event->getUrlView(),'https://new-radar.squat.net/en/event/amsterdam/joes-garage/2014-02-24/test-event');
$this->assertEquals($event->getUrlEdit(),'https://new-radar.squat.net/en/node/9171/edit');
$this->assertEquals($event->getUrlView(),'https://radar.squat.net/en/event/amsterdam/joes-garage/2014-02-24/test-event');
$this->assertEquals($event->getUrlEdit(),'https://radar.squat.net/en/node/9171/edit');
$this->assertEquals($event->getStatus(), TRUE);
$this->assertEquals($event->getCreated()->getTimestamp(),'1424807163');
$this->assertEquals($event->getUpdated()->getTimestamp(),'1424807163');
// Node level references
$categories = $event->getCategories();
$this->assertTrue($categories[0] instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($categories[0]->apiUri(),'https://new-radar.squat.net/api/1.0/taxonomy_term/e85a688d-03ac-4008-a3cb-1adb7e8f718a');
$category = reset($categories);
$this->assertTrue($category instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($category->apiUri(),'https://radar.squat.net/api/1.1/taxonomy_term/e85a688d-03ac-4008-a3cb-1adb7e8f718a');
$topics = $event->getTopics();
$this->assertTrue($topics[0] instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($topics[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/taxonomy_term/6c73cff2-9dc9-41db-a79e-f54bf4c010f7');
$topic = reset($topics);
$this->assertTrue($topic instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($topic->apiUri(), 'https://radar.squat.net/api/1.1/taxonomy_term/6c73cff2-9dc9-41db-a79e-f54bf4c010f7');
// Simple fields.
$this->assertTrue($event instanceof Event);
$this->assertEquals($event->getTitle(), 'Test event');
@ -45,11 +47,11 @@ class EventTest extends EntityTestCase {
// Entity references.
$price = $event->getPriceCategory();
$this->assertTrue($price[0] instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($price[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/taxonomy_term/9d943d0c-e2bf-408e-9110-4bfb044f60c0');
$this->assertEquals($price[1]->apiUri(), 'https://new-radar.squat.net/api/1.0/taxonomy_term/6f4101f4-cd9b-49f2-91a3-203d2b47a3ed');
$this->assertEquals($price[0]->apiUri(), 'https://radar.squat.net/api/1.1/taxonomy_term/9d943d0c-e2bf-408e-9110-4bfb044f60c0');
$this->assertEquals($price[1]->apiUri(), 'https://radar.squat.net/api/1.1/taxonomy_term/6f4101f4-cd9b-49f2-91a3-203d2b47a3ed');
$groups = $event->getGroups();
$this->assertTrue($groups[0] instanceof \Radar\Connect\Entity\Group);
$this->assertEquals($groups[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/node/0df4bcd7-54b4-4559-a960-60b5042d3d48');
$this->assertEquals($groups[0]->apiUri(), 'https://radar.squat.net/api/1.1/node/0df4bcd7-54b4-4559-a960-60b5042d3d48');
$raw_dates = $event->getDatesRaw();
$this->assertEquals($raw_dates[0]['value'], '1393271100');
$this->assertEquals($raw_dates[0]['time_end'], '2014-02-24T21:00:00+01:00');
@ -59,6 +61,6 @@ class EventTest extends EntityTestCase {
$this->assertEquals($dates[0]['end']->getTimezone()->getName(), '+01:00');
$locations = $event->getLocations();
$this->assertTrue($locations[0] instanceof \Radar\Connect\Entity\Location);
$this->assertEquals($locations[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/location/3c58abc1-e095-4db5-996d-2a064cebb2d3');
$this->assertEquals($locations[0]->apiUri(), 'https://radar.squat.net/api/1.1/location/3c58abc1-e095-4db5-996d-2a064cebb2d3');
}
}

View file

@ -17,23 +17,25 @@ class GroupTest extends EntityTestCase {
$this->assertEquals($group->getInternalId(), '41');
$this->assertEquals($group->getInternalVid(), '8935');
// Node level fields
$this->assertEquals($group->apiUri(), 'https://new-radar.squat.net/api/1.0/node/0df4bcd7-54b4-4559-a960-60b5042d3d48');
$this->assertEquals($group->apiUri(), 'https://radar.squat.net/api/1.1/node/0df4bcd7-54b4-4559-a960-60b5042d3d48');
$body_text = "<p>Joe's Garage is een ontmoetingsplek voor al dan niet krakers uit de transvaalbuurt en omstreken.</p>\n";
$this->assertEquals($group->getBody(), $body_text);
$this->assertEquals($group->getBodyRaw(), array('value' => $body_text, 'summary' => '', 'format' => 'rich_text_editor'));
$this->assertEquals($group->getUrlView(),'https://new-radar.squat.net/nl/amsterdam/joes-garage?language=nl');
$this->assertEquals($group->getUrlEdit(),'https://new-radar.squat.net/nl/node/41/edit?language=nl');
$this->assertEquals($group->getUrlView(),'https://radar.squat.net/nl/amsterdam/joes-garage?language=nl');
$this->assertEquals($group->getUrlEdit(),'https://radar.squat.net/nl/node/41/edit?language=nl');
$this->assertEquals($group->getStatus(), TRUE);
$this->assertEquals($group->getCreated()->getTimestamp(),'1409775185');
$this->assertEquals($group->getUpdated()->getTimestamp(),'1424352703');
// Node level references
$categories = $group->getCategories();
$this->assertEquals(count($categories), 6);
$this->assertTrue($categories[0] instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($categories[0]->apiUri(),'https://new-radar.squat.net/api/1.0/taxonomy_term/e97f372b-29bc-460b-bff6-35d2462411ff?language=nl');
$category = reset($categories);
$this->assertTrue($category instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($category->apiUri(),'https://radar.squat.net/api/1.1/taxonomy_term/e97f372b-29bc-460b-bff6-35d2462411ff?language=nl');
$topics = $group->getTopics();
$this->assertTrue($topics[0] instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($topics[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/taxonomy_term/82f00d0a-03df-40ec-a06d-67b875675858?language=nl');
$topic = reset($topics);
$this->assertTrue($topic instanceof \Radar\Connect\Entity\TaxonomyTerm);
$this->assertEquals($topic->apiUri(), 'https://radar.squat.net/api/1.1/taxonomy_term/82f00d0a-03df-40ec-a06d-67b875675858?language=nl');
// Simple fields.
$this->assertTrue($group instanceof Group);
$this->assertEquals($group->getTitle(), 'Joe\'s Garage');
@ -49,6 +51,6 @@ class GroupTest extends EntityTestCase {
// Entity references.
$locations = $group->getLocations();
$this->assertTrue($locations[0] instanceof \Radar\Connect\Entity\Location);
$this->assertEquals($locations[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/location/3c58abc1-e095-4db5-996d-2a064cebb2d3?language=nl');
$this->assertEquals($locations[0]->apiUri(), 'https://radar.squat.net/api/1.1/location/3c58abc1-e095-4db5-996d-2a064cebb2d3?language=nl');
}
}

View file

@ -18,12 +18,12 @@ class ListingsGroupTest extends EntityTestCase {
$this->assertEquals($group->getInternalVid(), '8976');
$this->assertEquals($group->getLanguage(), 'de');
// Node level fields
$this->assertEquals($group->apiUri(), 'https://new-radar.squat.net/api/1.0/node/9e43dac6-e1da-4f60-8428-de9f32ac9eb0');
$this->assertEquals($group->apiUri(), 'https://radar.squat.net/api/1.1/node/9e43dac6-e1da-4f60-8428-de9f32ac9eb0');
$body_text = "<p>Berliner Terminkalender für linke Subkultur und Politik</p>\n";
$this->assertEquals($group->getBody(), $body_text);
$this->assertEquals($group->getBodyRaw(), array('value' => $body_text, 'summary' => '', 'format' => 'rich_text_editor'));
$this->assertEquals($group->getUrlView(),'https://new-radar.squat.net/en/node/1599');
$this->assertEquals($group->getUrlEdit(),'https://new-radar.squat.net/en/node/1599/edit');
$this->assertEquals($group->getUrlView(),'https://radar.squat.net/en/node/1599');
$this->assertEquals($group->getUrlEdit(),'https://radar.squat.net/en/node/1599/edit');
$this->assertEquals($group->getStatus(), TRUE);
$this->assertEquals($group->getCreated()->getTimestamp(),'1415355772');
$this->assertEquals($group->getUpdated()->getTimestamp(),'1424428820');
@ -46,6 +46,6 @@ class ListingsGroupTest extends EntityTestCase {
$this->assertEquals(count($locations), 0);
$listed_groups = $group->getGroupsListed();
$this->assertEquals(count($listed_groups), 76);
$this->assertEquals($listed_groups[0]->apiUri(), 'https://new-radar.squat.net/api/1.0/node/da296694-ae72-47a9-9073-e450143b9c58');
$this->assertEquals($listed_groups[0]->apiUri(), 'https://radar.squat.net/api/1.1/node/da296694-ae72-47a9-9073-e450143b9c58');
}
}

View file

@ -14,7 +14,7 @@ class TaxonomyTermTest extends EntityTestCase {
$this->assertTrue($term instanceof TaxonomyTerm);
$this->assertEquals($term->getTitle(), 'action/protest/camp');
$this->assertEquals($term->apiUri(), 'https://new-radar.squat.net/api/1.0/taxonomy_term/e85a688d-03ac-4008-a3cb-1adb7e8f718a');
$this->assertEquals($term->apiUri(), 'https://radar.squat.net/api/1.1/taxonomy_term/e85a688d-03ac-4008-a3cb-1adb7e8f718a');
$this->assertEquals($term->getUuid(), 'e85a688d-03ac-4008-a3cb-1adb7e8f718a');
$this->assertEquals($term->getVuuid(), null);
$this->assertEquals($term->getInternalId(), 7);

View file

@ -12,4 +12,4 @@ Content-Length: 2613
Content-Type: application/json
Strict-Transport-Security: max-age=15768000;includeSubDomains
{"body":{"value":"<p>This is a handy event that site devs are using.</p>\n","summary":"","format":"rich_text_editor"},"category":[{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/e85a688d-03ac-4008-a3cb-1adb7e8f718a","id":"e85a688d-03ac-4008-a3cb-1adb7e8f718a","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8","id":"2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8","resource":"taxonomy_term"}],"group_content_access":"0","og_group_ref":[{"uri":"https://new-radar.squat.net/api/1.0/node/0df4bcd7-54b4-4559-a960-60b5042d3d48","id":"0df4bcd7-54b4-4559-a960-60b5042d3d48","resource":"node"}],"og_group_request":[],"date_time":[{"value":"1393271100","value2":"1393272000","duration":900,"time_start":"2014-02-24T20:45:00+01:00","time_end":"2014-02-24T21:00:00+01:00","rrule":null}],"image":[],"price":"Suggested donation \u20ac3","email":"joe@squat.net","link":[{"url":"http://www.joesgarage.nl/","attributes":[]}],"offline":[{"uri":"https://new-radar.squat.net/api/1.0/location/3c58abc1-e095-4db5-996d-2a064cebb2d3","id":"3c58abc1-e095-4db5-996d-2a064cebb2d3","resource":"location"}],"phone":"01-12345","topic":[{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/6c73cff2-9dc9-41db-a79e-f54bf4c010f7","id":"6c73cff2-9dc9-41db-a79e-f54bf4c010f7","resource":"taxonomy_term"}],"title_field":"Test event","price_category":[{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/9d943d0c-e2bf-408e-9110-4bfb044f60c0","id":"9d943d0c-e2bf-408e-9110-4bfb044f60c0","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/6f4101f4-cd9b-49f2-91a3-203d2b47a3ed","id":"6f4101f4-cd9b-49f2-91a3-203d2b47a3ed","resource":"taxonomy_term"}],"og_membership":[],"og_membership__1":[],"og_membership__2":[],"og_membership__3":[],"og_group_ref__og_membership":[],"og_group_ref__og_membership__1":[],"og_group_ref__og_membership__2":[],"og_group_ref__og_membership__3":[],"og_group_request__og_membership":[],"og_group_request__og_membership__1":[],"og_group_request__og_membership__2":[],"og_group_request__og_membership__3":[],"nid":"9171","vid":"9680","is_new":false,"type":"event","title":"Test event","language":"en","url":"https://new-radar.squat.net/en/event/amsterdam/joes-garage/2014-02-24/test-event","edit_url":"https://new-radar.squat.net/en/node/9171/edit","status":"1","promote":"0","sticky":"0","created":"1424807163","changed":"1424807163","feed_nid":null,"flag_abuse_node_user":[],"flag_abuse_whitelist_node_user":[],"uuid":"69300100-b104-4c37-b651-48351543e8a6","vuuid":"a66a7c7d-5ed4-487e-92b8-ee876b91e2d6"}
{"body":{"value":"<p>This is a handy event that site devs are using.</p>\n","summary":"","format":"rich_text_editor"},"category":[{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/e85a688d-03ac-4008-a3cb-1adb7e8f718a","id":"e85a688d-03ac-4008-a3cb-1adb7e8f718a","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8","id":"2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8","resource":"taxonomy_term"}],"group_content_access":"0","og_group_ref":[{"uri":"https://radar.squat.net/api/1.1/node/0df4bcd7-54b4-4559-a960-60b5042d3d48","id":"0df4bcd7-54b4-4559-a960-60b5042d3d48","resource":"node"}],"og_group_request":[],"date_time":[{"value":"1393271100","value2":"1393272000","duration":900,"time_start":"2014-02-24T20:45:00+01:00","time_end":"2014-02-24T21:00:00+01:00","rrule":null}],"image":[],"price":"Suggested donation \u20ac3","email":"joe@squat.net","link":[{"url":"http://www.joesgarage.nl/","attributes":[]}],"offline":[{"uri":"https://radar.squat.net/api/1.1/location/3c58abc1-e095-4db5-996d-2a064cebb2d3","id":"3c58abc1-e095-4db5-996d-2a064cebb2d3","resource":"location"}],"phone":"01-12345","topic":[{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/6c73cff2-9dc9-41db-a79e-f54bf4c010f7","id":"6c73cff2-9dc9-41db-a79e-f54bf4c010f7","resource":"taxonomy_term"}],"title_field":"Test event","price_category":[{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/9d943d0c-e2bf-408e-9110-4bfb044f60c0","id":"9d943d0c-e2bf-408e-9110-4bfb044f60c0","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/6f4101f4-cd9b-49f2-91a3-203d2b47a3ed","id":"6f4101f4-cd9b-49f2-91a3-203d2b47a3ed","resource":"taxonomy_term"}],"og_membership":[],"og_membership__1":[],"og_membership__2":[],"og_membership__3":[],"og_group_ref__og_membership":[],"og_group_ref__og_membership__1":[],"og_group_ref__og_membership__2":[],"og_group_ref__og_membership__3":[],"og_group_request__og_membership":[],"og_group_request__og_membership__1":[],"og_group_request__og_membership__2":[],"og_group_request__og_membership__3":[],"nid":"9171","vid":"9680","is_new":false,"type":"event","title":"Test event","language":"en","url":"https://radar.squat.net/en/event/amsterdam/joes-garage/2014-02-24/test-event","edit_url":"https://radar.squat.net/en/node/9171/edit","status":"1","promote":"0","sticky":"0","created":"1424807163","changed":"1424807163","feed_nid":null,"flag_abuse_node_user":[],"flag_abuse_whitelist_node_user":[],"uuid":"69300100-b104-4c37-b651-48351543e8a6","vuuid":"a66a7c7d-5ed4-487e-92b8-ee876b91e2d6"}

View file

@ -12,4 +12,4 @@ Content-Length: 2872
Content-Type: application/json
Strict-Transport-Security: max-age=15768000;includeSubDomains
{"body":{"value":"<p>Joe's Garage is een ontmoetingsplek voor al dan niet krakers uit de transvaalbuurt en omstreken.</p>\n","summary":"","format":"rich_text_editor"},"category":[{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/e97f372b-29bc-460b-bff6-35d2462411ff?language=nl","id":"e97f372b-29bc-460b-bff6-35d2462411ff","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8?language=nl","id":"2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/68197b93-2ece-4b0f-9a76-d9e99bda2603?language=nl","id":"68197b93-2ece-4b0f-9a76-d9e99bda2603","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/8e846372-fa86-4cb2-87d1-f24da784ec6b?language=nl","id":"8e846372-fa86-4cb2-87d1-f24da784ec6b","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/0b9e8d1f-d51d-4d32-b984-2dba1099e0fa?language=nl","id":"0b9e8d1f-d51d-4d32-b984-2dba1099e0fa","resource":"taxonomy_term"},{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/20a888f9-54c1-4767-8af1-40de3d1d2636?language=nl","id":"20a888f9-54c1-4767-8af1-40de3d1d2636","resource":"taxonomy_term"}],"group_group":true,"group_logo":[],"image":[],"email":"joe@squat.net","link":[{"url":"http://www.joesgarage.nl/","attributes":[]}],"offline":[{"uri":"https://new-radar.squat.net/api/1.0/location/3c58abc1-e095-4db5-996d-2a064cebb2d3?language=nl","id":"3c58abc1-e095-4db5-996d-2a064cebb2d3","resource":"location"}],"opening_times":{"value":"<p>Maandag: 19u <strong>Volkseten Vegazulu</strong></p>\n<p>Dinsdag: 11u/15u <strong>Kraakspreekuur, (daarna is er een borrel)</strong></p>\n<p>Dinsdag: 20u/21u30 <strong>Kraakspreekuur Oost</strong></p>\n<p>Woensdag: 15u/18u <strong>Lonely Collective Day Cafe</strong></p>\n<p>Donderdag: 19u <strong>Volkseten Vegazulu</strong></p>\n<p>Zaterdag: 14u/18u <strong>Weggeefwinkel</strong></p>\n<p>Zondag: 20u <strong>Filmavonden/Infoavonden</strong></p>\n","format":"rich_text_editor"},"phone":null,"topic":[{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/82f00d0a-03df-40ec-a06d-67b875675858?language=nl","id":"82f00d0a-03df-40ec-a06d-67b875675858","resource":"taxonomy_term"}],"notifications":["joe@squat.net"],"type":"group","members":[],"members__1":[],"members__2":[],"members__3":[],"nid":"41","vid":"8935","is_new":false,"title":"Joe's Garage","language":"en","url":"https://new-radar.squat.net/nl/amsterdam/joes-garage?language=nl","edit_url":"https://new-radar.squat.net/nl/node/41/edit?language=nl","status":"1","promote":"0","sticky":"0","created":"1409775185","changed":"1424352703","feed_nid":null,"flag_abuse_node_user":[],"flag_abuse_whitelist_node_user":[],"uuid":"0df4bcd7-54b4-4559-a960-60b5042d3d48","vuuid":"c6df91b9-58bd-4a5f-a52e-64ec18f267f0"}
{"body":{"value":"<p>Joe's Garage is een ontmoetingsplek voor al dan niet krakers uit de transvaalbuurt en omstreken.</p>\n","summary":"","format":"rich_text_editor"},"category":[{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/e97f372b-29bc-460b-bff6-35d2462411ff?language=nl","id":"e97f372b-29bc-460b-bff6-35d2462411ff","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8?language=nl","id":"2a56c4d7-eb98-4f96-9ac6-d383a1af5ce8","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/68197b93-2ece-4b0f-9a76-d9e99bda2603?language=nl","id":"68197b93-2ece-4b0f-9a76-d9e99bda2603","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/8e846372-fa86-4cb2-87d1-f24da784ec6b?language=nl","id":"8e846372-fa86-4cb2-87d1-f24da784ec6b","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/0b9e8d1f-d51d-4d32-b984-2dba1099e0fa?language=nl","id":"0b9e8d1f-d51d-4d32-b984-2dba1099e0fa","resource":"taxonomy_term"},{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/20a888f9-54c1-4767-8af1-40de3d1d2636?language=nl","id":"20a888f9-54c1-4767-8af1-40de3d1d2636","resource":"taxonomy_term"}],"group_group":true,"group_logo":[],"image":[],"email":"joe@squat.net","link":[{"url":"http://www.joesgarage.nl/","attributes":[]}],"offline":[{"uri":"https://radar.squat.net/api/1.1/location/3c58abc1-e095-4db5-996d-2a064cebb2d3?language=nl","id":"3c58abc1-e095-4db5-996d-2a064cebb2d3","resource":"location"}],"opening_times":{"value":"<p>Maandag: 19u <strong>Volkseten Vegazulu</strong></p>\n<p>Dinsdag: 11u/15u <strong>Kraakspreekuur, (daarna is er een borrel)</strong></p>\n<p>Dinsdag: 20u/21u30 <strong>Kraakspreekuur Oost</strong></p>\n<p>Woensdag: 15u/18u <strong>Lonely Collective Day Cafe</strong></p>\n<p>Donderdag: 19u <strong>Volkseten Vegazulu</strong></p>\n<p>Zaterdag: 14u/18u <strong>Weggeefwinkel</strong></p>\n<p>Zondag: 20u <strong>Filmavonden/Infoavonden</strong></p>\n","format":"rich_text_editor"},"phone":null,"topic":[{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/82f00d0a-03df-40ec-a06d-67b875675858?language=nl","id":"82f00d0a-03df-40ec-a06d-67b875675858","resource":"taxonomy_term"}],"notifications":["joe@squat.net"],"type":"group","members":[],"members__1":[],"members__2":[],"members__3":[],"nid":"41","vid":"8935","is_new":false,"title":"Joe's Garage","language":"en","url":"https://radar.squat.net/nl/amsterdam/joes-garage?language=nl","edit_url":"https://radar.squat.net/nl/node/41/edit?language=nl","status":"1","promote":"0","sticky":"0","created":"1409775185","changed":"1424352703","feed_nid":null,"flag_abuse_node_user":[],"flag_abuse_whitelist_node_user":[],"uuid":"0df4bcd7-54b4-4559-a960-60b5042d3d48","vuuid":"c6df91b9-58bd-4a5f-a52e-64ec18f267f0"}

File diff suppressed because one or more lines are too long

View file

@ -12,4 +12,4 @@ Content-Length: 360
Content-Type: application/json
Strict-Transport-Security: max-age=15768000;includeSubDomains
{"tid":"7","name":"action/protest/camp","description":"","weight":"0","node_count":10,"url":"https://new-radar.squat.net/en/category/action-protest-camp","parent":[],"parents_all":[{"uri":"https://new-radar.squat.net/api/1.0/taxonomy_term/7","id":"7","resource":"taxonomy_term"}],"feed_nid":null,"type":"category","uuid":"e85a688d-03ac-4008-a3cb-1adb7e8f718a"}
{"tid":"7","name":"action/protest/camp","description":"","weight":"0","node_count":10,"url":"https://radar.squat.net/en/category/action-protest-camp","parent":[],"parents_all":[{"uri":"https://radar.squat.net/api/1.1/taxonomy_term/7","id":"7","resource":"taxonomy_term"}],"feed_nid":null,"type":"category","uuid":"e85a688d-03ac-4008-a3cb-1adb7e8f718a"}