/** * Verify the Facebook credentials. * * @throws Kohana_Exception * @param string the service name * @return boolean */ public function verify($service = MMI_API::SERVICE_FACEBOOK) { $access_token = NULL; if (!array_key_exists('fragment', $_GET)) { $this->_convert_fragment_to_parameter(); } else { $fragment = urldecode(Security::xss_clean($_GET['fragment'])); parse_str($fragment, $parms); $access_token = Arr::get($parms, 'access_token'); unset($parms); } // Ensure the access token is set if (empty($access_token)) { MMI_Log::log_error(__METHOD__, __LINE__, 'Access token parameter missing'); throw new Kohana_Exception('Access token parameter missing in :method.', array(':method' => __METHOD__)); } // Load existing data from the database $auth_config = $this->_auth_config; $username = Arr::get($auth_config, 'username'); $model; if (!empty($username)) { $model = Model_MMI_API_Tokens::select_by_service_and_username($service, $username, FALSE); } else { $consumer_key = Arr::get($auth_config, 'api_key'); $model = Model_MMI_API_Tokens::select_by_service_and_consumer_key($service, $consumer_key, FALSE); } $success = FALSE; $previously_verified = FALSE; if ($model->loaded()) { // Check if the credentials were previously verified $previously_verified = $model->verified; $success = $previously_verified; } if (!$previously_verified) { // Create an access token $token = new OAuthToken($access_token, $service . '-' . time()); // Update the token credentials in the database $svc = MMI_API::factory($service); if (isset($token) and $svc->is_valid_token($token)) { $encrypt = Encrypt::instance(); $model->service = $service; $model->consumer_key = 'consumer-' . $service; $model->consumer_secret = $encrypt->encode($service . '-' . time()); $model->token_key = $token->key; $model->token_secret = $encrypt->encode($token->secret); unset($encrypt); $model->verified = 1; $model->verification_code = $service . '-' . time(); $model->username = $username; if (array_key_exists('expires_in', $_GET)) { $model->attributes = array('expires_in' => urldecode(Security::xss_clean($_GET['expires_in']))); } $success = MMI_Jelly::save($model, $errors); if (!$success and $this->_debug) { MMI_Debug::dead($errors); } } } return $success; }
/** * Initialize debugging (using the Request instance). * Load the configuration settings. * * @return void */ public function __construct() { $this->_debug = class_exists('MMI_Request') ? MMI_Request::debug() : FALSE; $config = MMI_API::get_config(); $this->_service_config = $config->get($this->_service, array()); $this->_auth_config = Arr::get($this->_service_config, 'auth', array()); }
/** * Verify the Flickr credentials. * * @throws Kohana_Exception * @return boolean */ public function verify() { // Set the service $service = $this->_service; if (empty($service)) { MMI_Log::log_error(__METHOD__, __LINE__, 'Service not set'); throw new Kohana_Exception('Service not set in :method.', array(':method' => __METHOD__)); } // Ensure the frob is set $frob = NULL; if (array_key_exists('frob', $_GET)) { $frob = urldecode(Security::xss_clean($_GET['frob'])); } if (empty($frob)) { MMI_Log::log_error(__METHOD__, __LINE__, 'Frob parameter missing'); throw new Kohana_Exception('Frob parameter missing in :method.', array(':method' => __METHOD__)); } // Load existing data from the database $auth_config = $this->_auth_config; $username = Arr::get($auth_config, 'username'); $model; if (!empty($username)) { $model = Model_MMI_API_Tokens::select_by_service_and_username($service, $username, FALSE); } else { $model = Jelly::factory('MMI_API_Tokens'); } $success = FALSE; if ($model->loaded()) { // Check if the credentials were previously verified $previously_verified = $model->verified; if ($previously_verified) { $success = TRUE; } else { // Create a dummy verification code $verification_code = $service . '-' . time(); } // Do database update if (!$previously_verified) { // Get an access token $svc = MMI_API::factory($service); $token = $svc->get_access_token($verification_code, array('token_key' => $frob, 'token_secret' => $service . '-' . time())); // Update the token credentials in the database if (isset($token) and $svc->is_valid_token($token)) { $model->token_key = $token->key; $model->token_secret = Encrypt::instance()->encode($token->secret); $model->verified = 1; $model->verification_code = $verification_code; if (!empty($token->attributes)) { $model->attributes = $token->attributes; } $success = MMI_Jelly::save($model, $errors); if (!$success and $this->_debug) { MMI_Debug::dead($errors); } } } } return $success; }
/** * Test the Posterous API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_POSTEROUS); // $response = $svc->get('readposts'); $requests = array('getsites' => array('url' => 'getsites'), 'gettags' => array('url' => 'gettags'), 'readposts' => array('url' => 'readposts')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Readernaut API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_READERNAUT); // $response = $svc->get('nathan/books/'); $requests = array('nathan' => array('url' => 'nathan/books/'), 'memakeit' => array('url' => 'memakeit/books/')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Scribd API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_SCRIBD); // $response = $svc->get(NULL, array('method' => 'docs.getList')); $requests = array('user documents' => array('parms' => array('method' => 'docs.getList')), 'user collections' => array('parms' => array('method' => 'docs.getCollections')), 'categories' => array('parms' => array('method' => 'docs.getCategories')), 'featured' => array('parms' => array('method' => 'docs.featured')), 'auto signin url' => array('parms' => array('method' => 'user.getAutoSigninUrl', 'next_url' => 'http://www.memakeit.com/'))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Bitly API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_BITLY); // $response = $svc->get('shorten', array('longUrl' => 'http://www.memakeit.com/')); $requests = array('memakeit' => array('url' => 'shorten', 'parms' => array('longUrl' => 'http://www.memakeit.com/')), 'google' => array('url' => 'shorten', 'parms' => array('longUrl' => 'http://www.google.com/'))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Mixx API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'mixx.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_MIXX); // $response = $svc->get('users/show', array('user_key' => $username)); $requests = array('profile' => array('url' => 'users/show', 'parms' => array('user_key' => $username)), 'real-life-size-bus-transformer' => array('url' => 'thingies/show', 'parms' => array('url' => 'http://www.atcrux.com/2010/03/11/real-life-size-bus-transformer/', 'comments' => 1, 'tags' => 1))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the SlideShare API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'slideshare.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_SLIDESHARE); // $response = $svc->get('get_slideshows_by_user', array('username_for' => $username, 'detailed' => '1')); $requests = array('user slideshows' => array('url' => 'get_slideshows_by_user', 'parms' => array('username_for' => $username, 'detailed' => '1')), 'user groups' => array('url' => 'get_user_groups', 'parms' => array('username_for' => $username)), 'user contacts' => array('url' => 'get_user_contacts', 'parms' => array('username_for' => $username)), 'get slideshow' => array('url' => 'get_slideshow', 'parms' => array('slideshow_url' => 'http://www.slideshare.net/vortexau/improving-php-application-performance-with-apc-presentation', 'detailed' => '1'))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Configure the request parameters as specified in the configuration file. * When processing additions, if a parameter value exists, it will not be * overwritten. * * @param array an associative array of request parameters * @return array */ protected function _configure_parameters($parms) { $parms = parent::_configure_parameters($parms); $name = 'format'; $temp = Arr::get($parms, $name); if (empty($temp)) { $parms[$name] = $this->_format; } return $parms; }
/** * Test the GitHub API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'github.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_GITHUB); // $response = $svc->get("user/show/{$username}"); $requests = array($username => array('url' => "user/show/{$username}"), 'shadowhand' => array('url' => 'user/show/shadowhand')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Gowalla API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'gowalla.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_GOWALLA); // $response = $svc->get("users/{$username}"); $requests = array('profile' => array('url' => "users/{$username}"), 'stamps' => array('url' => "users/{$username}/stamps"), 'top spots' => array('url' => "users/{$username}/top_spots")); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the YouTube API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_YOUTUBE); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('users/default', array('v' => 2)); $requests = array('user' => array('url' => 'users/default'), 'subscriptions' => array('url' => 'users/default/subscriptions')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Foursquare API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_FOURSQUARE); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('user'); $requests = array('user' => array('url' => 'user'), 'friends' => array('url' => 'friends'), 'checkins' => array('url' => 'checkins'), 'test' => array('url' => 'test')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the SoundCloud API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_SOUNDCLOUD); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('me'); $requests = array('profile' => array('url' => 'me'), 'tracks' => array('url' => 'me/tracks'), 'following' => array('url' => 'me/followings'), 'followers' => array('url' => 'me/followers')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Twitter API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_TWITTER); if (!$svc->is_valid_token(NULL, FALSE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('statuses/user_timeline', array('since_id' => '15635444694')); $requests = array('user_timeline' => array('url' => 'statuses/user_timeline'), 'retweeted_by_me' => array('url' => 'statuses/retweeted_by_me')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Reddit API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'reddit.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_REDDIT); $svc->login(); // $response = $svc->get('api/info', array('url' => 'http://www.1stwebdesigner.com/tutorials/create-stay-on-top-menu-css3-jquery/')); $requests = array('user about' => array('url' => "user/{$username}/about"), 'clear vote' => array('method' => MMI_HTTP::METHOD_POST, 'url' => 'api/vote', 'parms' => array('api_type' => 'json', 'dir' => '0', 'id' => 't3_ckvqi', 'r' => 'web_design'))); $response = $svc->mexec($requests); $this->_set_response($response, $svc->service()); }
/** * Test the LinkedIn API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_LINKEDIN); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('~:(id,first-name,last-name,location,current-status,current-status-timestamp,num-recommenders,connections)'); $requests = array('profile' => array('url' => '~:(id,first-name,last-name,location,current-status,current-status-timestamp,num-recommenders,connections)'), 'current-status' => array('url' => '~/current-status'), 'network' => array('url' => '~/network')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Delicious API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_DELICIOUS); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('posts/recent'); $requests = array('posts/recent' => array('url' => 'posts/recent'), 'posts/dates' => array('url' => 'posts/dates')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Facebook API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_FACEBOOK); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('me'); $requests = array('me' => array('url' => 'me'), 'friends' => array('url' => 'me/friends'), 'events' => array('url' => 'me/events'), 'photos' => array('url' => 'me/photos'), 'videos' => array('url' => 'me/videos'), 'home' => array('url' => 'me/home')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Vimeo API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_VIMEO); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('', array('method' => 'vimeo.people.getInfo')); $requests = array('profile' => array('parms' => array('method' => 'vimeo.people.getInfo')), 'user did' => array('parms' => array('method' => 'vimeo.activity.userDid')), 'videos uploaded' => array('parms' => array('method' => 'vimeo.videos.getUploaded')), 'videos liked' => array('parms' => array('method' => 'vimeo.videos.getLikes'))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the GoogleBuzz API. * * @return void */ public function action_index() { $svc = MMI_API::factory(MMI_API::SERVICE_GOOGLEBUZZ); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('people/@me/@self'); $requests = array('profile' => array('url' => 'people/@me/@self'), 'streams' => array('url' => 'activities/@me/@self'), 'followers' => array('url' => 'people/@me/@groups/@followers'), 'following' => array('url' => 'people/@me/@groups/@following')); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the MySpace API. * * @return void */ public function action_index() { $user_id = '469257560'; $svc = MMI_API::factory(MMI_API::SERVICE_MYSPACE); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get("v1/users/{$user_id}/details"); $requests = array('activities' => array('url' => "v1/users/{$user_id}/activities.atom"), 'friends' => array('url' => "v1/users/{$user_id}/friends"), 'profile' => array('url' => "v1/users/{$user_id}/details"), 'status' => array('url' => "v1/users/{$user_id}/status")); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Tumblr API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $email = 'XXXXXXXXXX'; $password = '******'; $username = Arr::path($config, 'tumblr.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_TUMBLR); // $response = $svc->get('http://memakeit.tumblr.com/api/read'); $requests = array('posts' => array('url' => "http://{$username}.tumblr.com/api/read"), 'pages' => array('url' => "http://{$username}.tumblr.com/api/pages"), 'posts (private)' => array('method' => MMI_HTTP::METHOD_POST, 'url' => "http://{$username}.tumblr.com/api/read", 'parms' => array('email' => $email, 'password' => $password)), 'likes' => array('method' => MMI_HTTP::METHOD_POST, 'url' => 'likes', 'parms' => array('email' => $email, 'password' => $password)), 'settings' => array('method' => MMI_HTTP::METHOD_POST, 'url' => 'authenticate', 'parms' => array('email' => $email, 'password' => $password))); $response = $svc->mexec($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Goodreads API. * * @return void */ public function action_index() { $user_id = '3865951'; $svc = MMI_API::factory(MMI_API::SERVICE_GOODREADS); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get("user/show/{$user_id}"); $requests = array('profile' => array('url' => "user/show/{$user_id}"), 'followers' => array('url' => "user/{$user_id}/followers"), 'following' => array('url' => "user/{$user_id}/following"), 'owned books' => array('url' => 'owned_books/user', 'parms' => array('id' => $user_id))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the LastFM API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'lastfm.auth.username', 'memakeit'); $parms1 = array('method' => 'user.getinfo', 'user' => $username); $parms2 = array('method' => 'artist.gettoptracks', 'artist' => 'the fall'); $svc = MMI_API::factory(MMI_API::SERVICE_LASTFM); // $response = $svc->get(NULL, $parms1); $requests = array($parms1['method'] => array('parms' => $parms1), $parms2['method'] => array('parms' => $parms2)); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the Flickr API. * * @return void */ public function action_index() { $user_id = '37619738@N07'; $svc = MMI_API::factory(MMI_API::SERVICE_FLICKR); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get(NULL, array('method' => 'flickr.people.getInfo', 'user_id' => $user_id)); $requests = array('people.getInfo' => array('parms' => array('method' => 'flickr.people.getInfo', 'user_id' => $user_id)), 'activity.userPhotos' => array('parms' => array('method' => 'flickr.activity.userPhotos')), 'activity.userComments' => array('parms' => array('method' => 'flickr.activity.userComments')), 'galleries.getList' => array('parms' => array('method' => 'flickr.galleries.getList', 'user_id' => $user_id)), 'photosets.getList' => array('parms' => array('method' => 'flickr.photosets.getList', 'user_id' => $user_id))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Customize the request parameters as specified in the configuration file. * When processing additions, if a parameter value exists, it will not be * overwritten. * * @param array an associative array of request parameters * @return array */ protected function _configure_parameters($parms) { $parms = parent::_configure_parameters($parms); // Ensure the API key is set $api_key = $this->_api_key; $this->_ensure_parm('API key', $api_key); // Set the API and generate the signature $parms['api_key'] = $api_key; if ($this->_sign_requests) { $parms['api_sig'] = $this->_get_signature($parms); } return $parms; }
/** * Test the Picasa API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'picasa.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_PICASA); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get("user/{$username}", array('kind' => 'photo', 'access' => 'all')); $requests = array('albums' => array('url' => "user/{$username}", 'parms' => array('kind' => 'album', 'access' => 'all')), 'recent photos' => array('url' => "user/{$username}", 'parms' => array('kind' => 'photo', 'access' => 'all'))); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }
/** * Test the FriendFeed API. * * @return void */ public function action_index() { $config = MMI_API::get_config(TRUE); $username = Arr::path($config, 'friendfeed.auth.username', 'memakeit'); $svc = MMI_API::factory(MMI_API::SERVICE_FRIENDFEED); if (!$svc->is_valid_token(NULL, TRUE)) { die(HTML::anchor($svc->get_auth_redirect(), $svc->service() . ' authorization required')); } // $response = $svc->get('feed/home'); $requests = array('me feed' => array('url' => 'feed/me'), 'user feed' => array('url' => "feed/{$username}"), 'friends feed' => array('url' => "feed/{$username}/friends"), 'comments feed' => array('url' => "feed/{$username}/comments"), 'likes feed' => array('url' => "feed/{$username}/likes")); $response = $svc->mget($requests); $this->_set_response($response, $svc->service()); }