-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dockerfile and demo program
- Loading branch information
1 parent
c6adb87
commit 70afe0a
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
?> |