--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Channel;
+use App\Models\TwitchToken;
+use GuzzleHttp\Psr7\Query;
+use Illuminate\Console\Command;
+use Illuminate\Http\Client\RequestException;
+use Illuminate\Support\Facades\Http;
+
+class TwitchChannelClips extends Command {
+
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'twitch:clips {name}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Fetch twitch channel clips';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $this->token = TwitchToken::firstWhere('nick', 'localhorsttv');
+ if (!$this->token) {
+ $this->line('please acquire a token for localhorsttv first');
+ return 1;
+ }
+ if ($this->token->hasExpired()) {
+ $this->line('access token has expired, refreshing');
+ $this->token->refresh();
+ }
+ $channel = Channel::where('title', '=', $this->argument('name'))->firstOrFail();
+ $clips = $this->fetchClips($channel);
+ foreach ($clips as $clip) {
+ var_dump($clip);
+ }
+ return Command::SUCCESS;
+ }
+
+ private function fetchClips(Channel $channel) {
+ $this->line($channel->twitch_chat);
+ $rsp = $this->token->request()
+ ->get('/clips', Query::build([
+ 'first' => 100,
+ 'broadcaster_id' => $channel->twitch_id,
+ ]))
+ ->throw();
+ return $rsp['data'];
+ }
+
+ private $token;
+
+}