Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created November 2, 2011 13:25
Show Gist options
  • Save objectivehtml/1333617 to your computer and use it in GitHub Desktop.
Save objectivehtml/1333617 to your computer and use it in GitHub Desktop.
New Channel Data API
Overview
--------
The idea here is to have a single "library" (in this case it's actually a driver)
that loads an API from _other_ add-ons.
For instance, say you wanted you application to interact with Google Maps for
ExpressionEngine, but you want to do it in a nice easy to use fashion without loading
a whole bunch of dependencies and reverse engineer someone's code. With an effort to
eliminate duplicate code and make life easier for all developers, we can now use
Channel Data to load a developer API for another add-on (in this examples, Google Maps
for ExpressionEngine) and start sharing resources.
This is much different than just loading an app package and using another their library. This
is actually using the API as the developer intended (and wrote it). They will be able to extend
their own classes and provide other developers safe (and intended) ways to integrate features.
It will be up to the developer to add API support, but at least a unified framework is now underway.
These are just some thoughts and the first working examples, I need some more feedback. Bottom line,
if all of the developers used the same framework to create a legitimate API, all of our products would improve.
Thanks to @wesrice the idea and new direction. I would love to bring on as many contributors as
possible. If you have any ideas or ways you think this library can improve, please do so. I
encourage constructive criticism, as it criticism makes better products.
<?php
class Sample_addon {
function __construct()
{
$this->EE =& get_instance();
}
function some_method()
{
$this->EE->load->driver('channel_data');
$this->EE->channel_data->api->load('gmap');
$data = $this->EE->channel_data->gmap->geocode('Austin, Texas');
}
}
// End of File
// ./system/expressionengine/third_party/sample_addon/mod.sample_addon.php
?>
<?php
/* Example API file, in this case the Gmap API */
class Gmap_api extends Base_API {
public function geocode($query, $limit = FALSE, $offset = 0)
{
$this->EE->load->library('Google_maps');
return $this->EE->google_maps->geocode($query, $limit, $offset);
}
}
// End of File
// ./system/expressionengine/third_party/api.gmap.php
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment