Skip to content

Commit

Permalink
chore: update SDKs to new RC version
Browse files Browse the repository at this point in the history
  • Loading branch information
christyjacob4 committed Aug 20, 2024
1 parent 6e68a65 commit 71b764c
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/examples/functions/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ $result = $functions->create(
templateRepository: '<TEMPLATE_REPOSITORY>', // optional
templateOwner: '<TEMPLATE_OWNER>', // optional
templateRootDirectory: '<TEMPLATE_ROOT_DIRECTORY>', // optional
templateVersion: '<TEMPLATE_VERSION>' // optional
templateVersion: '<TEMPLATE_VERSION>', // optional
specification: '' // optional
);
13 changes: 13 additions & 0 deletions docs/examples/functions/list-specifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
use Appwrite\Client;
use Appwrite\Services\Functions;
$client = (new Client())
->setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
->setProject('&lt;YOUR_PROJECT_ID&gt;') // Your project ID
->setKey('&lt;YOUR_API_KEY&gt;'); // Your secret API key

$functions = new Functions($client);

$result = $functions->listSpecifications();
3 changes: 2 additions & 1 deletion docs/examples/functions/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ $result = $functions->update(
providerRepositoryId: '<PROVIDER_REPOSITORY_ID>', // optional
providerBranch: '<PROVIDER_BRANCH>', // optional
providerSilentMode: false, // optional
providerRootDirectory: '<PROVIDER_ROOT_DIRECTORY>' // optional
providerRootDirectory: '<PROVIDER_ROOT_DIRECTORY>', // optional
specification: '' // optional
);
11 changes: 11 additions & 0 deletions docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ POST https://cloud.appwrite.io/v1/functions
| templateOwner | string | The name of the owner of the template. | |
| templateRootDirectory | string | Path to function code in the template repo. | |
| templateVersion | string | Version (tag) for the repo linked to the function template. | |
| specification | string | Runtime specification for the function and builds. | s-0.5vcpu-512mb |

## List runtimes

Expand All @@ -57,6 +58,15 @@ GET https://cloud.appwrite.io/v1/functions/runtimes

** Get a list of all runtimes that are currently active on your instance. **

## List available function runtime specifications

```http request
GET https://cloud.appwrite.io/v1/functions/specifications
```

** List allowed function specifications for this instance.
**

## List function templates

```http request
Expand Down Expand Up @@ -131,6 +141,7 @@ PUT https://cloud.appwrite.io/v1/functions/{functionId}
| providerBranch | string | Production branch for the repo linked to the function | |
| providerSilentMode | boolean | Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. | |
| providerRootDirectory | string | Path to function code in the linked repo. | |
| specification | string | Runtime specification for the function and builds. | s-0.5vcpu-512mb |

## Delete function

Expand Down
4 changes: 2 additions & 2 deletions src/Appwrite/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Client
*/
protected array $headers = [
'content-type' => '',
'user-agent' => 'AppwritePHPSDK/12.0.0-rc.1 ()',
'user-agent' => 'AppwritePHPSDK/12.0.0-rc.2 ()',
'x-sdk-name'=> 'PHP',
'x-sdk-platform'=> 'server',
'x-sdk-language'=> 'php',
'x-sdk-version'=> '12.0.0-rc.1',
'x-sdk-version'=> '12.0.0-rc.2',
];

/**
Expand Down
54 changes: 50 additions & 4 deletions src/Appwrite/Services/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ public function list(?array $queries = null, ?string $search = null): array
* @param ?string $templateOwner
* @param ?string $templateRootDirectory
* @param ?string $templateVersion
* @param ?string $specification
* @throws AppwriteException
* @return array
*/
public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $templateRepository = null, ?string $templateOwner = null, ?string $templateRootDirectory = null, ?string $templateVersion = null): array
public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $templateRepository = null, ?string $templateOwner = null, ?string $templateRootDirectory = null, ?string $templateVersion = null, ?string $specification = null): array
{
$apiPath = str_replace(
[],
Expand Down Expand Up @@ -173,6 +174,10 @@ public function create(string $functionId, string $name, Runtime $runtime, ?arra
$apiParams['templateVersion'] = $templateVersion;
}

if (!is_null($specification)) {
$apiParams['specification'] = $specification;
}

$apiHeaders = [];
$apiHeaders['content-type'] = 'application/json';

Expand Down Expand Up @@ -213,6 +218,36 @@ public function listRuntimes(): array
);
}

/**
* List available function runtime specifications
*
* List allowed function specifications for this instance.
*
*
* @throws AppwriteException
* @return array
*/
public function listSpecifications(): array
{
$apiPath = str_replace(
[],
[],
'/functions/specifications'
);

$apiParams = [];

$apiHeaders = [];
$apiHeaders['content-type'] = 'application/json';

return $this->client->call(
Client::METHOD_GET,
$apiPath,
$apiHeaders,
$apiParams
);
}

/**
* List function templates
*
Expand Down Expand Up @@ -350,10 +385,11 @@ public function get(string $functionId): array
* @param ?string $providerBranch
* @param ?bool $providerSilentMode
* @param ?string $providerRootDirectory
* @param ?string $specification
* @throws AppwriteException
* @return array
*/
public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null): array
public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $specification = null): array
{
$apiPath = str_replace(
['{functionId}'],
Expand Down Expand Up @@ -422,6 +458,10 @@ public function update(string $functionId, string $name, ?Runtime $runtime = nul
$apiParams['providerRootDirectory'] = $providerRootDirectory;
}

if (!is_null($specification)) {
$apiParams['specification'] = $specification;
}

$apiHeaders = [];
$apiHeaders['content-type'] = 'application/json';

Expand Down Expand Up @@ -887,7 +927,7 @@ public function listExecutions(string $functionId, ?array $queries = null, ?stri
* @throws AppwriteException
* @return array
*/
public function createExecution(string $functionId, ?string $body = null, ?bool $async = null, ?string $xpath = null, ?ExecutionMethod $method = null, ?array $headers = null, ?string $scheduledAt = null, callable $onProgress = null): array
public function createExecution(string $functionId, ?string $body = null, ?bool $async = null, ?string $xpath = null, ?ExecutionMethod $method = null, ?array $headers = null, ?string $scheduledAt = null): array
{
$apiPath = str_replace(
['{functionId}'],
Expand Down Expand Up @@ -923,8 +963,14 @@ public function createExecution(string $functionId, ?string $body = null, ?bool
}

$apiHeaders = [];
$apiHeaders['content-type'] = 'multipart/form-data';
$apiHeaders['content-type'] = 'application/json';

return $this->client->call(
Client::METHOD_POST,
$apiPath,
$apiHeaders,
$apiParams
);
}

/**
Expand Down
29 changes: 25 additions & 4 deletions tests/Appwrite/Services/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function testMethodCreate(): void {
"providerRepositoryId" => "appwrite",
"providerBranch" => "main",
"providerRootDirectory" => "functions/helloWorld",
"providerSilentMode" => true,);
"providerSilentMode" => true,
"specification" => "s-0.5vcpu-512mb",);


$this->client
Expand Down Expand Up @@ -91,6 +92,23 @@ public function testMethodListRuntimes(): void {
$this->assertSame($data, $response);
}

public function testMethodListSpecifications(): void {

$data = array(
"total" => 5,
"specifications" => array(),);


$this->client
->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any())
->andReturn($data);

$response = $this->functions->listSpecifications(
);

$this->assertSame($data, $response);
}

public function testMethodListTemplates(): void {

$data = array(
Expand Down Expand Up @@ -166,7 +184,8 @@ public function testMethodGet(): void {
"providerRepositoryId" => "appwrite",
"providerBranch" => "main",
"providerRootDirectory" => "functions/helloWorld",
"providerSilentMode" => true,);
"providerSilentMode" => true,
"specification" => "s-0.5vcpu-512mb",);


$this->client
Expand Down Expand Up @@ -205,7 +224,8 @@ public function testMethodUpdate(): void {
"providerRepositoryId" => "appwrite",
"providerBranch" => "main",
"providerRootDirectory" => "functions/helloWorld",
"providerSilentMode" => true,);
"providerSilentMode" => true,
"specification" => "s-0.5vcpu-512mb",);


$this->client
Expand Down Expand Up @@ -360,7 +380,8 @@ public function testMethodUpdateDeployment(): void {
"providerRepositoryId" => "appwrite",
"providerBranch" => "main",
"providerRootDirectory" => "functions/helloWorld",
"providerSilentMode" => true,);
"providerSilentMode" => true,
"specification" => "s-0.5vcpu-512mb",);


$this->client
Expand Down

0 comments on commit 71b764c

Please sign in to comment.