2
2
3
3
namespace Arnebr \Tibber ;
4
4
5
- use Illuminate \Http \Client \Response ;
6
5
use Illuminate \Support \Facades \Http ;
7
- use PhpParser \Node \Expr \FuncCall ;
8
6
9
7
class Tibber
10
8
{
11
9
public const HOURLY = 'HOURLY ' ;
10
+
12
11
public const DAILY = 'DAILY ' ;
12
+
13
13
public const WEEKLY = 'WEEKLY ' ;
14
+
14
15
public const MONTHLY = 'MONTHLY ' ;
16
+
15
17
public const ANNUAL = 'ANNUAL ' ;
16
18
17
- public const APP_HOME ='HOME ' ;
18
- public const APP_CONSUMPTION ='CONSUMPTION ' ;
19
- public const APP_METER_READING ='METER_READING ' ;
20
- public const APP_COMPARISON ='COMPARISON ' ;
19
+ public const APP_HOME = 'HOME ' ;
20
+
21
+ public const APP_CONSUMPTION = 'CONSUMPTION ' ;
22
+
23
+ public const APP_METER_READING = 'METER_READING ' ;
24
+
25
+ public const APP_COMPARISON = 'COMPARISON ' ;
21
26
22
27
private function request ($ query ): array
23
28
{
24
-
25
29
$ client = Http::withHeaders ([
26
30
'Content-Type ' => 'application/json ' ,
27
31
])->withToken (config ('tibber.token ' ))->post (config ('tibber.api_url ' ), [
28
- 'query ' => $ query
32
+ 'query ' => $ query,
29
33
]);
30
34
31
35
return $ client ->json ();
32
36
}
37
+
33
38
public function viewer ($ subquery = '' )
34
39
{
35
40
$ query = <<<GQL
@@ -43,11 +48,13 @@ public function viewer($subquery = '')
43
48
}
44
49
}
45
50
GQL ;
51
+
46
52
return $ this ->request ($ query );
47
53
}
54
+
48
55
public function homes ($ homeId = null , $ subquery = '' )
49
56
{
50
- $ action = ($ homeId === NULL ) ? 'homes ' : 'home(id: ' . $ homeId . ') ' ;
57
+ $ action = ($ homeId === null ) ? 'homes ' : 'home(id: ' . $ homeId. ') ' ;
51
58
$ subquery = <<<GQL
52
59
$ action {
53
60
$ subquery
@@ -137,8 +144,10 @@ public function homes($homeId = null, $subquery = '')
137
144
}
138
145
}
139
146
GQL ;
147
+
140
148
return $ this ->viewer ($ subquery );
141
149
}
150
+
142
151
public function consumption ($ homeId = null , $ resolution = Tibber::HOURLY , $ last = 100 )
143
152
{
144
153
$ subquery = <<<GQL
@@ -154,9 +163,12 @@ public function consumption($homeId = null, $resolution = Tibber::HOURLY, $last
154
163
currency
155
164
}
156
165
GQL ;
157
- return $ this ->homes ($ homeId ,$ subquery );
166
+
167
+ return $ this ->homes ($ homeId , $ subquery );
158
168
}
159
- public function sendPushNotification (string $ title ,string $ message , $ screenToOpen =Tibber::APP_HOME ){
169
+
170
+ public function sendPushNotification (string $ title , string $ message , $ screenToOpen = Tibber::APP_HOME )
171
+ {
160
172
$ subquery = <<<GQL
161
173
mutation{
162
174
sendPushNotification(input: {
@@ -170,6 +182,7 @@ public function sendPushNotification(string $title,string $message, $screenToOpe
170
182
}
171
183
172
184
GQL ;
185
+
173
186
return $ this ->request ($ subquery );
174
187
}
175
188
}
0 commit comments