Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan committed Sep 20, 2023
1 parent 964c612 commit 2cc4e60
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions bridges/TwitchBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public function collectData()
'channel' => $channel,
'types' => self::BROADCAST_TYPES[$type]
];
$data = $this->apiRequest($query, $variables);
$response = $this->apiRequest($query, $variables);
$data = $response->data;
if ($data->user === null) {
throw new \Exception(sprintf('Unable to find channel `%s`', $channel));
}
Expand Down Expand Up @@ -205,37 +206,29 @@ private function formatQueryTime($seconds)
);
}

// GraphQL: https://graphql.org/
// Tool for developing/testing queries: https://github.com/skevy/graphiql-app
/**
* GraphQL: https://graphql.org/
* Tool for developing/testing queries: https://github.com/skevy/graphiql-app
*
* Official instructions for obtaining your own client ID can be found here:
* https://dev.twitch.tv/docs/v5/#getting-a-client-id
*/
private function apiRequest($query, $variables)
{
$request = [
'query' => $query,
'variables' => $variables
'query' => $query,
'variables' => $variables,
];
/**
* Official instructions for obtaining your own client ID can be found here:
* https://dev.twitch.tv/docs/v5/#getting-a-client-id
*/
$header = [
'Client-ID: kimne78kx3ncx6brgo4mv6wki5h1ko'
$headers = [
'Client-ID: kimne78kx3ncx6brgo4mv6wki5h1ko',
];
$opts = [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($request)
CURLOPT_POSTFIELDS => json_encode($request),
];

Logger::debug("Sending GraphQL query:\n" . $query);
Logger::debug("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
$response = json_decode(getContents('https://gql.twitch.tv/gql', $header, $opts));
Logger::debug("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));

if (isset($response->errors)) {
$messages = array_column($response->errors, 'message');
throw new \Exception(sprintf('twitch api: `%s`', implode("\n", $messages)));
}

return $response->data;
$json = getContents('https://gql.twitch.tv/gql', $headers, $opts);
$result = Json::decode($json, false);
return $result;
}

public function getName()
Expand Down

0 comments on commit 2cc4e60

Please sign in to comment.