urlDevelopment; } else { $default = $this->urlProduction; } $this->client = new Client([ 'base_uri' => $default, 'connect_timeout' => 5, 'timeout' => 15, ]); } public function bukuAjar(string $nip, int $periode, ?int $limit = 1, ?string $status = 'Diterima') { try { $url = "api/v1/buku/pengajuan/$nip?kategori=Buku Ajar&periode=$periode"; if ($status !== null) { $url .= "&status=$status"; } $response = $this->client->get($url); $data = json_decode($response->getBody()->getContents(), true); $data = collect($data['data'])->sortByDesc('poin'); if ($limit) { $data = $data->take($limit); } return $data; } catch (Throwable $th) { Log::info("Insentif ($nip): ".$th->getMessage()); throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500); } } public function modulAjar(string $nip, int $periode, ?int $limit = 2, ?string $status = 'Diterima') { // API Insentif modul ajar sudah tidak terpakai lagi, return empty collection (poin 0) return collect([]); } public function publikasi(string $type, string $nip, int $periode = 386) { try { $response = $this->client->get("api/$type/$nip/$periode"); $data = json_decode($response->getBody()->getContents(), true); return collect($data['data']); } catch (Throwable $th) { Log::info("Insentif ($nip): ".$th->getMessage()); throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500); } } public function cekData(string $nip) { try { $response = $this->client->get("api/v1/perhitungan/$nip"); $data = json_decode($response->getBody()->getContents(), true); return collect($data); } catch (Throwable $th) { Log::info("Insentif ($nip): ".$th->getMessage()); throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500); } } public function verifikasiBukuAjar(string $unique, string $action, string $nip, ?string $note = null): array { try { $url = "api/v1/buku/verifikasi/$unique/$action"; $body = [ 'kategori' => 'buku-ajar', 'nip' => $nip, 'apps' => 'Verifikator', ]; if ($note !== null) { $body['note'] = $note; } $response = $this->client->put($url, [ 'json' => $body, 'http_errors' => false, ]); return [ '_http_status' => $response->getStatusCode(), 'data' => json_decode($response->getBody()->getContents(), true) ?? [], ]; } catch (Throwable $th) { Log::info("Insentif verifikasi buku ajar ($unique/$action): ".$th->getMessage()); throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500); } } public function jurnal(string $nip, ?int $periode = null) { try { if ($periode === null) { $periode = Periode::where('status', true)->first()->id_periode; } $response = $this->client->get("api/v1/jurnal/pengajuan/$nip?periode=$periode"); $data = json_decode($response->getBody()->getContents(), true); return collect($data['data']); } catch (Throwable $th) { Log::info("Insentif ($nip): ".$th->getMessage()); throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500); } } }