| 1 |
<?php |
| 2 |
/* |
| 3 |
* Copyright (c) 2010 Google Inc. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 |
* use this file except in compliance with the License. You may obtain a copy of |
| 7 |
* the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 |
* License for the specific language governing permissions and limitations under |
| 15 |
* the License. |
| 16 |
*/ |
| 17 |
|
| 18 |
require_once 'service/apiModel.php'; |
| 19 |
require_once 'service/apiService.php'; |
| 20 |
require_once 'service/apiServiceRequest.php'; |
| 21 |
|
| 22 |
|
| 23 |
/** |
| 24 |
* The "text" collection of methods. |
| 25 |
* Typical usage is: |
| 26 |
* <code> |
| 27 |
* $freebaseService = new apiFreebaseService(...); |
| 28 |
* $text = $freebaseService->text; |
| 29 |
* </code> |
| 30 |
*/ |
| 31 |
class TextServiceResource extends apiServiceResource { |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Returns blob attached to node at specified id as HTML (text.get) |
| 36 |
* |
| 37 |
* @param string $id The id of the item that you want data about |
| 38 |
* @param array $optParams Optional parameters. Valid optional parameters are listed below. |
| 39 |
* |
| 40 |
* @opt_param string maxlength The max number of characters to return. Valid only for 'plain' format. |
| 41 |
* @opt_param string format Sanitizing transformation. |
| 42 |
* @return ContentserviceGet |
| 43 |
*/ |
| 44 |
public function get($id, $optParams = array()) { |
| 45 |
$params = array('id' => $id); |
| 46 |
$params = array_merge($params, $optParams); |
| 47 |
$data = $this->__call('get', array($params)); |
| 48 |
if ($this->useObjects()) { |
| 49 |
return new ContentserviceGet($data); |
| 50 |
} else { |
| 51 |
return $data; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* The "mqlread" collection of methods. |
| 59 |
* Typical usage is: |
| 60 |
* <code> |
| 61 |
* $freebaseService = new apiFreebaseService(...); |
| 62 |
* $mqlread = $freebaseService->mqlread; |
| 63 |
* </code> |
| 64 |
*/ |
| 65 |
class MqlreadServiceResource extends apiServiceResource { |
| 66 |
/** |
| 67 |
* Performs MQL Queries. (mqlread.mqlread) |
| 68 |
* |
| 69 |
* @param string $query An envelope containing a single MQL query. |
| 70 |
* @param array $optParams Optional parameters. Valid optional parameters are listed below. |
| 71 |
* |
| 72 |
* @opt_param string lang The language of the results - an id of a /type/lang object. |
| 73 |
* @opt_param bool html_escape Whether or not to escape entities. |
| 74 |
* @opt_param string indent How many spaces to indent the json. |
| 75 |
* @opt_param string uniqueness_failure How MQL responds to uniqueness failures. |
| 76 |
* @opt_param string dateline The dateline that you get in a mqlwrite response to ensure consistent results. |
| 77 |
* @opt_param string cursor The mql cursor. |
| 78 |
* @opt_param string callback JS method name for JSONP callbacks. |
| 79 |
* @opt_param bool cost Show the costs or not. |
| 80 |
* @opt_param string as_of_time Run the query as it would've been run at the specified point in time. |
| 81 |
*/ |
| 82 |
public function mqlread($query, $optParams = array()) { |
| 83 |
$params = array('query' => $query); |
| 84 |
$params = array_merge($params, $optParams); |
| 85 |
$data = $this->__call('mqlread', array($params)); |
| 86 |
return $data; |
| 87 |
} |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* The "image" collection of methods. |
| 93 |
* Typical usage is: |
| 94 |
* <code> |
| 95 |
* $freebaseService = new apiFreebaseService(...); |
| 96 |
* $image = $freebaseService->image; |
| 97 |
* </code> |
| 98 |
*/ |
| 99 |
class ImageServiceResource extends apiServiceResource { |
| 100 |
/** |
| 101 |
* Returns the scaled/cropped image attached to a freebase node. (image.image) |
| 102 |
* |
| 103 |
* @param string $id Freebase entity or content id, mid, or guid. |
| 104 |
* @param array $optParams Optional parameters. Valid optional parameters are listed below. |
| 105 |
* |
| 106 |
* @opt_param string maxwidth Maximum width in pixels for resulting image. |
| 107 |
* @opt_param string maxheight Maximum height in pixels for resulting image. |
| 108 |
* @opt_param string fallbackid Use the image associated with this secondary id if no image is associated with the primary id. |
| 109 |
* @opt_param bool pad A boolean specifying whether the resulting image should be padded up to the requested dimensions. |
| 110 |
* @opt_param string mode Method used to scale or crop image. |
| 111 |
*/ |
| 112 |
public function image($id, $optParams = array()) { |
| 113 |
$params = array('id' => $id); |
| 114 |
$params = array_merge($params, $optParams); |
| 115 |
$data = $this->__call('image', array($params)); |
| 116 |
return $data; |
| 117 |
} |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
/** |
| 123 |
* Service definition for Freebase (v1). |
| 124 |
* |
| 125 |
* <p> |
| 126 |
* Lets you access the Freebase repository of open data. |
| 127 |
* </p> |
| 128 |
* |
| 129 |
* <p> |
| 130 |
* For more information about this service, see the |
| 131 |
* <a href="http://wiki.freebase.com/wiki/New_Freebase_API" target="_blank">API Documentation</a> |
| 132 |
* </p> |
| 133 |
* |
| 134 |
* @author Google, Inc. |
| 135 |
*/ |
| 136 |
class apiFreebaseService extends apiService { |
| 137 |
public $text; |
| 138 |
/** |
| 139 |
* Constructs the internal representation of the Freebase service. |
| 140 |
* |
| 141 |
* @param apiClient apiClient |
| 142 |
*/ |
| 143 |
public function __construct(apiClient $apiClient) { |
| 144 |
$this->rpcPath = '/rpc'; |
| 145 |
$this->restBasePath = '/freebase/v1/'; |
| 146 |
$this->version = 'v1'; |
| 147 |
$this->serviceName = 'freebase'; |
| 148 |
|
| 149 |
$apiClient->addService($this->serviceName, $this->version); |
| 150 |
$this->text = new TextServiceResource($this, $this->serviceName, 'text', json_decode('{"methods": {"get": {"parameters": {"format": {"default": "plain", "enum": ["html", "plain", "raw"], "location": "query", "type": "string"}, "id": {"repeated": true, "required": true, "type": "string", "location": "path"}, "maxlength": {"format": "uint32", "type": "integer", "location": "query"}}, "id": "freebase.text.get", "httpMethod": "GET", "path": "text{/id*}", "response": {"$ref": "ContentserviceGet"}}}}', true)); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
class ContentserviceGet extends apiModel { |
| 155 |
public $result; |
| 156 |
public function setResult($result) { |
| 157 |
$this->result = $result; |
| 158 |
} |
| 159 |
public function getResult() { |
| 160 |
return $this->result; |
| 161 |
} |
| 162 |
} |
| 163 |
|