Skip to content

Commit 8b7c517

Browse files
authored
Merge branch 'main' of https://github.com/arnebr/laravel-tibber into main
2 parents 3e6bb56 + 60cf5b3 commit 8b7c517

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

config/tibber.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
return [
55
/* Get token from developer.tibber.com
66
*/
7-
'api_url'=>'https://api.tibber.com/v1-beta/gql',
8-
'token'=>env('TIBBER_TOKEN','5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE'),
9-
'homeId'=>env('TIBBER_HOMEID',null)
7+
'api_url' => 'https://api.tibber.com/v1-beta/gql',
8+
'token' => env('TIBBER_TOKEN', '5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE'),
9+
'homeId' => env('TIBBER_HOMEID', null),
1010
];

src/Tibber.php

+24-11
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,39 @@
22

33
namespace Arnebr\Tibber;
44

5-
use Illuminate\Http\Client\Response;
65
use Illuminate\Support\Facades\Http;
7-
use PhpParser\Node\Expr\FuncCall;
86

97
class Tibber
108
{
119
public const HOURLY = 'HOURLY';
10+
1211
public const DAILY = 'DAILY';
12+
1313
public const WEEKLY = 'WEEKLY';
14+
1415
public const MONTHLY = 'MONTHLY';
16+
1517
public const ANNUAL = 'ANNUAL';
1618

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';
2126

2227
private function request($query): array
2328
{
24-
2529
$client = Http::withHeaders([
2630
'Content-Type' => 'application/json',
2731
])->withToken(config('tibber.token'))->post(config('tibber.api_url'), [
28-
'query' => $query
32+
'query' => $query,
2933
]);
3034

3135
return $client->json();
3236
}
37+
3338
public function viewer($subquery = '')
3439
{
3540
$query = <<<GQL
@@ -43,11 +48,13 @@ public function viewer($subquery = '')
4348
}
4449
}
4550
GQL;
51+
4652
return $this->request($query);
4753
}
54+
4855
public function homes($homeId = null, $subquery = '')
4956
{
50-
$action = ($homeId === NULL) ? 'homes' : 'home(id:' . $homeId . ')';
57+
$action = ($homeId === null) ? 'homes' : 'home(id:'.$homeId.')';
5158
$subquery = <<<GQL
5259
$action {
5360
$subquery
@@ -137,8 +144,10 @@ public function homes($homeId = null, $subquery = '')
137144
}
138145
}
139146
GQL;
147+
140148
return $this->viewer($subquery);
141149
}
150+
142151
public function consumption($homeId = null, $resolution = Tibber::HOURLY, $last = 100)
143152
{
144153
$subquery = <<<GQL
@@ -154,9 +163,12 @@ public function consumption($homeId = null, $resolution = Tibber::HOURLY, $last
154163
currency
155164
}
156165
GQL;
157-
return $this->homes($homeId,$subquery);
166+
167+
return $this->homes($homeId, $subquery);
158168
}
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+
{
160172
$subquery = <<<GQL
161173
mutation{
162174
sendPushNotification(input: {
@@ -170,6 +182,7 @@ public function sendPushNotification(string $title,string $message, $screenToOpe
170182
}
171183
172184
GQL;
185+
173186
return $this->request($subquery);
174187
}
175188
}

src/TibberServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Arnebr\Tibber;
44

5+
use Arnebr\Tibber\Commands\TibberCommand;
56
use Spatie\LaravelPackageTools\Package;
67
use Spatie\LaravelPackageTools\PackageServiceProvider;
7-
use Arnebr\Tibber\Commands\TibberCommand;
88

99
class TibberServiceProvider extends PackageServiceProvider
1010
{

tests/TestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Arnebr\Tibber\Tests;
44

5+
use Arnebr\Tibber\TibberServiceProvider;
56
use Illuminate\Database\Eloquent\Factories\Factory;
67
use Orchestra\Testbench\TestCase as Orchestra;
7-
use Arnebr\Tibber\TibberServiceProvider;
88

99
class TestCase extends Orchestra
1010
{

tests/TibberTest.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@
33
use Arnebr\Tibber\Facades\Tibber;
44

55
it('can make request', function () {
6-
$tibber=Tibber::viewer();
7-
expect($tibber)->toBeArray();
6+
$tibber = Tibber::viewer();
7+
expect($tibber)->toBeArray();
88
});
99

1010
it('can make viewer request', function () {
11-
$tibber=Tibber::viewer();
12-
expect($tibber)->toBeArray();
11+
$tibber = Tibber::viewer();
12+
expect($tibber)->toBeArray();
1313
});
1414
it('can make home request', function () {
15-
$tibber=Tibber::homes();
16-
expect($tibber)->toBeArray();
15+
$tibber = Tibber::homes();
16+
expect($tibber)->toBeArray();
1717
});
1818
it('can make consumption request', function () {
19-
$tibber=Tibber::consumption();
20-
expect($tibber)->toBeArray();
19+
$tibber = Tibber::consumption();
20+
expect($tibber)->toBeArray();
2121
});
2222
it('can make push notification request', function () {
23-
$tibber=Tibber::sendPushNotification('test','test');
24-
expect($tibber)->toBeArray();
25-
expect($tibber['errors'][0]['message'])->toBe('operation not allowed for demo user');
23+
$tibber = Tibber::sendPushNotification('test', 'test');
24+
expect($tibber)->toBeArray();
25+
expect($tibber['errors'][0]['message'])->toBe('operation not allowed for demo user');
2626
});
27-

0 commit comments

Comments
 (0)