Permalink
Browse files

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

… stuff
  • Loading branch information...
a-musing-moose committed Feb 25, 2011
1 parent 2ce1e74 commit 8751dab930245977befb4cccc6f044b8b4ff3b09
View
Binary file not shown.
View
Binary file not shown.
@@ -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';
-
-}
@@ -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;
- }
-
-}
@@ -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';
-}
@@ -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
-{
-
-}
@@ -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;
- }
-
-}
@@ -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;
- }
-
-}
Oops, something went wrong.

0 comments on commit 8751dab

Please sign in to comment.