Exemple #1
0
 /**
  * Add the `Node` to trash.
  *
  * @return array
  */
 public function trash()
 {
     $retval = ['success' => false, 'data' => []];
     if ($this['status'] === 'TRASH') {
         $retval['data']['message'] = 'Node is already in trash.';
         return $retval;
     }
     $response = self::$httpClient->put(self::$account->getMetadataUrl() . "trash/{$this['id']}", ['headers' => ['Authorization' => 'Bearer ' . self::$account->getToken()['access_token']], 'exceptions' => false]);
     $retval['data'] = json_decode((string) $response->getBody(), true);
     if ($response->getStatusCode() === 200) {
         $retval['success'] = true;
         $this->replace($retval['data']);
         $this->save();
     }
     return $retval;
 }
 /**
  * Create a new remote node nested under the provided parents (created under
  * root node if none given).
  *
  * @param string $name    Name of the new remote folder
  * @param null   $parents Parent IDs to give the folder
  *
  * @return array
  * @throws \Exception
  */
 public function createFolder($name, $parents = null)
 {
     $retval = ['success' => false, 'data' => [], 'response_code' => null];
     if (is_null($parents)) {
         $parents = Node::loadRoot()['id'];
     }
     if (!is_array($parents)) {
         $parents = [$parents];
     }
     $response = $this->httpClient->post("{$this->account->getMetadataUrl()}nodes", ['headers' => ['Authorization' => "Bearer {$this->account->getToken()["access_token"]}"], 'json' => ['name' => $name, 'parents' => $parents, 'kind' => 'FOLDER'], 'exceptions' => false]);
     $retval['data'] = json_decode((string) $response->getBody(), true);
     if (($retval['response_code'] = $response->getStatusCode()) === 201) {
         $retval['success'] = true;
         (new Node($retval['data']))->save();
     }
     return $retval;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function saveAccountConfig(Account $account)
 {
     $config = ORM::for_table('configs')->where('email', $account->getEmail())->find_one();
     if (!$config) {
         $config = ORM::for_table('configs')->create();
     }
     $config->set(['email' => $account->getEmail(), 'token_type' => $account->getToken()['token_type'], 'expires_in' => $account->getToken()['expires_in'], 'refresh_token' => $account->getToken()['refresh_token'], 'access_token' => $account->getToken()['access_token'], 'last_authorized' => $account->getToken()['last_authorized'], 'content_url' => $account->getContentUrl(), 'metadata_url' => $account->getMetadataUrl(), 'checkpoint' => $account->getCheckpoint()]);
     return $config->save();
 }