/** * Pushbullet redirect uri * * @return \Phalcon\Http\ResponseInterface */ public function pushbulletAction() { $code = $this->request->get('code'); try { $pushbullet = new Pushbullet(''); $pushbullet->setConfig($this->config); $token = $pushbullet->getToken($code); } catch (Exception $e) { $this->flashSession->error($e->getMessage()); return $this->response->redirect('user/app'); } $pushbullet_oauth = UserOauth::findFirst(["user_id = :user_id: and app = 'pushbullet'", 'bind' => ['user_id' => $this->current_user->id]]); if ($pushbullet_oauth) { $pushbullet_oauth->access_token = $token; $pushbullet_oauth->save(); // active UserActive::record('oauth-edit', $this->current_user->id); } else { $oauth = new UserOauth(); $oauth->user_id = $this->current_user->id; $oauth->app = 'pushbullet'; $oauth->access_token = $token; $oauth->create(); // active UserActive::record('oauth-create', $this->current_user->id); } return $this->response->redirect('user/app'); }
protected function execute(array $arguments) { if (isset($arguments[0]) && ($user_id = (int) $GLOBALS['user_id'])) { $oauth = \UserOauth::findFirst(["user_id = :user_id: and app='pushbullet'", 'bind' => ['user_id' => $user_id]]); if ($oauth) { $token = $oauth->access_token; $pushbullet = new Pushbullet($token); $pushbullet->pushNote('', $arguments[0]); } return ''; } throw new InvalidArgumentException('strings invalid'); }
/** * @throws \Workflow\Exception\PocketException */ public function appAction() { $oauth = UserOauth::find(["user_id = :user_id: and access_token <> ''", 'bind' => ['user_id' => $this->current_user->id]]); $app = []; foreach ($oauth as $item) { $app[$item->app] = 'auth'; } $pushbullet = new Pushbullet(''); $pushbullet->setConfig($this->config); $pock = new Pocket(''); $pock->setConfig($this->config); $request_token = $pock->requestToken(); $this->view->setVar('pushbullet_authorize_uri', $pushbullet->authorizeUrl()); $this->view->setVar('pocket_authorize_uri', $pock->authorizeUrl($request_token)); $this->view->setVar('app', $app); }
/** * Push a file. * * @param string $recipient Recipient. Can be device_iden, email or channel #tagname. * @param string $filePath The path of the file to push. * @param string $mimeType The MIME type of the file. If null, we'll try to guess it. * @param string $title The title of the push notification. * @param string $body The body of the push notification. * @param string $altFileName Alternative file name to use instead of the original one. * For example, you might want to push 'someFile.tmp' as 'image.jpg'. * * @return object Response. * @throws PushbulletException */ public function pushFile($recipient, $filePath, $mimeType = null, $title = null, $body = null, $altFileName = null) { $data = []; $fullFilePath = realpath($filePath); if (!is_readable($fullFilePath)) { throw new PushbulletException('File: File does not exist or is unreadable.'); } if (filesize($fullFilePath) > 25 * 1024 * 1024) { throw new PushbulletException('File: File size exceeds 25 MB.'); } $data['file_name'] = $altFileName === null ? basename($fullFilePath) : $altFileName; // Try to guess the MIME type if the argument is NULL $data['file_type'] = $mimeType === null ? mime_content_type($fullFilePath) : $mimeType; // Request authorization to upload the file $response = $this->_curlRequest(self::URL_UPLOAD_REQUEST, 'GET', $data); $data['file_url'] = $response->file_url; if (version_compare(PHP_VERSION, '5.5.0', '>=')) { $response->data->file = new \CURLFile($fullFilePath); } else { $response->data->file = '@' . $fullFilePath; } // Upload the file $this->_curlRequest($response->upload_url, 'POST', $response->data, false, false); Pushbullet::_parseRecipient($recipient, $data); $data['type'] = 'file'; $data['title'] = $title; $data['body'] = $body; return $this->_curlRequest(self::URL_PUSHES, 'POST', $data); }