public function indexAction()
 {
     $serviceKey = $this->params()->fromQuery('service');
     $serviceType = $this->params()->fromQuery('type');
     $userId = $this->params()->fromQuery('uid');
     $serviceKey = ucfirst(strtolower($serviceKey));
     $serviceType = ucfirst(strtolower($serviceType));
     $this->changeViewModel('json');
     $itemModel = Api::_()->getModel('Oauth\\Model\\Accesstoken');
     $dataClass = $itemModel->getItem()->getDataClass();
     $item = $dataClass->where(function ($where) use($serviceKey, $serviceType, $userId) {
         $where->equalTo('adapterKey', strtolower($serviceKey));
         $where->equalTo('tokenStatus', 'active');
         $where->equalTo('version', $serviceType);
         $where->equalTo('user_id', $userId);
         return $where;
     })->find('one');
     $item = (array) $item;
     if (!$item) {
         return new JsonModel();
     }
     $webserice = WebserviceFactory::factory($serviceType . $serviceKey, $item, $this->getServiceLocator());
     $adapter = $webserice->getAdapter();
     $userApi = $adapter->uniformApi('User');
     $userId = $item['remoteUserId'];
     $user = $userApi->setUserId($userId)->getData();
     //$json = $userApi->getLastRawResponse();
     //p($userApi->getAdapter()->getClient()->getRequest()->toString());
     //p($userApi->getAdapter()->getClient()->getResponse()->getBody());
     return new JsonModel(array('data' => $user));
 }
 public function syncAction()
 {
     $serviceKey = $this->params()->fromQuery('service');
     $serviceType = $this->params()->fromQuery('type');
     $content = $this->params()->fromQuery('content');
     $user = \Core\Auth::getLoginUser();
     $userId = $user['id'];
     $serviceKey = ucfirst(strtolower($serviceKey));
     $serviceType = ucfirst(strtolower($serviceType));
     $this->changeViewModel('json');
     if (!$userId || !$content) {
         return new JsonModel();
     }
     $itemModel = Api::_()->getModel('Oauth\\Model\\Accesstoken');
     $dataClass = $itemModel->getItem()->getDataClass();
     $item = $dataClass->where(function ($where) use($serviceKey, $serviceType, $userId) {
         $where->equalTo('adapterKey', strtolower($serviceKey));
         $where->equalTo('tokenStatus', 'active');
         $where->equalTo('version', $serviceType);
         $where->equalTo('user_id', $userId);
         return $where;
     })->find('one');
     $item = (array) $item;
     if (!$item) {
         return new JsonModel();
     }
     $webserice = WebserviceFactory::factory($serviceType . $serviceKey, $item, $this->getServiceLocator());
     $adapter = $webserice->getAdapter();
     $feedApi = $adapter->uniformApi('Feed');
     $feedApi->setUserId($item['remoteUserId']);
     $feed = $feedApi->createFeed(array('content' => $content));
     return new JsonModel(array('data' => $feed));
 }
 public function indexAction()
 {
     $serviceKey = $this->params()->fromQuery('service');
     $serviceType = $this->params()->fromQuery('type');
     $userId = $this->params()->fromQuery('uid');
     $serviceKey = ucfirst(strtolower($serviceKey));
     $serviceType = ucfirst(strtolower($serviceType));
     $this->changeViewModel('json');
     $itemModel = Api::_()->getModel('Oauth\\Model\\Accesstoken');
     $dataClass = $itemModel->getItem()->getDataClass();
     $item = $dataClass->where(function ($where) use($serviceKey, $serviceType, $userId) {
         $where->equalTo('adapterKey', strtolower($serviceKey));
         $where->equalTo('tokenStatus', 'active');
         $where->equalTo('version', $serviceType);
         $where->equalTo('user_id', $userId);
         return $where;
     })->find('one');
     $item = (array) $item;
     if (!$item) {
         return new JsonModel();
     }
     $fileModel = Api::_()->getModel('File\\Model\\File');
     $file = $fileModel->getFile(24, array('self' => array('*', 'getThumb()', 'getFullPath()')));
     $webserice = WebserviceFactory::factory($serviceType . $serviceKey, $item, $this->getServiceLocator());
     $adapter = $webserice->getAdapter();
     $albumApi = $adapter->uniformApi('Album');
     $albumApi->setUserId($item['remoteUserId']);
     $albumApi->setAlbumId('5819073682310479025');
     //$data = $albumApi->getAlbumList();
     $file = $albumApi->uploadPhoto($file);
     return new JsonModel(array('file' => $file));
 }