Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1841f5c
WIP
Oct 6, 2022
5ee27cc
Elixir: Fix default values in roles
dhrdlicka Oct 26, 2022
4304179
Elixir: Fix redundant `endif` in example
dhrdlicka Oct 26, 2022
703bada
Tests: Don't follow symlinks when cleaning up
dhrdlicka Oct 26, 2022
c92c2ab
Tests: Fix expected/actual output swap
dhrdlicka Oct 26, 2022
4980d37
Elixir: Change SDK information to be consistent
dhrdlicka Oct 26, 2022
b167936
Tests: Add Elixir 1.14 test
dhrdlicka Oct 26, 2022
b79e1a6
Tests: Add Elixir test to `.travis.yml`
dhrdlicka Oct 26, 2022
1b8727e
Move directory back to , fixes tests
dhrdlicka Oct 26, 2022
b87e3d1
Tests: Use the Alpine variant container for Elixir
dhrdlicka Oct 26, 2022
78468a8
Elixir: Follow redirects, fixes redirect test
dhrdlicka Oct 27, 2022
9552871
Elixir: Add HTTP error handling
dhrdlicka Oct 27, 2022
8fd2836
Elixir: Refactor response handling
dhrdlicka Nov 2, 2022
6384b08
Elixir: Proper header and endpoint config
dhrdlicka Nov 2, 2022
fbfbd44
Elixir: Fix chunked upload
dhrdlicka Nov 2, 2022
3a7d80f
Elixir: Fix permissions
dhrdlicka Nov 2, 2022
1f22dab
Tests: Update Elixir tests
dhrdlicka Nov 2, 2022
cce1241
Elixir: Add default endpoint value
dhrdlicka Nov 2, 2022
ac5d2d5
Elixir: add return types
dhrdlicka Nov 2, 2022
681dd8d
Elixir: Fix file upload with raw binaries
dhrdlicka Nov 3, 2022
59c4979
Elixir: File upload error handling
dhrdlicka Nov 3, 2022
9f02426
Elixir: Add download test
dhrdlicka Nov 3, 2022
e8c7955
Elixir: Replace tests launch script with a oneliner
dhrdlicka Nov 4, 2022
3c1b1b5
Merge pull request #1 from dhrdlicka/elixir-tests
martin-dekastello Nov 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
- SDK=DartBeta
- SDK=DartStable
- SDK=Deno1171
- SDK=Elixir114
- SDK=FlutterStable
- SDK=Go112
- SDK=Go118
Expand Down
24 changes: 24 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Appwrite\SDK\Language\CLI;
use Appwrite\SDK\Language\PHP;
use Appwrite\SDK\Language\Python;
use Appwrite\SDK\Language\Elixir;
use Appwrite\SDK\Language\Ruby;
use Appwrite\SDK\Language\Dart;
use Appwrite\SDK\Language\Go;
Expand Down Expand Up @@ -235,6 +236,29 @@ function getSSLPage($url) {

$sdk->generate(__DIR__ . '/examples/python');

// Elixir
$sdk = new SDK(new Elixir(), new Swagger2($spec));

$sdk
->setName('NAME')
->setDescription('Repo description goes here')
->setShortDescription('Repo short description goes here')
->setURL('https://example.com')
->setLogo('https://appwrite.io/v1/images/console.png')
->setLicenseContent('test test test')
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
->setChangelog('**CHANGELOG**')
->setGitUserName('repoowner')
->setGitRepoName('reponame')
->setTwitter('appwrite_io')
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
->setDefaultHeaders([
'X-Appwrite-Response-Format' => '0.7.0',
])
;

$sdk->generate(__DIR__ . '/examples/elixir');

// Dart
$dart = new Dart();
$dart->setPackageName('dart_appwrite');
Expand Down
314 changes: 314 additions & 0 deletions src/SDK/Language/Elixir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
<?php

namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Exception;

class Elixir extends Language {

protected $params = [
'pipPackage' => 'packageName',
];

/**
* @param string $name
* @return $this
*/
public function setPipPackage($name): self
{
$this->setParam('pipPackage', $name);

return $this;
}

/**
* @return string
*/
public function getName(): string
{
return 'Elixir';
}

/**
* Get Language Keywords List
*
* @return array
*/
public function getKeywords(): array
{
return [
'false',
'is',
'nil',
'for',
'try',
'true',
'def',
'alias',
'and',
'del',
'not',
'with',
'as',
'case',
'if',
'or',
'assert',
'else',
'import',
'when',
'in',
'throw',
];
}

/**
* @return array
*/
public function getIdentifierOverrides(): array
{
return [];
}

/**
* @return array
*/
public function getFiles(): array
{
return [
[
'scope' => 'default',
'destination' => 'README.md',
'template' => 'elixir/README.md.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'CHANGELOG.md',
'template' => 'elixir/CHANGELOG.md.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'LICENSE',
'template' => 'elixir/LICENSE.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'mix.exs',
'template' => 'elixir/mix.exs.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => '.formatter.exs',
'template' => 'elixir/.formatter.exs.twig',
'minify' => false,
],
/*[
'scope' => 'service',
'destination' => 'docs/{{service.name | caseSnake}}.md',
'template' => 'elixir/docs/service.md.twig',
'minify' => false,
],
[
'scope' => 'service',
'destination' => 'docs/{{service.name | caseSnake}}.md',
'template' => 'elixir/docs/service.md.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'docs/examples/{{service.name | caseSnake}}/{{method.name | caseSnake}}.md',
'template' => 'elixir/docs/example.md.twig',
'minify' => false,
],*/
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/client.ex',
'template' => 'elixir/lib/appwrite/client.ex.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/permission.ex',
'template' => 'elixir/lib/appwrite/permission.ex.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/role.ex',
'template' => 'elixir/lib/appwrite/role.ex.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/id.ex',
'template' => 'elixir/lib/appwrite/id.ex.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/query.ex',
'template' => 'elixir/lib/appwrite/query.ex.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/exception.ex',
'template' => 'elixir/lib/appwrite/exception.ex.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'lib/{{ spec.title | caseSnake}}/input_file.ex',
'template' => 'elixir/lib/appwrite/input_file.ex.twig',
'minify' => false,
],
[
'scope' => 'service',
'destination' => 'lib/{{ spec.title | caseSnake}}/services/{{service.name | caseSnake}}.ex',
'template' => 'elixir/lib/appwrite/services/service.ex.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
'template' => 'elixir/docs/example.md.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => '.travis.yml',
'template' => 'elixir/.travis.yml.twig',
'minify' => false,
],
];
}

/**
* @param array $parameter
* @return string
* @throws Exception
*/
public function getTypeName(array $parameter): string
{
throw new Exception('Method not supported for Elixir SDKs');
}

/**
* @param array $param
* @return string
*/
public function getParamDefault(array $param): string
{
$type = $param['type'] ?? '';
$default = $param['default'] ?? '';
$required = $param['required'] ?? '';

if($required) {
return '';
}

$output = '=';

if(empty($default) && $default !== 0 && $default !== false) {
switch ($type) {
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
case self::TYPE_BOOLEAN:
$output .= 'None';
break;
case self::TYPE_STRING:
$output .= "''";
break;
case self::TYPE_ARRAY:
$output .= '[]';
break;
case self::TYPE_OBJECT:
case self::TYPE_FILE:
$output .= '{}';
break;
}
}
else {
switch ($type) {
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
case self::TYPE_ARRAY:
case self::TYPE_OBJECT:
$output .= $default;
break;
case self::TYPE_FILE:
#$output .= json_encode($default);
$output .= '{}';
break;
case self::TYPE_BOOLEAN:
$output .= ($default) ? 'True' : 'False';
break;
case self::TYPE_STRING:
$output .= "'$default'";
break;
}
}

return $output;
}

/**
* @param array $param
* @return string
*/
public function getParamExample(array $param): string
{
$type = $param['type'] ?? '';
$example = $param['example'] ?? '';

$output = '';

if(empty($example) && $example !== 0 && $example !== false) {
switch ($type) {
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
case self::TYPE_BOOLEAN:
$output .= 'None';
break;
case self::TYPE_STRING:
$output .= "''";
break;
case self::TYPE_ARRAY:
$output .= '[]';
break;
case self::TYPE_OBJECT:
$output .= '{}';
break;
case self::TYPE_FILE:
$output .= "InputFile.from_path('file.png')";
break;
}
}
else {
switch ($type) {
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
case self::TYPE_ARRAY:
case self::TYPE_OBJECT:
$output .= $example;
break;
case self::TYPE_BOOLEAN:
$output .= ($example) ? 'True' : 'False';
break;
case self::TYPE_STRING:
$output .= "'{$example}'";
break;
case self::TYPE_FILE:
$output .= "InputFile.from_path('file.png')";
break;
}
}

return $output;
}
}
4 changes: 4 additions & 0 deletions templates/elixir/.formatter.exs.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
16 changes: 16 additions & 0 deletions templates/elixir/.travis.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python

python:
- "3.8"

jobs:
include:
- stage: pypi release
python: "3.8"
script: echo "Deploying to pypi ..."
deploy:
provider: pypi
username: "__token__"
password: $PYPI_TOKEN
on:
tags: true
1 change: 1 addition & 0 deletions templates/elixir/CHANGELOG.md.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{sdk.changelog}}
1 change: 1 addition & 0 deletions templates/elixir/LICENSE.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{sdk.licenseContent | raw}}
Loading