Skip to content

Commit 9afd698

Browse files
authored
Merge pull request #61 from Kriper1111/master
2 parents 34e696b + 6c7ecf5 commit 9afd698

4 files changed

Lines changed: 60 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Homestead.json
77
/access.log
88
/error.log
99
.phpintel
10-
.idea
10+
.idea
11+
.vscode

app/Http/Controllers/TwitchController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ public function subEmotes(Request $request, $channel = null)
18331833
{
18341834
$channel = $channel ?: $request->input('channel', null);
18351835
$wantsJson = (($request->wantsJson() || $request->exists('json')) ? true : false);
1836+
$wantsPlans = ($request->exists('tiers') && $wantsJson);
18361837
$id = $request->input('id', 'false');
18371838

18381839
if (empty($channel)) {
@@ -1913,6 +1914,20 @@ public function subEmotes(Request $request, $channel = null)
19131914
}
19141915

19151916
// We only care about the emote codes.
1917+
// or do we?
1918+
if ($wantsPlans) {
1919+
$plans = $emotes['plans'];
1920+
$emotesData = $emotes['emotes'];
1921+
$emotesTiers = $plans->sortEmotes($emotesData);
1922+
return $this->json([
1923+
'emotes' => [
1924+
'tier1' => $emotesTiers['$4.99'],
1925+
'tier2' => $emotesTiers['$9.99'],
1926+
'tier3' => $emotesTiers['$24.99'],
1927+
],
1928+
]);
1929+
}
1930+
19161931
$emotes = $emotes['emotes'];
19171932
$emoteCodes = $emotes->codes();
19181933

app/Http/Resources/TwitchEmotes/Channel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function toArray($request)
1717
$res = $this->resource;
1818

1919
$emotes = EmotesCollection::make(collect($res['emotes']));
20+
$plans = Plans::make($res['plans']);
2021

2122
return [
2223
'name' => $res['channel_name'],
@@ -27,7 +28,7 @@ public function toArray($request)
2728
'generated_at' => $res['generated_at'],
2829

2930
'emotes' => $emotes,
30-
'plans' => $res['plans'],
31+
'plans' => $plans,
3132
'badges' => [
3233
'subscribers' => $res['subscriber_badges'] ?? null,
3334
'bits' => $res['bits_badges'] ?? null,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Resources\TwitchEmotes;
4+
5+
use Illuminate\Http\Resources\Json\ResourceCollection;
6+
7+
class Plans extends ResourceCollection
8+
{
9+
// Should convert the resource into an array
10+
public function toArray($request)
11+
{
12+
$res = $this->resource;
13+
14+
return [
15+
'tier1' => $res['$4.99'],
16+
'tier2' => $res['$9.99'],
17+
'tier3' => $res['$24.99'],
18+
];
19+
}
20+
21+
/**
22+
* Sorts emotes by their tier, returns them as an array
23+
*
24+
* @param array $emotes
25+
* @return array
26+
*/
27+
public function sortEmotes($emotes)
28+
{
29+
return $this->collection
30+
->map(function($plans) use($emotes){
31+
$accumulator = [];
32+
foreach ($emotes as $emote){
33+
if ((string) $emote['emoticon_set'] === $plans){
34+
array_push($accumulator, $emote['code']);
35+
};
36+
}
37+
return($accumulator);
38+
})
39+
->toArray();
40+
}
41+
}

0 commit comments

Comments
 (0)