sdk-generator icon indicating copy to clipboard operation
sdk-generator copied to clipboard

Add context appropriate file names for SDK generator

Open gewenyu99 opened this issue 2 years ago • 8 comments

Our create deployment endpoint uses file.png for the example, which makes no sense.

const promise = functions.createDeployment('[FUNCTION_ID]', '[ENTRYPOINT]', 'file.png', false);

This PR makes the generated file examples context appropriate.

Testing is underway manually and the examples used to test will be posted below.

gewenyu99 avatar Jul 29 '22 17:07 gewenyu99

Python

File:

from appwrite.client import Client
from appwrite.input_file import InputFile
from appwrite.services.storage import Storage

client = Client()

(client
  .set_endpoint('https://demo.appwrite.io/v1') # Your API Endpoint
  .set_project('appwrite-bot') # Your project ID
  .set_key("")
)

storage = Storage(client)

result = storage.create_file('bucket', 'unique()', InputFile.from_path('dir/file.png'))

Deployment:

from appwrite.client import Client
from appwrite.input_file import InputFile
from appwrite.services.functions import Functions

client = Client()

(client
  .set_endpoint('https://demo.appwrite.io/v1') # Your API Endpoint
  .set_project('appwrite-bot') # Your project ID
  .set_key("")
)

functions = Functions(client)

result = functions.create_deployment('test', './index.js', InputFile.from_path('dir/code.tar.gz'), True)

gewenyu99 avatar Jul 29 '22 17:07 gewenyu99

PHP

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Appwrite\Client;
use Appwrite\InputFile;
use Appwrite\Services\Storage;

$client = new Client();

$client
    ->setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    ->setProject('appwrite-bot') // Your project ID
    ->setKey('')
;

$storage = new Storage($client);

$result = $storage->createFile('bucket', 'unique()', InputFile::withPath('dir/file.png'));
<?php
require_once __DIR__ . '/vendor/autoload.php';

use Appwrite\Client;
use Appwrite\InputFile;
use Appwrite\Services\Functions;

$client = new Client();

$client
    ->setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    ->setProject('appwrite-bot') // Your project ID
    ->setKey('')
;

$functions = new Functions($client);

$result = $functions->createDeployment('test', './index.js', InputFile::withPath('dir/code.tar.gz'), false);

gewenyu99 avatar Jul 29 '22 19:07 gewenyu99

Node:

const sdk = require('node-appwrite');
const fs = require('fs');

// Init SDK
const client = new sdk.Client();

const storage = new sdk.Storage(client);

client
    .setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    .setProject('appwrite-bot') // Your project ID
    .setKey('')
;

const promise = storage.createFile('bucket', 'unique()', sdk.InputFile.fromPath('dir/file.png', 'file.png'));

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});



const sdk = require('node-appwrite');
const fs = require('fs');

// Init SDK
const client = new sdk.Client();

const functions = new sdk.Functions(client);

client
    .setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    .setProject('appwrite-bot') // Your project ID
    .setKey('')
;

const promise = functions.createDeployment('test', './index.js', sdk.InputFile.fromPath('dir/code.tar.gz', 'code.tar.gz'), false);

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

gewenyu99 avatar Jul 29 '22 19:07 gewenyu99

Ruby:

require 'appwrite'

client = Appwrite::Client.new
InputFile = Appwrite::InputFile

client
  .set_endpoint('https://demo.appwrite.io/v1') # Your API Endpoint
  .set_project('appwrite-bot') # Your project ID
  .set_key("")


storage = Appwrite::Storage.new(client)

response = storage.create_file(bucket_id: 'bucket', file_id: 'unique()', file: Appwrite::InputFile.from_path('dir/file.png'))

puts response.inspect

require 'appwrite'

client = Appwrite::Client.new
InputFile = Appwrite::InputFile

client
  .set_endpoint('https://demo.appwrite.io/v1') # Your API Endpoint
  .set_project('appwrite-bot') # Your project ID
  .set_key("")

functions = Appwrite::Functions.new(client)

response = functions.create_deployment(function_id: 'test', entrypoint: './index.js', code: Appwrite::InputFile.from_path('dir/code.tar.gz'), activate: false)
puts response.inspect

gewenyu99 avatar Jul 29 '22 19:07 gewenyu99

SWIFT

import Appwrite

func main() async throws {
    let client = Client()
      .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .setProject("5df5acd0d48c2") // Your project ID
    let storage = Storage(client)
    let file = try await storage.createFile(
        bucketId: "[BUCKET_ID]",
        fileId: "[FILE_ID]",
        file: InputFile.fromPath('dir/file.png')
    )

    print(String(describing: file)
}

import Appwrite

func main() async throws {
    let client = Client()
      .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .setProject("5df5acd0d48c2") // Your project ID
    let functions = Functions(client)
    let execution = try await functions.createExecution(
        functionId: "[FUNCTION_ID]"
    )

    print(String(describing: execution)
}

gewenyu99 avatar Jul 29 '22 20:07 gewenyu99

Kotlin

import io.appwrite.Client
import io.appwrite.models.InputFile
import io.appwrite.services.Functions

suspend fun main() {
    val client = Client(context)
      .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .setProject("5df5acd0d48c2") // Your project ID

    val functions = Functions(client)
    val response = functions.createDeployment(
        functionId = "[FUNCTION_ID]",
        entrypoint = "[ENTRYPOINT]",
        code = InputFile.fromPath("dir/code.tar.gz"),
        activate = false
    )
    val json = response.body?.string()
}


import io.appwrite.Client
import io.appwrite.models.InputFile
import io.appwrite.services.Storage

suspend fun main() {
    val client = Client(context)
      .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .setProject("5df5acd0d48c2") // Your project ID

    val storage = Storage(client)
    val response = storage.createFile(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]",
        file = InputFile.fromPath("dir/file.png"),
    )
    val json = response.body?.string()
}

Java:

import io.appwrite.Client
import io.appwrite.models.InputFile
import io.appwrite.services.Functions

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2"); // Your project ID

    Functions functions = new Functions(client);
    functions.createDeployment(
        functionId = "[FUNCTION_ID]",
        entrypoint = "[ENTRYPOINT]",
        code = InputFile.fromPath("dir/code.tar.gz"),
        activate = false
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}


import io.appwrite.Client
import io.appwrite.models.InputFile
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2"); // Your project ID

    Storage storage = new Storage(client);
    storage.createFile(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]",
        file = InputFile.fromPath("dir/file.png"),
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

gewenyu99 avatar Jul 29 '22 21:07 gewenyu99

Deno

import * as sdk from "https://deno.land/x/appwrite/mod.ts";

// Init SDK
let client = new sdk.Client();

let functions = new sdk.Functions(client);

client
    .setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    .setProject('appwrite-bot') // Your project ID
    .setKey('')
;


let promise = functions.createDeployment('test', './index.js', 'dir/code.tar.gz', false);

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});




import * as sdk from "https://deno.land/x/appwrite/mod.ts";

// Init SDK
let client = new sdk.Client();

let storage = new sdk.Storage(client);

client
    .setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    .setProject('appwrite-bot') // Your project ID
    .setKey('')
;


const promise = storage.createFile('bucket', 'unique()', 'dir/file.png');

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

gewenyu99 avatar Jul 29 '22 21:07 gewenyu99

DART

// import 'dart:io';
// import 'package:dart_appwrite/dart_appwrite.dart';
//
// void main() { // Init SDK
//   Client client = Client();
//   Storage storage = Storage(client);
//
//   client
//     .setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
//     .setProject('appwrite-bot') // Your project ID
//     .setKey('')
//   ;
//
//   Future result = storage.createFile(
//     bucketId: 'bucket',
//     fileId: 'unique()',
//     file: InputFile(path: 'dir/file.png', filename: 'file.png'),
//   );
//
//   result
//     .then((response) {
//       print(response);
//     }).catchError((error) {
//       print(error.response);
//   });
// }
//

import 'dart:io';
import 'package:dart_appwrite/dart_appwrite.dart';

void main() { // Init SDK
  Client client = Client();
  Functions functions = Functions(client);

  client
    .setEndpoint('https://demo.appwrite.io/v1') // Your API Endpoint
    .setProject('appwrite-bot') // Your project ID
    .setKey('')
  ;

  Future result = functions.createDeployment(
    functionId: 'test',
    entrypoint: './index.js',
    code: InputFile(path: 'dir/code.tar.gz', filename: 'code.tar.gz'),
    activate: false,
  );

  result
    .then((response) {
      print(response);
    }).catchError((error) {
      print(error.response);
  });
}

gewenyu99 avatar Jul 29 '22 22:07 gewenyu99