Add a writer to the permissions on the file (temporary).

@param \repository_googledocs\rest $client Authenticated client.
@param string $fileid The file we are updating.
@param string $email The email of the writer account to add.
@return boolean
329082
protected function add_temp_writer_to_file(\repository_googledocs\rest $client, $fileid, $email) {
        // Expires in 7 days.
        $expires = new DateTime();
        $expires->add(new DateInterval("P7D"));

        $updateeditor = [
            'emailAddress' => $email,
            'role' => 'writer',
            'type' => 'user',
            'expirationTime' => $expires->format(DateTime::RFC3339)
        ];
        $params = ['fileid' => $fileid, 'sendNotificationEmail' => 'false'];
        $response = $client->call('create_permission', $params, json_encode($updateeditor));
        if (empty($response->id)) {
            $details = 'Cannot add user ' . $email . ' as a writer for document: ' . $fileid;
            throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);
        }
        return true;
    }
208952
protected function add_temp_writer_to_file(\repository_onedrive\rest $client, $fileid, $email) {
        // Expires in 7 days.
        $expires = new DateTime();
        $expires->add(new DateInterval("P7D"));

        $updateeditor = [
            'recipients' => [[ 'email' => $email ]],
            'roles' => ['write'],
            'requireSignIn' => true,
            'sendInvitation' => false
        ];
        $params = ['fileid' => $fileid];
        $response = $client->call('create_permission', $params, json_encode($updateeditor));
        if (empty($response->value[0]->id)) {
            $details = 'Cannot add user ' . $email . ' as a writer for document: ' . $fileid;
            throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);
        }
        // Store the permission id in the DB. Scheduled task will remove this permission after 7 days.
        if ($access = repository_onedrive\access::get_record(['permissionid' => $response->value[0]->id, 'itemid' => $fileid ])) {
            // Update the timemodified.
            $access->update();
        } else {
            $record = (object) [ 'permissionid' => $response->value[0]->id, 'itemid' => $fileid ];
            $access = new repository_onedrive\access(0, $record);
            $access->create();
        }
        return true;
    }
763212
def add(self, email):
        
        if email not in self._collaborators:
            self._collaborators[email] = ShareRequestValue.Add
        self._dirty = True
149251
protected function prevent_writers_from_sharing_file(\repository_googledocs\rest $client, $fileid) {
        // We don't want anyone but Moodle to change the sharing settings.
        $params = [
            'fileid' => $fileid
        ];
        $update = [
            'writersCanShare' => false
        ];
        $response = $client->call('update', $params, json_encode($update));
        if (empty($response->id)) {
            $details = 'Cannot prevent writers from sharing document: ' . $fileid;
            throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);
        }
        return true;
    }
373187
public static function authorize($clientID, $clientSecret)
    {
        return json_decode(
            (new AuthorizationRequest($clientID, $clientSecret))->execute()->getBody(), true
        );
    }
1300354
public function write($file, $content, $type='sandbox')
	{
		$url = 'https://api-content.dropbox.com/1/files_put/';
		$result = $this->doOAuthCall($url,'PUT',null,$type,$file,$content);
		$result_body = json_decode($result['body'],true);
		if (!array_key_exists('error', $result_body)) {
			return $result_body;
		} else {
			trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
			return false;
		}
	}
687006
public function dumpFile($filename, $content)
    {
        $dir = dirname($filename);

        if (!is_dir($dir)) {
            $this->mkdir($dir);
        }

        if (!is_writable($dir)) {
            throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
        }

        // Will create a temp file with 0600 access rights
        // when the filesystem supports chmod.
        $tmpFile = $this->tempnam($dir, basename($filename));

        if (false === @file_put_contents($tmpFile, $content)) {
            throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
        }

        @chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());

        $this->rename($tmpFile, $filename, true);
    }
340820
public Client createWithEmailAndDescription( String email, String description ) {
    ParameterMap<String, String> params = new ParameterMap<String, String>();
    if( StringUtils.isNotBlank( email ) )
      params.add( "email", email );
    if( StringUtils.isNotBlank( description ) )
      params.add( "description", description );

    return RestfulUtils.create( ClientService.PATH, params, Client.class, super.httpClient );
  }
797325
private function write($src, $fileName, $content)
    {

        if (!$this->file->exists($src)) {
            $this->file->makeDirectory($src);
        }
        $this->file->put($fileName, $content);
    }
645154
public static void writeReadDeleteDocument(DatabaseClient client, String filename, String format) throws IOException {
    // create a manager for documents of any format
    GenericDocumentManager docMgr = client.newDocumentManager();

    InputStream docStream = Util.openStream("data"+File.separator+filename);
    if (docStream == null)
      throw new IOException("Could not read document example");

    // create an identifier for the document
    String docId = "/example/"+filename;

    // create a handle for the document
    InputStreamHandle writeHandle = new InputStreamHandle();
    writeHandle.set(docStream);

    // write the document
    docMgr.write(docId, writeHandle);

    // create a handle to receive the document content
    BytesHandle readHandle = new BytesHandle();

    // read the document content
    docMgr.read(docId, readHandle);

    // access the document content
    byte[] document = readHandle.get();

    // ... do something with the document content ...

    // delete the document
    docMgr.delete(docId);

    System.out.println("Wrote, read, and deleted /example/"+filename+
      " content with "+document.length+" bytes in the "+format+" format");
  }
729509
public function addClient(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client)
    {
        $this->clients[] = $client;

        return $this;
    }
892362
WriteResult writeDocument(RestClient restClient,
                              String key,
                              Boolean randomizeKeys) throws Exception {
        if (isBulkWrite) {
            writeBatchSizeWorthOfDocs(restClient, key, randomizeKeys);
        } else {
            writeSingleDoc(restClient, key, randomizeKeys);
        }

        return WriteResult.PROVISIONAL_RESULT_THAT_ASSUMES_ALL_WENT_WELL;
    }
455687
public function initialize($email, $password, array $clientConfig = [])
    {
        $mergedConfig = array_merge(
            $this->clientConfig,
            $clientConfig,
            [
                'headers' => [
                    'User-Agent' => "RIPS-API-Connector/{$this->version}",
                ],
            ],
            [
                'headers' => $this->getAuthHeaders($email, $password, $clientConfig)
            ]
        );

        $client = new Client($mergedConfig);
        $this->callbacks = new CallbackRequests($client);
        $this->applications = new ApplicationRequests($client);
        $this->licenses = new LicenseRequests($client);
        $this->logs = new LogRequests($client);
        $this->orgs = new OrgRequests($client);
        $this->quotas = new QuotaRequests($client);
        $this->settings = new SettingRequests($client);
        $this->sources = new SourceRequests($client);
        $this->status = new StatusRequests($client);
        $this->teams = new TeamRequests($client);
        $this->users = new UserRequests($client);
        $this->oauth2 = new OAuth2Requests($client);
        $this->activities = new ActivityRequests($client);
        $this->maintenance = new MaintenanceRequests($client);
        $this->languages = new LanguageRequests($client);
        $this->systems = new SystemRequests($client);
    }
1329670
public function updateEmailContent($emailId, $args = array(), $returnRaw = false)
    {
        $args['id'] = $emailId;

        return $this->getResult('updateEmailContent', $args, false, $returnRaw);
    }
194521
public function write($file_name, $content = '')
    {
        if (!is_file($file_name)) {
            return false;
        }

        return file_put_contents($file_name, $content, LOCK_EX);
    }
999666
public function addAuthor(string $name = null, string $email = null)
    {
        is_null($name) and $name = '';
        is_null($email) and $email = '';

        if (empty($name) and empty($email)) {
            throw new AuthorNoDataException();
        }

        if (!empty($email)) {
            $author = trim(sprintf(self::FORMAT_AUTHOR, $name, $email));
        } else {
            $author = trim($name);
        }

        $this->authors[] = $author;

        return $this;
    }
131677
private function createAccessToken($email, $password, $clientConfig)
    {
        $oauth2Config = $clientConfig['oauth2'];
        if (!array_key_exists('client_id', $oauth2Config)) {
            throw new Exception('Cannot create new oauth token without client id');
        }

        $mergedConfig = array_merge($this->clientConfig, $clientConfig, [
            'headers' => [
                'User-Agent' => "RIPS-API-Connector/{$this->version}",
            ],
            RequestOptions::JSON => [
                'grant_type' => 'password',
                'client_id' => $oauth2Config['client_id'],
                'username' => $email,
                'password' => $password
            ]
        ]);

        $request = new AccessTokenRequest(new Client($mergedConfig));
        $tokens = $request->getTokens()->getDecodedData();

        if (isset($oauth2Config['store_token']) && $oauth2Config['store_token'] === true) {
            if (!array_key_exists('token_file_path', $oauth2Config) || empty($oauth2Config['token_file_path'])) {
                throw new Exception('Token path is needed to store token');
            }
            $filePath = $oauth2Config['token_file_path'];
            file_put_contents($filePath, json_encode($tokens));
        }

        return $tokens->access_token;
    }