Skip to content

Commit

Permalink
Replace palcekitten with picsum
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative authored and bastianallgeier committed Dec 9, 2024
1 parent 6757261 commit fce8620
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 66 deletions.
2 changes: 1 addition & 1 deletion content/docs/1_guide/4_content/6_text-formatting/guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ You can even use KirbyTags in your templates with the (helper: kirbytag) helper,

### Extending KirbyText

You'd love to have a special tag for embedding cat pictures from [http://placekitten.com/](http://placekitten.com/) or you need some other tags for your next client project?
You'd love to have a special tag for embedding pictures from [https://picsum.photos](https://picsum.photos) or you need some other tags for your next client project?

(link: docs/reference/text/kirbytags text: KirbyText is extensible), so you can actually build in all the great features you need.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Text:

```php
<?php
$response = Remote::get('http://placekitten.com/200/300');
$response = Remote::get('https://picsum.photos/200/300');

// Do stuff depending on http code
// Codes and how you want to handle them depends on the API you are querying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Default parameters:

## Examples

In this example, we make a GET request to the free placekitten API, and write the content of the requested image to file:
In this example, we make a GET request to the picsum API, and write the content of the requested image to file:

```php
<?php
$targetPage = page('home');
$response = Remote::get('http://placekitten.com/200/300');
$response = Remote::get('https://picsum.photos/200/300');
if ($response->code() === 200) {
F::write($targetPage->root() . '/kitten.jpg', $response->content());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,39 @@ Text:

```php
<?php
$response = Remote::get('http://placekitten.com/200/300');
$response = Remote::get('https://picsum.photos/200/300');

dump($response->headers());

/** Example dump result
^ array:16 [▼
"Date" => "Sun, 16 Apr 2023 14:30:18 GMT"
"Content-Length" => "9339"
"Connection" => "keep-alive"
"Cache-Control" => "public, max-age=86400"
"Expires" => "Thu, 31 Dec 2020 20:00:00 GMT"
"Vary" => "User-Agent, Accept-Encoding"
"Access-Control-Allow-Origin" => "*"
"Last-Modified" => "Sat, 15 Apr 2023 06:23:28 GMT"
"CF-Cache-Status" => "HIT"
"Age" => "33423"
"Accept-Ranges" => "bytes"
"Report-To" => "{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=4vZQgs2oxA3eVVzIxTcmlUEIx7YIzwpzV1cfKjATuOXeGaE3Qn%2B1xz4sacdDLaGMzdz3lI46%2Be2FthD%2F%2B4Cww ▶"
"NEL" => "{"success_fraction":0,"report_to":"cf-nel","max_age":604800}"
"Server" => "cloudflare"
"CF-RAY" => "7b8d201da8023663-FRA"
"alt-svc" => "h3=":443"; ma=86400, h3-29=":443"; ma=86400"
]
Array
(
[date] => Sun, 08 Dec 2024 14:51:41 GMT
[location] => https://fastly.picsum.photos/id/122/200/300.jpg?hmac=OfQ8cObBgD7BOhMjqNrjqHDjO-rXiNQ4KvSd8QRAuIA
[cache-control] => public, max-age=2592000, stale-while-revalidate=60, stale-if-error=43200, immutable
[vary] => Origin
[cf-cache-status] => DYNAMIC
[report-to] => {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=qk209aXgTNMdqTg60OQLoE7MfAak3r5fVnkQIgutWnjv%2BHTfppun9WNEyNmhECjN%2B%2FvqP4MYwrXyl3TM%2FmqXw%2BuJlT0qsx8JM3kBrvItORnL75ik%2FB9HQyThynpfHHo%3D"}],"group":"cf-nel","max_age":604800}
[nel] => {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
[strict-transport-security] => max-age=15552000
[x-content-type-options] => nosniff
[server] => nginx
[cf-ray] => 8eed932c4ac9e532-TXL
[alt-svc] => h3=":443"; ma=86400
[server-timing] => cfL4;desc="?proto=TCP&rtt=17481&min_rtt=17081&rtt_var=5380&sent=5&recv=8&lost=0&retrans=0&sent_bytes=3407&recv_bytes=755&delivery_rate=148894&cwnd=192&unsent_bytes=0&cid=e9a40de35697703a&ts=77&x=0"
[content-type] => image/jpeg
[content-disposition] => inline; filename="122-200x300.jpg"
[picsum-id] => 122
[timing-allow-origin] => *
[accept-ranges] => bytes
[via] => 1.1 varnish
[age] => 1666153
[x-served-by] => cache-ams21055-AMS
[x-cache] => HIT
[x-cache-hits] => 3
[x-timer] => S1733669501.064267,VS0,VE0
[content-length] => 8346
)
*/
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,55 @@ Text:

```php
<?php
$response = Remote::get('http://placekitten.com/200/300');
$response = Remote::get('https://picsum.photos/200/300');

dump($response->info());

/**
* Example dump result
* array:38 [▼
"url" => "http://placekitten.com/200/300"
"content_type" => null
"http_code" => 200
"header_size" => 776
"request_size" => 85
"filetime" => -1
"ssl_verify_result" => 0
"redirect_count" => 0
"total_time" => 0.049741
"namelookup_time" => 0.006713
"connect_time" => 0.023869
"pretransfer_time" => 0.023992
"size_upload" => 0.0
"size_download" => 9339.0
"speed_download" => 187752.0
"speed_upload" => 0.0
"download_content_length" => 9339.0
"upload_content_length" => 0.0
"starttransfer_time" => 0.049533
"redirect_time" => 0.0
"redirect_url" => ""
"primary_ip" => "188.114.96.3"
"certinfo" => []
"primary_port" => 80
"local_ip" => "192.168.178.47"
"local_port" => 51030
"http_version" => 2
"protocol" => 1
"ssl_verifyresult" => 0
"scheme" => "HTTP"
"appconnect_time_us" => 0
"connect_time_us" => 23869
"namelookup_time_us" => 6713
"pretransfer_time_us" => 23992
"redirect_time_us" => 0
"starttransfer_time_us" => 49533
"total_time_us" => 49741
"effective_method" => "GET"
]
Array
(
[url] => https://fastly.picsum.photos/id/101/200/300.jpg?hmac=xUDvORQTxaML0fp9wnx4y6LIHvc7M-tNcOJz8rDLRXo
[content_type] => image/jpeg
[http_code] => 200
[header_size] => 1458
[request_size] => 269
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 0.31152
[namelookup_time] => 0.063239
[connect_time] => 0.107737
[pretransfer_time] => 0.187745
[size_upload] => 0
[size_download] => 9100
[speed_download] => 29211
[speed_upload] => 0
[download_content_length] => 9100
[upload_content_length] => 0
[starttransfer_time] => 0.306241
[redirect_time] => 0.171962
[redirect_url] =>
[primary_ip] => 111.222.33.44
[certinfo] => Array()
[primary_port] => 443
[local_ip] => 192.168.1.2
[local_port] => 61445
[http_version] => 3
[protocol] => 2
[ssl_verifyresult] => 0
[scheme] => https
[appconnect_time_us] => 187025
[connect_time_us] => 107737
[namelookup_time_us] => 63239
[pretransfer_time_us] => 187745
[redirect_time_us] => 171962
[starttransfer_time_us] => 306241
[total_time_us] => 311520
[effective_method] => GET
[capath] =>
[cainfo] => /etc/ssl/cert.pem
)
*/
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Default parameters:
$targetPage = page('notes')->children()->first();

$response = Remote::request(
'http://placekitten.com/200/300',
'https://picsum.photos/200/300',
[
'method' => 'GET',
]
);

// Save content from request to file
if ($response->code() === 200) {
F::write($targetPage->root() . '/kitten.jpg', $response->content());
F::write($targetPage->root() . '/photo.jpg', $response->content());
}
```

Expand Down

0 comments on commit fce8620

Please sign in to comment.