Skip to content

Commit f6172dd

Browse files
author
Vinlock
committed
Added bio(), created_at(), updated_at(), followers().
1 parent 3ae30a8 commit f6172dd

File tree

5 files changed

+99
-10
lines changed

5 files changed

+99
-10
lines changed

Diff for: src/Services/Service.php

-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ public function getObject() {
5151
return (object) $this->getArray();
5252
}
5353

54-
public static function sortViewers(&$streams) {
55-
usort($streams, function($a, $b) {
56-
return $b->viewers - $a->viewers;
57-
});
58-
}
59-
6054
public function sort() {
6155
usort($this->streams, function($a, $b) {
6256
return $b->viewers - $a->viewers;

Diff for: src/StreamInterface.php

+13
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,17 @@ function id();
8888
*/
8989
function avatar();
9090

91+
/**
92+
* Stream Bio
93+
*
94+
* @return mixed
95+
*/
96+
function bio();
97+
98+
function created_at();
99+
100+
function updated_at();
101+
102+
function followers();
103+
91104
}

Diff for: src/StreamObjects/Hitbox.php

+17
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,21 @@ public function avatar() {
132132
return self::STREAM_IMG.stripcslashes($this->stream['channel']['user_logo']);
133133
}
134134

135+
public function bio() {
136+
return "";
137+
}
138+
139+
public function created_at() {
140+
return $this->stream['media_date_added'];
141+
}
142+
143+
public function updated_at() {
144+
return $this->stream['media_live_since'];
145+
}
146+
147+
public function followers() {
148+
return $this->stream['channel']['followers'];
149+
}
150+
151+
135152
}

Diff for: src/StreamObjects/Stream.php

+51-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ abstract class Stream {
2626

2727
protected $service;
2828

29+
protected $time_format = "m-d-Y H:i:s";
30+
2931
/**
3032
* Append Stream Service to ID
3133
*
@@ -44,8 +46,8 @@ abstract class Stream {
4446

4547
protected $customMembers = [];
4648

47-
protected function stream() {
48-
return [
49+
protected function stream($date_format = TRUE) {
50+
$result = [
4951
"username" => $this->username(),
5052
"display_name" => $this->display_name(),
5153
"game" => $this->game(),
@@ -55,12 +57,24 @@ protected function stream() {
5557
"large" => $this->largePreview()
5658
],
5759
"status" => $this->status(),
60+
"bio" =>$this->bio(),
5861
"url" => $this->url(),
5962
"viewers" => $this->viewers(),
6063
"id" => $this->id(),
6164
"avatar" => $this->avatar(),
62-
"service" => $this->service
65+
"service" => $this->service,
66+
"followers" => $this->followers()
6367
];
68+
if ($date_format === TRUE) {
69+
$result['created_at'] = $this->created_at()->format($this->time_format);
70+
$result['updated_at'] = $this->updated_at()->format($this->time_format);
71+
} elseif ($date_format) {
72+
$result['created_at'] = $this->created_at()->format($date_format);
73+
$result['updated_at'] = $this->updated_at()->format($date_format);
74+
} else {
75+
$result['created_at'] = $this->created_at();
76+
$result['updated_at'] = $this->updated_at();
77+
}
6478
}
6579

6680
/**
@@ -149,6 +163,13 @@ public function preview($size = "large") {
149163
}
150164
}
151165

166+
public static function FilterBio($bio) {
167+
// Filter the Bio of all bad characters.
168+
$bio = preg_replace("/\r|\n/", "", html_entity_decode(
169+
htmlspecialchars($bio), ENT_QUOTES));
170+
return $bio;
171+
}
172+
152173
/**
153174
* Stream Username
154175
*
@@ -226,6 +247,33 @@ abstract public function id();
226247
*/
227248
abstract public function avatar();
228249

250+
/**
251+
* Stream Bio
252+
*
253+
* @return mixed
254+
*/
255+
abstract public function bio();
256+
257+
/**
258+
* When the Stream User made account.
259+
*
260+
* @return \DateTime
261+
*/
262+
abstract public function created_at();
263+
264+
/**
265+
* When stream was last updated.
266+
*
267+
* @return \DateTime
268+
*/
269+
abstract public function updated_at();
270+
271+
/**
272+
* Number of stream followers
273+
*
274+
* @return integer
275+
*/
276+
abstract public function followers();
229277

230278

231279
}

Diff for: src/StreamObjects/Twitch.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function viewers() {
118118
* @return string
119119
*/
120120
public function id() {
121-
return $this->stream['_id'];
121+
return $this->stream['channel']['_id'];
122122
}
123123

124124
/**
@@ -131,5 +131,22 @@ public function avatar() {
131131
return (is_null($avatar)) ? self::DEFAULT_AVATAR : $avatar;
132132
}
133133

134+
public function bio() {
135+
$json = json_decode(\Requests::get(self::USERS_API.$this->username())->body);
136+
return self::FilterBio($json['bio']);
137+
}
138+
139+
public function created_at() {
140+
return new \DateTime($this->stream['created_at']);
141+
}
142+
143+
public function updated_at() {
144+
return new \DateTime($this->stream['updated_at']);
145+
}
146+
147+
public function followers() {
148+
return $this->stream['channel']['followers'];
149+
}
150+
134151

135152
}

0 commit comments

Comments
 (0)