get(sprintf('sets/?search=%s', $setId)); $options = []; foreach ($response['results'] as $result) { $options[$result['set_num']] = $result['name']; } return $options; } /** * Get a specific set from its rebrickable ID */ public function getSet(string $setId) { return $this->get(sprintf('sets/%s/', $setId)); } /** * Get a specific theme from its rebrickable ID */ public function getTheme(string $themeId) { return $this->get(sprintf('themes/%s/', $themeId)); } /** * Return minifigs associated to the set */ public function getMinifigs(string $setId) { return $this->get(sprintf('sets/%s/minifigs/', $setId))['results']; } /** * Cache and return the result of a GET request */ private function get(string $url) { $key = $this->config['key']; $baseUrl = $this->config['base_url']; $cacheKey = sprintf('%s_%s', static::$cachePrefix, Str::slug($url)); if (Cache::has($cacheKey)) { return Cache::get($cacheKey); } $response = Http::throw() ->withHeader('Authorization', sprintf('key %s', $key)) ->get(sprintf('%s/%s', $baseUrl, $url))->json(); Cache::put($cacheKey, $response, now()->addDays(7)); return $response; } }