Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 8957ebfdbba78d5c816438b6659327bf0ff42f04 @dancannon committed Jul 7, 2011
@@ -0,0 +1 @@
+.idea
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2011 by Daniel Cannon
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
1 README
@@ -0,0 +1 @@
+This file was created by JetBrains PhpStorm 2.1.1 for binding GitHub repository
No changes.
@@ -0,0 +1,14 @@
+<?php
+namespace WowApi\Api;
+
+use WowApi\Request\RequestInterface;
+
+abstract class Api implements ApiInterface
+{
+ protected $request;
+
+ public function __construct(RequestInterface $request)
+ {
+ $this->request = $request;
+ }
+}
@@ -0,0 +1,9 @@
+<?php
+namespace WowApi\Api;
+
+use \WowApi\Request\RequestInterface;
+
+interface ApiInterface
+{
+ function __construct(RequestInterface $request);
+}
@@ -0,0 +1,14 @@
+<?php
+namespace WowApi\Api;
+
+use WowApi\Utilities;
+
+class Character extends Api
+{
+ public function getCharacter($server, $character, array $fields=array())
+ {
+ $server = Utilities::urlencode($server);
+ $character = Utilities::urlencode($character);
+ $this->request->get("character/$server/$character", array('fields' => implode(',', $fields)));
+ }
+}
@@ -0,0 +1,10 @@
+<?php
+namespace WowApi\Api;
+
+class Classes extends Api
+{
+ public function getClasses()
+ {
+ return $this->request->get('data/character/classes');
+ }
+}
@@ -0,0 +1,14 @@
+<?php
+namespace WowApi\Api;
+
+use WowApi\Utilities;
+
+class Guild extends Api
+{
+ public function getGuild($server, $guild, array $fields=array())
+ {
+ $server = Utilities::urlencode($server);
+ $guild = Utilities::urlencode($guild);
+ $this->request->get("/guild/$server/$guild", array('fields' => implode(',', $fields)));
+ }
+}
@@ -0,0 +1,10 @@
+<?php
+namespace WowApi\Api;
+
+class GuildPerks extends Api
+{
+ public function getPerks()
+ {
+ return $this->request->get('data/guild/perks');
+ }
+}
@@ -0,0 +1,10 @@
+<?php
+namespace WowApi\Api;
+
+class GuildRewards extends Api
+{
+ public function getRewards()
+ {
+ return $this->request->get('data/guild/rewards');
+ }
+}
@@ -0,0 +1,13 @@
+<?php
+namespace WowApi\Api;
+
+use WowApi\Utilities;
+
+class Items extends Api
+{
+ public function getItem($itemId)
+ {
+ $itemId = Utilities::urlencode($itemId);
+ return $this->request->get("data/item/$itemId");
+ }
+}
@@ -0,0 +1,10 @@
+<?php
+namespace WowApi\Api;
+
+class Races extends Api
+{
+ public function getRaces()
+ {
+ return $this->request->get('data/character/races');
+ }
+}
@@ -0,0 +1,26 @@
+<?php
+namespace WowApi\Api;
+
+use WowApi\Exception\ApiException;
+
+class Realm extends Api
+{
+ public function getRealm($realm) {
+ return $this->getRealms(array($realm));
+ }
+
+
+ /**
+ * Get status results for specified realm(s).
+ *
+ * @param array $realms String or array of realm(s)
+ * @return mixed
+ */
+ public function getRealms(array $realms = array()) {
+ if (empty($realms)) {
+ return $this->request->get('realm/status');
+ } else {
+ return $this->request->get('realm/status', array('realms' => implode(',', $realms)));
+ }
+ }
+}
@@ -0,0 +1,13 @@
+<?php
+namespace WowApi\Cache;
+
+class ApcCache extends Cache
+{
+ public function write($key, $data) {
+ apc_store($key, $data);
+ }
+
+ public function read($key) {
+ return apc_fetch($key);
+ }
+}
@@ -0,0 +1,24 @@
+<?php
+namespace WowApi\Cache;
+
+abstract class Cache implements CacheInterface
+{
+ public function getCachedResponse($path, $parameters)
+ {
+ $return = array();
+ $return['last-modified'] = $this->read("wowapi:last-modified" . $this->getHash($path, $parameters));
+ $return['response'] = $this->read("wowapi:response" . $this->getHash($path, $parameters));
+ return $return;
+ }
+
+ public function setCachedResponse($path, $parameters, $response, $date)
+ {
+ $this->write("wowapi:last-modified" . $this->getHash($path, $parameters), $date);
+ $this->write("wowapi:response" . $this->getHash($path, $parameters), $response);
+ }
+
+ protected function getHash($path, $parameters)
+ {
+ return md5($path . serialize($parameters));
+ }
+}
@@ -0,0 +1,10 @@
+<?php
+namespace WowApi\Cache;
+
+interface CacheInterface
+{
+ function write($key, $data);
+ function read($key);
+ function getCachedResponse($path, $parameters);
+ function setCachedResponse($path, $parameters, $response, $date);
+}
Oops, something went wrong.

0 comments on commit 8957ebf

Please sign in to comment.