summaryrefslogtreecommitdiff
path: root/src/Client.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client.php')
-rw-r--r--src/Client.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Client.php b/src/Client.php
new file mode 100644
index 0000000..255e29f
--- /dev/null
+++ b/src/Client.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace GeminiFoundation;
+
+use GeminiFoundation\Response;
+
+class Client
+{
+ protected string $baseUrl;
+
+ public function __construct($baseUrl)
+ {
+ $this->baseUrl = $baseUrl;
+ }
+
+ public function request($url): Response
+ {
+ $context = stream_context_create(options: [
+ 'ssl' => [
+ 'verify_peer' => false,
+ ],
+ ]);
+
+ $connection = stream_socket_client(
+ address: "tls://{$this->baseUrl}:1965",
+ context: $context
+ );
+
+ fwrite($connection, "gemini://{$this->baseUrl}{$url}");
+ $responseString = '';
+ while (!feof($connection)) {
+ $responseString .= fgets($connection, 1024);
+ }
+ fclose($connection);
+
+ $response = Response::fromString($responseString);
+
+ return $response;
+ }
+}