Skip to content
Browse files

Removing cruft. Note to self... must remember to git rm when yoy move…

… stuff
  • Loading branch information...
1 parent 2ce1e74 commit 8751dab930245977befb4cccc6f044b8b4ff3b09 Jonathan Moss committed
View
BIN Freebase.phar
Binary file not shown.
View
BIN src/Freebase.phar
Binary file not shown.
View
23 src/classes/freebase/Constants.php
@@ -1,23 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * @package freebase
- */
-class Constants
-{
- /**
- * Response when call successful
- */
- const API_RESPONSE_CODE_OK = '/api/status/ok';
-
- /**
- * Response when call failed
- */
- const API_RESPONSE_CODE_ERROR = '/api/status/error';
-
-}
View
86 src/classes/freebase/DomFactory.php
@@ -1,86 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * The response factory class provides method to generate a Node DOM from freebase responses
- *
- * @package freebase
- */
-class DomFactory
-{
-
- /**
- * @param string $json
- * @return \freebase\Node
- */
- public static function createDomFromJson($json, $id = null)
- {
- $node = null;
- $data = \json_decode($json, true);
- if (null === $data) {
- throw new \freebase\exception\InvalidJson($json);
- }
- if (self::getResponseCode($data, $id) == Constants::API_RESPONSE_CODE_OK ) {
- if (null === $id) {
- $node = self::createNode(self::getResultNode($data), 'root');
- } else {
- $node = self::createNode(self::getResultNode($data, $id), $id);
- }
-
- } else {
- throw new \freebase\exception\ApiError("");
- }
- return $node;
- }
-
- /**
- *
- * @param array $data
- * @param string $id
- * @return string
- */
- protected static function getResponseCode(array $data, $id = null)
- {
- $code = null;
- if (null == $id) {
- $code = isset($data['code']) ? $data['code'] : null;
- } else {
- $code = isset($data[$id]['code']) ? $data[$id]['code'] : null;
- }
- return $code;
- }
-
- protected static function getResultNode(array $data, $id = null)
- {
- $result = null;
- if (null == $id) {
- $result = $data['result'];
- } else {
- $result = $data[$id]['result'];
- }
- return $result;
- }
-
- /**
- * @param array $data
- * @param string $name
- * @return \freebase\Node
- */
- protected static function createNode(array $data, $name = null)
- {
- $node = new Node($name);
- foreach ($data as $key => $value) {
- if (\is_scalar($value)) {
- $node->setAttributeValue($key, $value);
- } else {
- $node->addChild(self::createNode($value, $key));
- }
- }
- return $node;
- }
-
-}
View
22 src/classes/freebase/Enum.php
@@ -1,22 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2010 Tangent Labs
- * @version SVN: $Id$
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * @package freebase
- */
-class Enum
-{
- const API_RESPONSE_CODE_OK = '/api/status/ok';
- const API_RESPONSE_CODE_ERROR = '/api/status/error';
-
- /**
- * Attribute types that need special handling
- */
- const ATTRIB_TYPE = 'type';
- const ATTRIB_EXPECTED_TYPE = 'expected_type';
-}
View
16 src/classes/freebase/Exception.php
@@ -1,16 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * Base class for freebase exceptions
- *
- * @package freebase
- */
-class Exception extends \Exception
-{
-
-}
View
55 src/classes/freebase/Factory.php
@@ -1,55 +0,0 @@
-<?php
-/**
- * @package
- * @copyright 2010 Tangent Labs
- * @version SVN: $Id$
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * Description of Factory
- *
- * @package
- */
-class Factory
-{
-
- /**
- * @param string $json
- * @return \freebase\Node
- */
- public static function loadFromJson($json)
- {
- $node = null;
- $data = \json_decode($json, true);
- if (null === $data) {
- throw new \freebase\exception\InvalidJson();
- }
- if (isset($data['code']) && $data['code'] == Enum::API_RESPONSE_CODE_OK ) {
- $node = self::createNode($data['result'], 'root');
- } else {
- $messages = \implode(". ", $data['messages']);
- throw new \freebase\exception\ApiError($messages);
- }
- return $node;
- }
-
- /**
- * @param array $data
- * @param string $name
- * @return \freebase\Node
- */
- protected static function createNode(array $data, $name = null)
- {
- $node = new Node($name);
- foreach ($data as $key => $value) {
- if (\is_scalar($value)) {
- $node->setProperty($key, $value);
- } else {
- $node->addNode(self::createNode($value, $key));
- }
- }
- return $node;
- }
-
-}
View
81 src/classes/freebase/Freebase.php
@@ -1,81 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * Master interface class to freebase
- *
- * @package freebase
- */
-class Freebase
-{
-
- const PATH_TOPIC = 'experimental/topic/standard/?id=';
-
- const PATH_MQLREAD = 'service/mqlread';
-
- /**
- * @var string
- */
- private $baseUrl;
-
- /**
- * @param string $baseUrl
- */
- public function __construct($baseUrl = "http://api.freebase.com/api/")
- {
- if (\substr($baseUrl, -1) !== '/') {
- $baseUrl .= '/';
- }
- $this->baseUrl = $baseUrl;
- }
-
- /**
- * @param string $id
- * @return \freebase\Node
- */
- public function fetchByTopicId($id, array $domains = array())
- {
- $url = $this->baseUrl . self::PATH_TOPIC . $id;
- if (!empty($domains)) {
- $url .= '?' . \implode(',', $domains);
- }
- $json = $this->doRequest($url);
- return DomFactory::createDomFromJson($json, $id);
- }
-
- /**
- * @param Query $query
- * @return \freebase\Node
- */
- public function fetchByQuery(Query $query)
- {
- $url = $this->baseUrl . self::PATH_MQLREAD;
- $json = $this->doRequest($url, $query->__toJson());
- return DomFactory::createDomFromJson($json);
- }
-
- /**
- * @param string $url
- * @param string $jsonData
- * @return string
- */
- protected function doRequest($url, $jsonData = null)
- {
- $ch = \curl_init();
- \curl_setopt($ch, \CURLOPT_URL, $url);
- \curl_setopt($ch, \CURLOPT_HEADER, false);
- \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, true);
- if (null !== $jsonData) {
- \curl_setopt($ch, \CURLOPT_POST, true);
- \curl_setopt($ch, \CURLOPT_POSTFIELDS, array('query' => $jsonData));
- }
- $response = \curl_exec($ch);
- \curl_close($ch);
- return $response;
- }
-
-}
View
196 src/classes/freebase/Node.php
@@ -1,196 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * Description of Node
- *
- * @package freebase
- */
-class Node implements \IteratorAggregate
-{
-
- /**
- * @var string
- */
- protected $name;
-
- /**
- * @var array
- */
- protected $children = array();
-
- /**
- * @var \freebase\Node
- */
- protected $parent = null;
-
- /**
- * @var array
- */
- protected $attributes = array();
-
- /**
- * @param string $name
- */
- public function __construct($name = null)
- {
- $this->name = $name;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * @return \freebase\Node
- */
- public function getParent()
- {
- return $this->parent;
- }
-
-
- /**
- * @param \freebase\Node $parent
- * @return \freebase\Node
- */
- public function setParent(\freebase\Node $parent)
- {
- $this->parent = $parent;
- return $this;
- }
-
- //////////////////////////////
- // ATTRIBUTE ACCESS METHODS //
- //////////////////////////////
-
- /**
- * Returns all attributes as an array keyed by the attribute name
- *
- * @return array
- */
- public function getAttributes()
- {
- return $this->attributes;
- }
-
- /**
- * @param mixed $value
- * @return \freebase\Node
- */
- public function setAttributeValue($key, $value)
- {
- $this->attributes[$key] = $value;
- return $this;
- }
-
- /**
- * @param string $key
- * @return mixed
- */
- public function getAttributeValue($key)
- {
- $value = null;
- if (\array_key_exists($key, $this->attributes)) {
- $value = $this->attributes[$key];
- }
- return $value;
- }
-
- /**
- * @param string $key
- * @return mixed
- */
- public function __get($key) {
- return $this->getAttributeValue($key);
- }
-
- /**
- * @param string $key
- * @param mixed $value
- * @return void
- */
- public function __set($key, $value)
- {
- $this->setAttributeValue($key, $value);
- }
-
- /**
- * @param string $key
- * @return boolean
- */
- public function __isset($key)
- {
- return isset($this->attributes[$key]);
- }
-
- /////////////////////////
- // NODE ACCESS METHODS //
- /////////////////////////
-
- /**
- * @param \freebase\Node $node
- * @return \freebase\Node
- */
- public function addChild(\freebase\Node $node)
- {
- $node->setParent($this);
- $this->children[$node->getName()] = $node;
- return $this;
- }
-
- /**
- * @return array
- */
- public function getChildren()
- {
- return $this->children;
- }
-
- /**
- * @param string $name
- * @return \freebase\Node
- */
- public function getChildByName($name)
- {
- $node = null;
- if (isset($this->children[$name])) {
- $node = $this->children[$name];
- }
- return $node;
- }
-
- public function getChildByPath($path)
- {
- $nodeList = \explode(".", $path);
- $node = $this;
- foreach ($nodeList as $name) {
- if (null === $node) {
- break;
- }
- $node = $node->getChildByName($name);
- }
- if (null === $node) {
- throw new exception\InvalidPath($path);
- }
- return $node;
- }
-
- /////////////////////////////////
- // IteratorAggregate INTERFACE //
- /////////////////////////////////
-
- public function getIterator()
- {
- return new \ArrayIterator($this->children);
- }
-
-}
View
44 src/classes/freebase/Query.php
@@ -1,44 +0,0 @@
-<?php
-/**
- * @package freebase
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * Object of this class represent a search of freebase
- *
- * @package freebase
- */
-class Query
-{
-
- protected $criteria = array();
-
- public function addField($name, $value = null)
- {
- $this->criteria[$name] = $value;
- return $this;
- }
-
- /**
- * @return array
- */
- public function getCriteria()
- {
- return $this->criteria;
- }
-
- /**
- * @return string
- */
- public function __toJson()
- {
- $query = array(
- 'query' => $this->criteria
- );
-
- return \json_encode($query);
- }
-
-}
View
37 src/classes/freebase/Transport.php
@@ -1,37 +0,0 @@
-<?php
-/**
- * @package
- * @copyright 2010 Tangent Labs
- * @version SVN: $Id$
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase;
-/**
- * Description of Transport
- *
- * @package
- */
-class Transport
-{
-
- private $baseUrl;
-
- /**
- * @param string $baseUrl
- */
- public function __construct($baseUrl)
- {
- if (\substr($baseUrl, -1) !== '/') {
- $baseUrl .= '/';
- }
- $this->baseUrl = $baseUrl;
- }
-
- public function query($uri)
- {
- $url = $this->baseUrl . $uri;
- $json = \file_get_contents($url);
- return Factory::loadFromJson($json);
- }
-
-}
View
18 src/classes/freebase/exception/ApiError.php
@@ -1,18 +0,0 @@
-<?php
-/**
- * @package freebase
- * @subpackage exception
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase\exception;
-/**
- * Description of InvalidJson
- *
- * @package freebase
- * @subpackage exception
- */
-class ApiError extends \freebase\Exception
-{
-
-}
View
24 src/classes/freebase/exception/InvalidJson.php
@@ -1,24 +0,0 @@
-<?php
-/**
- * @package freebase
- * @subpackage exception
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase\exception;
-/**
- * Description of InvalidJson
- *
- * @package freebase
- * @subpackage exception
- */
-class InvalidJson extends \freebase\Exception
-{
-
- const MESSAGE = "JSON response could not be parsed";
-
- public function __construct($json)
- {
- parent::__construct(self::MESSAGE . $json);
- }
-}
View
26 src/classes/freebase/exception/InvalidPath.php
@@ -1,26 +0,0 @@
-<?php
-/**
- * @package freebase
- * @subpackage exception
- * @copyright 2011 Tangent One
- * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
- */
-namespace freebase\exception;
-/**
- * @package freebase
- * @subpackage exception
- */
-class InvalidPath extends \freebase\Exception
-{
-
- const TEMPLATE = "The path %s could not be found in this document";
-
- /**
- * @param string $path
- */
- public function __construct($path)
- {
- parent::__construct(\sprintf(self::TEMPLATE, $path));
- }
-
-}

0 comments on commit 8751dab

Please sign in to comment.
Something went wrong with that request. Please try again.