-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from samwilson/apis
Add remaining API classes
- Loading branch information
Showing
41 changed files
with
5,646 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ | |
/examples/config.php | ||
/examples/cache/ | ||
/tests/config.php | ||
/config.php | ||
/cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Samwilson\PhpFlickr\PhpFlickr; | ||
use Stash\Driver\FileSystem; | ||
use Stash\Pool as StashPool; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// Set up phpFlickr. | ||
$config = require_once __DIR__ . '/../config.php'; | ||
$phpflickr = new PhpFlickr($config['consumer_key'], $config['consumer_secret']); | ||
$driver = new FileSystem([ 'path' => __DIR__ . '/../cache' ]); | ||
$pool = new StashPool($driver); | ||
$phpflickr->setCache($pool); | ||
|
||
// Get method info. | ||
$methodsResponse = $phpflickr->reflection()->getMethods(); | ||
$methods = []; | ||
foreach ($methodsResponse as $method) { | ||
$methodParts = explode('.', $method); | ||
$methodGroup = array_slice($methodParts, 1, count($methodParts) - 2); | ||
$methodGroupName = implode('', array_map('ucfirst', $methodGroup)) . 'Api'; | ||
$classname = '\\Samwilson\\PhpFlickr\\' . $methodGroupName; | ||
$methods[$methodGroupName]['classname'] = $classname; | ||
$methods[$methodGroupName]['methods'][$method] = $methodParts[count($methodParts) - 1]; | ||
} | ||
|
||
// Create PHP code. | ||
foreach ($methods as $methodGroupName => $methodInfo) { | ||
$classname = basename(str_replace('\\', '/', $methodInfo['classname'])); | ||
$php = "<?php\n\n" | ||
. "namespace Samwilson\PhpFlickr;\n\n" | ||
. "class " . $classname . " extends ApiMethodGroup\n{\n\n"; | ||
foreach ($methodInfo['methods'] as $method => $shortMethod) { | ||
$details = $phpflickr->reflection()->getMethodInfo($method); | ||
$desc = wordwrap($details['method']['description'], 80, "\n * "); | ||
$auth = $details['method']['needslogin'] ? 'requires' : 'does not require'; | ||
$params = []; | ||
$sigs = []; | ||
$paramNames = []; | ||
foreach ($details['arguments']['argument'] as $arg) { | ||
if ($arg['name'] === 'api_key') { | ||
continue; | ||
} | ||
$nameParts = explode('_', $arg['name']); | ||
$phpName = $nameParts[0] . implode('', array_map('ucfirst', array_slice($nameParts, 1))); | ||
$paramDesc = str_replace("\n", ' ', $arg['_content']); | ||
$params[] = wordwrap('@param string $' . $phpName . ' ' . $paramDesc, 80, "\n * "); | ||
$sigs[] = '$' . $phpName . (isset($arg['optional']) && $arg['optional'] ? ' = null' : ''); | ||
$paramNames[$arg['name']] = "'" . $arg['name'] . "' => \$$phpName"; | ||
} | ||
$url = 'https://www.flickr.com/services/api/' . $method . '.html'; | ||
$methodPhp = " /**\n * $desc\n" | ||
. " *\n" | ||
. " * This method $auth authentication.\n" | ||
. " *\n" | ||
. " * @link $url\n" | ||
. " * " . implode("\n * ", $params) . "\n" | ||
. " * @return\n" | ||
. " */\n" | ||
. " public function " . $shortMethod . "(" . implode(', ', $sigs) . ")\n {\n"; | ||
if (count($params) > 0) { | ||
$methodPhp .= " \$params = [\n" | ||
. " " . implode(",\n ", $paramNames) . "\n" | ||
. " ];\n" | ||
. " return \$this->flickr->request('" . $method . "', \$params);\n"; | ||
} else { | ||
$methodPhp .= " return \$this->flickr->request('" . $method . "');\n"; | ||
} | ||
$methodPhp .= " }\n\n"; | ||
try { | ||
$reflection = new ReflectionClass($methodInfo['classname']); | ||
$reflection->getMethod($shortMethod); | ||
} catch (ReflectionException $exception) { | ||
if ($shortMethod !== 'echo') { | ||
// Don't flag echo() as missing, as it's called "testEcho" in the code. | ||
echo "Not found: " . $methodInfo['classname'] . '::' . $shortMethod . "()\n\n$methodPhp"; | ||
} | ||
} | ||
$php .= $methodPhp; | ||
} | ||
$php .= "}\n"; | ||
|
||
$filename = __DIR__ . '/../src/' . $classname . '.php'; | ||
echo "Writing $filename\n"; | ||
file_put_contents($filename, $php); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Samwilson\PhpFlickr; | ||
|
||
class ActivityApi extends ApiMethodGroup | ||
{ | ||
|
||
/** | ||
* Returns a list of recent activity on photos commented on by the calling user. | ||
* <b>Do not poll this method more than once an hour</b>. | ||
* | ||
* This method requires authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.activity.userComments.html | ||
* @param string $perPage Number of items to return per page. If this argument is | ||
* omitted, it defaults to 10. The maximum allowed value is 50. | ||
* @param string $page The page of results to return. If this argument is omitted, | ||
* it defaults to 1. | ||
* @return | ||
*/ | ||
public function userComments($perPage = null, $page = null) | ||
{ | ||
$params = [ | ||
'per_page' => $perPage, | ||
'page' => $page | ||
]; | ||
return $this->flickr->request('flickr.activity.userComments', $params); | ||
} | ||
|
||
/** | ||
* Returns a list of recent activity on photos belonging to the calling user. <b>Do | ||
* not poll this method more than once an hour</b>. | ||
* | ||
* This method requires authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.activity.userPhotos.html | ||
* @param string $timeframe The timeframe in which to return updates for. This can | ||
* be specified in days (<code>'2d'</code>) or hours (<code>'4h'</code>). The | ||
* default behavoir is to return changes since the beginning of the previous user | ||
* session. | ||
* @param string $perPage Number of items to return per page. If this argument is | ||
* omitted, it defaults to 10. The maximum allowed value is 50. | ||
* @param string $page The page of results to return. If this argument is omitted, | ||
* it defaults to 1. | ||
* @return | ||
*/ | ||
public function userPhotos($timeframe = null, $perPage = null, $page = null) | ||
{ | ||
$params = [ | ||
'timeframe' => $timeframe, | ||
'per_page' => $perPage, | ||
'page' => $page | ||
]; | ||
return $this->flickr->request('flickr.activity.userPhotos', $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Samwilson\PhpFlickr; | ||
|
||
class BlogsApi extends ApiMethodGroup | ||
{ | ||
|
||
/** | ||
* Get a list of configured blogs for the calling user. | ||
* | ||
* This method requires authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.blogs.getList.html | ||
* @param string $service Optionally only return blogs for a given service id. You | ||
* can get a list of from <a | ||
* href="/services/api/flickr.blogs.getServices.html">flickr.blogs.getServices()</a>. | ||
* @return | ||
*/ | ||
public function getList($service = null) | ||
{ | ||
$params = [ | ||
'service' => $service | ||
]; | ||
return $this->flickr->request('flickr.blogs.getList', $params); | ||
} | ||
|
||
/** | ||
* Return a list of Flickr supported blogging services | ||
* | ||
* This method does not require authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.blogs.getServices.html | ||
* | ||
* @return | ||
*/ | ||
public function getServices() | ||
{ | ||
return $this->flickr->request('flickr.blogs.getServices'); | ||
} | ||
|
||
/** | ||
* This method requires authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.blogs.postPhoto.html | ||
* @param string $photoId The id of the photo to blog | ||
* @param string $title The blog post title | ||
* @param string $description The blog post body | ||
* @param string $blogPassword The password for the blog (used when the blog does | ||
* not have a stored password). | ||
* @param string $service A Flickr supported blogging service. Instead of passing | ||
* a blog id you can pass a service id and we'll post to the first blog of that | ||
* service we find. | ||
* @param string $blogId The id of the blog to post to. | ||
* @return | ||
*/ | ||
public function postPhoto($photoId, $title, $description, $blogPassword = null, $service = null, $blogId = null) | ||
{ | ||
$params = [ | ||
'blog_id' => $blogId, | ||
'photo_id' => $photoId, | ||
'title' => $title, | ||
'description' => $description, | ||
'blog_password' => $blogPassword, | ||
'service' => $service | ||
]; | ||
return $this->flickr->request('flickr.blogs.postPhoto', $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Samwilson\PhpFlickr; | ||
|
||
class CamerasApi extends ApiMethodGroup | ||
{ | ||
|
||
/** | ||
* Retrieve all the models for a given camera brand. | ||
* | ||
* This method does not require authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.cameras.getBrandModels.html | ||
* @param string $brand The ID of the requested brand (as returned from | ||
* flickr.cameras.getBrands). | ||
* @return | ||
*/ | ||
public function getBrandModels($brand) | ||
{ | ||
$params = [ | ||
'brand' => $brand | ||
]; | ||
return $this->flickr->request('flickr.cameras.getBrandModels', $params); | ||
} | ||
|
||
/** | ||
* Returns all the brands of cameras that Flickr knows about. | ||
* | ||
* This method does not require authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.cameras.getBrands.html | ||
* | ||
* @return | ||
*/ | ||
public function getBrands() | ||
{ | ||
return $this->flickr->request('flickr.cameras.getBrands'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Samwilson\PhpFlickr; | ||
|
||
class CollectionsApi extends ApiMethodGroup | ||
{ | ||
|
||
/** | ||
* Returns information for a single collection. Currently can only be called by | ||
* the collection owner, this may change. | ||
* | ||
* This method requires authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.collections.getInfo.html | ||
* @param string $collectionId The ID of the collection to fetch information for. | ||
* @return | ||
*/ | ||
public function getInfo($collectionId) | ||
{ | ||
$params = [ | ||
'collection_id' => $collectionId | ||
]; | ||
return $this->flickr->request('flickr.collections.getInfo', $params); | ||
} | ||
|
||
/** | ||
* Returns a tree (or sub tree) of collections belonging to a given user. | ||
* | ||
* This method does not require authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.collections.getTree.html | ||
* @param string $collectionId The ID of the collection to fetch a tree for, or | ||
* zero to fetch the root collection. Defaults to zero. | ||
* @param string $userId The ID of the account to fetch the collection tree for. | ||
* Deafults to the calling user. | ||
* @return | ||
*/ | ||
public function getTree($collectionId = null, $userId = null) | ||
{ | ||
$params = [ | ||
'collection_id' => $collectionId, | ||
'user_id' => $userId | ||
]; | ||
return $this->flickr->request('flickr.collections.getTree', $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Samwilson\PhpFlickr; | ||
|
||
class CommonsApi extends ApiMethodGroup | ||
{ | ||
|
||
/** | ||
* Retrieves a list of the current Commons institutions. | ||
* | ||
* This method does not require authentication. | ||
* | ||
* @link https://www.flickr.com/services/api/flickr.commons.getInstitutions.html | ||
* | ||
* @return | ||
*/ | ||
public function getInstitutions() | ||
{ | ||
return $this->flickr->request('flickr.commons.getInstitutions'); | ||
} | ||
} |
Oops, something went wrong.