File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM php:8.2-cli
2+
3+ WORKDIR /app
4+ COPY . .
5+
6+ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
7+ RUN composer install
8+
9+ ENV API_BASE_URL=https://api.buttercms.com/v2
10+ ENV API_KEY=your_api_key
11+
12+ CMD ["php" , "demo/demo.php" ]
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ require_once 'vendor/autoload.php ' ;
4+
5+ use ButterCMS \ButterCMS ;
6+
7+ $ apiKey = getenv ('API_KEY ' );
8+ if (empty ($ apiKey )) {
9+ die ("API_KEY environment variable is not set \n" );
10+ }
11+
12+ $ client = new ButterCMS ($ apiKey );
13+
14+ try {
15+ $ params = ['preview ' => 1 ];
16+ $ page = $ client ->fetchPage ('* ' , 'test-page-1 ' , $ params );
17+ echo "Page Slug: " . $ page ->getSlug () . "\n" ;
18+ echo "Page Status: " . $ page ->getStatus () . "\n" ;
19+ echo "Page Scheduled Date: " . $ page ->getScheduled () . "\n" ;
20+ } catch (Exception $ e ) {
21+ echo "Error fetching page: " . $ e ->getMessage () . "\n" ;
22+ }
23+
24+ try {
25+ $ postResponse = $ client ->fetchPost ('test-blog-post ' );
26+ $ post = $ postResponse ->getPost ();
27+ echo "Post Slug: " . $ post ->getSlug () . "\n" ;
28+ echo "Post Status: " . $ post ->getStatus () . "\n" ;
29+ echo "Post Scheduled Date: " . $ post ->getScheduled () . "\n" ;
30+ } catch (Exception $ e ) {
31+ echo "Error fetching post: " . $ e ->getMessage () . "\n" ;
32+ }
33+
34+ ?>
You can’t perform that action at this time.
0 commit comments