@section('title', __('radio.menu_item_5_sub_5')) @section('head') @endsection @php $breadcrumb = [ ['label' => __('general.header_nav_radio')], ['label' => __('radio.menu_item_5_sub_5')], ]; $tokenRow = $getTokenAuth->first(); $hasToken = $tokenRow !== null; $tokenMask = $hasToken ? str_repeat('*', 32) : null; /* the plain token is never stored: after it is generated the screen can only say when it was made and used */ $tokenCreated = $hasToken && $tokenRow->created_at ? DateShort($tokenRow->created_at) : null; $tokenUsed = $hasToken && $tokenRow->last_used_at ? DateShort($tokenRow->last_used_at) : null; $v1EndsAt = '2027-01-01'; $v1EndsAtLabel = \Carbon\Carbon::parse($v1EndsAt)->format('d/m/Y'); $limitTotal = max(1, (int) $userLogged->limit_total); $limitUsed = (int) $userLogged->limit_used; $limitPct = min(100, round($limitUsed * 100 / $limitTotal)); $limitState = $limitPct <= 70 ? 'ok' : ($limitPct <= 94 ? 'warn' : 'crit'); $endpoint = rtrim(config('app.url'), '/') . '/api/v2/radio/data'; /* v1 address: the encrypted part is rewritten because a raw slash in it breaks the route */ $endpointV1 = rtrim(config('app.url'), '/') . '/api/radio/data/' . session('siteID') . '/' . str_replace('/', '|brasbar', EncryptBras($siteData->domain . '|' . $streamData->port)); $sampleToken = __('radio.api_token_placeholder'); $samples = [ 'curl' => 'cURL', 'php' => 'PHP', 'js' => 'JavaScript', 'python' => 'Python', ]; $code = []; $code['curl'] = 'curl -X GET "' . $endpoint . '" \ -H "Authorization: Bearer ' . $sampleToken . '" \ -H "Accept: application/json"'; $code['php'] = '$ch = curl_init(\'' . $endpoint . '\'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ \'Authorization: Bearer ' . $sampleToken . '\', \'Accept: application/json\', ]); $data = json_decode(curl_exec($ch), true); curl_close($ch); echo $data[\'onair\'][\'current_music\'];'; $code['js'] = 'const res = await fetch(\'' . $endpoint . '\', { headers: { Authorization: \'Bearer ' . $sampleToken . '\', Accept: \'application/json\' } }); const data = await res.json(); console.log(data.onair.current_music);'; $code['python'] = 'import requests res = requests.get(\'' . $endpoint . '\', headers={ \'Authorization\': \'Bearer ' . $sampleToken . '\', \'Accept\': \'application/json\', }) print(res.json()[\'onair\'][\'current_music\'])'; /* the v1 samples change only the address: the header and the reading stay as they are documented today */ $codeV1 = []; foreach ($code as $key => $sample) { $codeV1[$key] = str_replace([$endpoint, '[\'onair\']', '.onair.'], [$endpointV1, '[\'onair_data\']', '.onair_data.'], $sample); } $sampleResponse = '{ "status": "success", "station": { "name": "' . __('radio.api_sample_radio_name') . '", "domain": "' . ($siteData->domain ?: 'suaradio.com.br') . '", "port": ' . (int) $streamData->port . ' }, "plan": { "listeners": 1000, "bitrate": 128 }, "listeners": { "current": 25, "peak": 200 }, "onair": { "current_music": "' . __('radio.api_sample_current') . '", "next_music": "' . __('radio.api_sample_next') . '", "codec": "aac", "bitrate": 128 }, "limit": { "used": 132, "total": 5000 } }'; $sampleResponseV1 = '{ "status": "success", "plan": { "radio_name": "' . __('radio.api_sample_radio_name') . '", "listeners": 1000, "bitrate": 128 }, "listeners": { "current": "25", "peak": "200" }, "onair_data": { "current_music": "' . __('radio.api_sample_current') . '", "next_music": "' . __('radio.api_sample_next') . '", "stream_data": { "codec": "aac", "bitrate": "128" } } }'; $sampleError = '{ "status": "error", "error": { "code": "stream_unreachable", "message": "The streaming server did not answer." } }'; $sampleErrorV1 = '{ "status": "error", "data": { "error_code": 403, "message": "Access denied" } }'; $authHeaders = [ ['Authorization', 'Bearer ' . $sampleToken], ['Accept', 'application/json'], ]; $responseFields = [ ['status', __('radio.api_field_status'), __('radio.api_type_text'), 'success | error'], ['station.name', __('radio.api_field_radio_name'), __('radio.api_type_text'), 'Rádio Brascast'], ['station.domain', __('radio.api_field_station_domain'), __('radio.api_type_text'), 'suaradio.com.br'], ['station.port', __('radio.api_field_station_port'), __('radio.api_type_number'), '8000'], ['plan.listeners', __('radio.api_field_plan_listeners'), __('radio.api_type_number'), '1000'], ['plan.bitrate', __('radio.api_field_plan_bitrate'), __('radio.api_type_number'), '128'], ['listeners.current', __('radio.api_field_listeners_current'), __('radio.api_type_number'), '25'], ['listeners.peak', __('radio.api_field_listeners_peak'), __('radio.api_type_number'), '200'], ['onair.current_music', __('radio.api_field_current_music'), __('radio.api_type_text'), __('radio.api_format_audio_name')], ['onair.next_music', __('radio.api_field_next_music'), __('radio.api_type_text'), __('radio.api_format_audio_name')], ['onair.codec', __('radio.api_field_codec'), __('radio.api_type_text'), 'aac'], ['onair.bitrate', __('radio.api_field_bitrate'), __('radio.api_type_number'), '128'], ['limit.used', __('radio.api_field_limit_used'), __('radio.api_type_number'), '132'], ['limit.total', __('radio.api_field_limit_total'), __('radio.api_type_number'), '5000'], ]; $responseFieldsV1 = [ ['status', __('radio.api_field_status'), __('radio.api_type_text'), 'success | error'], ['plan.radio_name', __('radio.api_field_radio_name'), __('radio.api_type_text'), 'Rádio Brascast'], ['plan.listeners', __('radio.api_field_plan_listeners'), __('radio.api_type_number'), '1000'], ['plan.bitrate', __('radio.api_field_plan_bitrate'), __('radio.api_type_number'), '128'], ['listeners.current', __('radio.api_field_listeners_current'), __('radio.api_type_number'), '25'], ['listeners.peak', __('radio.api_field_listeners_peak'), __('radio.api_type_number'), '200'], ['onair_data.current_music', __('radio.api_field_current_music'), __('radio.api_type_text'), __('radio.api_format_audio_name')], ['onair_data.next_music', __('radio.api_field_next_music'), __('radio.api_type_text'), __('radio.api_format_audio_name')], ['onair_data.stream_data.codec', __('radio.api_field_codec'), __('radio.api_type_text'), 'aac'], ['onair_data.stream_data.bitrate', __('radio.api_field_bitrate'), __('radio.api_type_number'), '128'], ]; $errorCodes = [ ['200', 'ok', __('radio.api_error_200'), __('radio.api_error_200_fix')], ['401', 'crit', __('radio.api_error_401'), __('radio.api_error_401_fix')], ['403', 'crit', __('radio.api_error_403_v2'), __('radio.api_error_403_v2_fix')], ['429', 'warn', __('radio.api_error_429'), __('radio.api_error_429_fix')], ['502', 'warn', __('radio.api_error_502'), __('radio.api_error_502_fix')], ]; $errorCodesV1 = [ ['200', 'ok', __('radio.api_error_200'), __('radio.api_error_200_fix')], ['402', 'warn', __('radio.api_error_402'), __('radio.api_error_402_fix')], ['403', 'crit', __('radio.api_error_403'), __('radio.api_error_403_fix')], ]; $steps = [ ['fa-key', __('radio.api_step_1_title'), __('radio.api_step_1_text')], ['fa-paper-plane', __('radio.api_step_2_title'), __('radio.api_step_2_text')], ['fa-code', __('radio.api_step_3_title'), __('radio.api_step_3_text')], ]; $tabs = [ ['start', 'fa-rocket', __('radio.api_tab_start'), __('radio.api_tab_start_desc')], ['auth', 'fa-key', __('radio.api_tab_auth'), __('radio.api_tab_auth_desc')], ['data', 'fa-list', __('radio.api_tab_data'), __('radio.api_tab_data_desc')], ['errors', 'fa-circle-xmark', __('radio.api_tab_errors'), __('radio.api_tab_errors_desc')], ['v1', 'fa-clock-rotate-left', __('radio.api_tab_v1'), __('radio.api_tab_v1_desc', ['date' => $v1EndsAtLabel])], ['faq', 'fa-circle-question', 'FAQ', __('radio.api_tab_faq_desc')], ]; $faq = [ [__('radio.api_faq_q1'), __('radio.api_faq_a1')], [__('radio.api_faq_q2'), __('radio.api_faq_a2')], [__('radio.api_faq_q3'), __('radio.api_faq_a3')], [__('radio.api_faq_q4'), __('radio.api_faq_a4')], ]; @endphp @include('includes/header-novo')
@include('includes.breadcrumb') @include('includes.flash')

{{ __('radio.menu_item_5_sub_5') }}

{{ __('radio.api_page_sub') }}

{{ __('radio.api_v1_deprecated', ['date' => $v1EndsAtLabel]) }}

{{ __('radio.api_token_limits_title') }}

Auth Token
{{ $hasToken ? $tokenMask : __('radio.api_token_none') }} {{-- só o token recém-gerado pode ser copiado: do gravado existe apenas o hash --}}

{{ __('radio.api_token_help') }}

@if($hasToken)

{{ __('radio.api_token_created', ['date' => $tokenCreated]) }} · {{ $tokenUsed ? __('radio.api_token_last_used', ['date' => $tokenUsed]) : __('radio.api_token_never_used') }}

@endif

{{ __('radio.api_token_once') }}

{{ __('radio.api_daily_limit') }}

{{ number_format($limitUsed, 0, ',', '.') }} / {{ number_format($limitTotal, 0, ',', '.') }}

{{ $limitPct }}% {{ __('radio.api_limit_reset') }}

{{ __('radio.api_start_title') }}

{{ __('radio.api_start_intro') }}

    @foreach($steps as $index => $step)
  1. {{ $index + 1 }} {{ $step[1] }} {{ $step[2] }}
  2. @endforeach
@foreach($samples as $key => $label) @endforeach
@foreach($code as $key => $sample) @endforeach

{{ __('radio.api_start_tip') }}

@section('scripts') @endsection @include('includes/footer-novo')