Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sergeylukin/rackspace-cdn-gateway
Just a nicely interfaced gateway for Rackspace CDN SDK
https://github.com/sergeylukin/rackspace-cdn-gateway
Last synced: 27 days ago
JSON representation
Just a nicely interfaced gateway for Rackspace CDN SDK
- Host: GitHub
- URL: https://github.com/sergeylukin/rackspace-cdn-gateway
- Owner: sergeylukin
- Created: 2013-09-11T16:07:28.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-11T16:40:10.000Z (over 11 years ago)
- Last Synced: 2024-04-08T18:22:04.223Z (9 months ago)
- Language: PHP
- Size: 121 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Rackspace-cdn-gateway in PHP
============================Just a nicely interfaced gateway for
[Rackspace CDN SDK](https://github.com/rackerlabs/php-cloudfiles) (which is
deprecated already) written in PHP.It may be unstable so use on your own risk.
Tested on PHP 5.2.x
Usage
-----Assuming `$CDN` is the instance object that was factored somewhere:
```php
try {
// Create/Update blob
$CDN->blob('lorem.js')->set('contents', "console.log('hello world!')")->save();// Delete blob
$CDN->blob('lorem.js')->delete();// Check if exists
if( $CDN->blob('lorem.js')->isExists() ) {
echo 'Blob exists';
} else {
echo 'Blob does not exist';
}// List all blobs
$blobs = $CDN->blobs();
foreach( $blobs as $blob ) {
echo "Name: " . $blob->name . "\n";
echo "Type: " . $blob->content_type . "\n";
echo "URI: " . $blob->uri . "\n";
echo "SSL URI: " . $blob->ssl_uri . "\n";
echo "Contents: " . $blob->contents . "\n";
}// Get Attribute directly by blob name
echo "Name: " . $CDN->blob('lorem.js')->name;
echo "URI: " . $CDN->blob('lorem.js')->uri;
echo "SSL URI: " . $CDN->blob('lorem.js')->ssl_uri;
// etc.// Just container info, not really useful imho but it's there
print_r( $CDN->info() );// Truncate container
foreach( $CDN->blobs as $blob ) $blob->delete();} catch( Exception $e ) {
echo 'Following error occured: ' . $e->getMessage();
}
```Instantiation
-------------Note that this piece of code is probably a good candidate for being factored
in a Factory to hide the complexity of creating an instance.
[Read more](http://en.wikipedia.org/wiki/Factory_method_pattern) on
factory design pattern if not sure about it.```php
require 'path/to/rackspace/cdn/cloudfiles.php';
$RackspaceAuth = new CF_Authentication('username', 'apikey');
$RackspaceAuth->authenticate();
$RackspaceConnection = new CF_Connection($RackspaceAuth);
$CDN = new Gateways_Rackspace($RackspaceConnection);
$CDN->setConfig( array( /* ..configuration.. */ );
$CDN->container = 'name-of-container';
```