Source Parsers
If you're pulling information in from an API, you may need to provide special headers to your API requests or use a certain part of the response body as your 'feed items'. This can't be done with the built-in 'source parsers', however you can build your own, extending on YumYum's built-in code.
Source Parsers look like so:
1<?php 2 3namespace App; 4 5use DoubleThreeDigital\YumYum\Feeds\Sources\JSON; 6use Illuminate\Support\Collection; 7use Illuminate\Support\Facades\Http; 8 9class CustomJsonSource extends JSON10{11 public function handle(): Collection12 {13 $response = Http::get($this->source['url']);14 15 return collect($response->json()['data']); // Here we're grabbing 'feed items' from inside the response's `data` array.16 }17}
The above example extends on the built-in JSON
source parser.
The handle
method is where all the important code should go. From it, you should return a collection of 'feed items' which will one by one be sent to Destination Transformers before being saved.