Browse Source

gledale http client

moell 10 months ago
parent
commit
61f5343371

+ 2 - 0
app/Services/File/BIM/BIMDriverEnum.php

@@ -5,4 +5,6 @@ namespace App\Services\File\BIM;
 enum BIMDriverEnum: string
 {
     case BLACK_HOLE = "black_hole";
+
+    case GLENDALE = "glendale";
 }

+ 3 - 1
app/Services/File/BIM/BIMFactory.php

@@ -4,6 +4,7 @@ namespace App\Services\File\BIM;
 
 use App\Services\File\BIM\BlackHole\BlackHole;
 use App\Services\File\BIM\Contacts\BIMContact;
+use App\Services\File\BIM\Glendale\Glendale;
 
 class BIMFactory
 {
@@ -12,7 +13,8 @@ class BIMFactory
         $driver = $driver ? $driver : config("bim.default");
 
         return match ($driver) {
-            "black_hole" => new BlackHole(),
+            BIMDriverEnum::BLACK_HOLE => new BlackHole(),
+            BIMDriverEnum::GLENDALE => new Glendale(),
         };
     }
 }

+ 71 - 0
app/Services/File/BIM/Glendale/Client.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace App\Services\File\BIM\Glendale;
+
+
+use App\Services\File\BIM\Exceptions\FailedException;
+use Psr\Http\Message\ResponseInterface;
+
+
+class Client {
+
+    protected static ?Client $instance = null;
+
+    protected \GuzzleHttp\Client $client;
+
+    protected function __construct()
+    {
+        $this->client = new \GuzzleHttp\Client([
+            'base_uri' => config("bim.glendale.host"),
+            'http_errors' => false,
+            'debug' => false,
+            'headers' => [
+                'Accept' => "application/json",
+                'Token' => config("bim.glendale.token"),
+            ]
+        ]);
+    }
+
+    public static function getInstance(): Client
+    {
+        if (! self::$instance) {
+            self::$instance = new self();
+        }
+
+        return self::$instance;
+    }
+
+    public function request(string $method, string $uri, array $options = []): ?array
+    {
+        return $this->parseResponse($this->client->request($method, $uri, $options));
+    }
+
+    public function post(string $uri, array $options = []) {
+        return $this->request("POST", $uri, $options);
+    }
+
+    protected function parseResponse(ResponseInterface $response): ?array
+    {
+        $body = json_decode((string)$response->getBody(), true);
+
+        return match ($response->getStatusCode()) {
+            200, 201, 204 => $this->parseStatusSuccessResponse($body),
+            default => throw new FailedException($body['message'] ?? $response->getReasonPhrase()),
+        };
+    }
+
+    protected function parseStatusSuccessResponse(array $body)
+    {
+        $isJson = json_last_error() == JSON_ERROR_NONE;
+
+        if (! $isJson) {
+            return [];
+        }
+
+        if ($body['code'] != 1) {
+            throw new FailedException($body['codeMsg']);
+        }
+
+        return $body;
+    }
+}

+ 35 - 0
app/Services/File/BIM/Glendale/Glendale.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Services\File\BIM\Glendale;
+
+use App\Services\File\BIM\Contacts\BIMContact;
+use Illuminate\Http\UploadedFile;
+
+class Glendale implements BIMContact
+{
+
+    public function uploadFile(UploadedFile $file, array $params = [])
+    {
+        // TODO: Implement uploadFile() method.
+    }
+
+    public function downloadSourceFile()
+    {
+        // TODO: Implement downloadSourceFile() method.
+    }
+
+    public function findConvertStatus(string $dataSetId)
+    {
+        // TODO: Implement findConvertStatus() method.
+    }
+
+    public function viewDataSetModel(array $dataSetIDS)
+    {
+        // TODO: Implement viewDataSetModel() method.
+    }
+
+    public function addToConvertQueue(string $dataSetId): array
+    {
+        return [];
+    }
+}

+ 6 - 0
config/bim.php

@@ -11,5 +11,11 @@ return [
         'secret_key' => env("BLACK_HOLE_SECRET_KEY"),
         'user_id' => env("BLACK_HOLE_USER_ID"),
         'project_id' => env("BLACK_HOLE_PROJECT_ID"),
+    ],
+
+    'glendale' => [
+        'host' => env("GLENDALE_HOST", "http://106.53.68.51:9012/"),
+        'token' => env("GLENDALE_TOKEN"),
+        'project_id' => env("GLENDALE_PROJECT_ID"),
     ]
 ];