Skip to content

Commit

Permalink
feat: add dockerfile and demo program
Browse files Browse the repository at this point in the history
  • Loading branch information
martinalbert committed Oct 28, 2024
1 parent c6adb87 commit 70afe0a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:8.2-cli

WORKDIR /app
COPY . .

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install

ENV API_BASE_URL=https://api.buttercms.com/v2
ENV API_KEY=your_api_key

CMD ["php", "demo/demo.php"]
34 changes: 34 additions & 0 deletions demo/demo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

require_once 'vendor/autoload.php';

use ButterCMS\ButterCMS;

$apiKey = getenv('API_KEY');
if (empty($apiKey)) {
die("API_KEY environment variable is not set\n");
}

$client = new ButterCMS($apiKey);

try {
$params = ['preview' => 1];
$page = $client->fetchPage('*', 'test-page-1', $params);
echo "Page Slug: " . $page->getSlug() . "\n";
echo "Page Status: " . $page->getStatus() . "\n";
echo "Page Scheduled Date: " . $page->getScheduled() . "\n";
} catch (Exception $e) {
echo "Error fetching page: " . $e->getMessage() . "\n";
}

try {
$postResponse = $client->fetchPost('test-blog-post');
$post = $postResponse->getPost();
echo "Post Slug: " . $post->getSlug() . "\n";
echo "Post Status: " . $post->getStatus() . "\n";
echo "Post Scheduled Date: " . $post->getScheduled() . "\n";
} catch (Exception $e) {
echo "Error fetching post: " . $e->getMessage() . "\n";
}

?>

0 comments on commit 70afe0a

Please sign in to comment.