Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
arnebr authored and github-actions[bot] committed Feb 10, 2023
1 parent 608b68b commit 60cf5b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
6 changes: 3 additions & 3 deletions config/tibber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
return [
/* Get token from developer.tibber.com
*/
'api_url'=>'https://api.tibber.com/v1-beta/gql',
'token'=>env('TIBBER_TOKEN','5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE'),
'homeId'=>env('TIBBER_HOMEID',null)
'api_url' => 'https://api.tibber.com/v1-beta/gql',
'token' => env('TIBBER_TOKEN', '5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE'),
'homeId' => env('TIBBER_HOMEID', null),
];
35 changes: 24 additions & 11 deletions src/Tibber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,39 @@

namespace Arnebr\Tibber;

use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use PhpParser\Node\Expr\FuncCall;

class Tibber
{
public const HOURLY = 'HOURLY';

public const DAILY = 'DAILY';

public const WEEKLY = 'WEEKLY';

public const MONTHLY = 'MONTHLY';

public const ANNUAL = 'ANNUAL';

public const APP_HOME='HOME';
public const APP_CONSUMPTION='CONSUMPTION';
public const APP_METER_READING='METER_READING';
public const APP_COMPARISON='COMPARISON';
public const APP_HOME = 'HOME';

public const APP_CONSUMPTION = 'CONSUMPTION';

public const APP_METER_READING = 'METER_READING';

public const APP_COMPARISON = 'COMPARISON';

private function request($query): array
{

$client = Http::withHeaders([
'Content-Type' => 'application/json',
])->withToken(config('tibber.token'))->post(config('tibber.api_url'), [
'query' => $query
'query' => $query,
]);

return $client->json();
}

public function viewer($subquery = '')
{
$query = <<<GQL
Expand All @@ -43,11 +48,13 @@ public function viewer($subquery = '')
}
}
GQL;

return $this->request($query);
}

public function homes($homeId = null, $subquery = '')
{
$action = ($homeId === NULL) ? 'homes' : 'home(id:' . $homeId . ')';
$action = ($homeId === null) ? 'homes' : 'home(id:'.$homeId.')';
$subquery = <<<GQL
$action {
$subquery
Expand Down Expand Up @@ -137,8 +144,10 @@ public function homes($homeId = null, $subquery = '')
}
}
GQL;

return $this->viewer($subquery);
}

public function consumption($homeId = null, $resolution = Tibber::HOURLY, $last = 100)
{
$subquery = <<<GQL
Expand All @@ -154,9 +163,12 @@ public function consumption($homeId = null, $resolution = Tibber::HOURLY, $last
currency
}
GQL;
return $this->homes($homeId,$subquery);

return $this->homes($homeId, $subquery);
}
public function sendPushNotification(string $title,string $message, $screenToOpen=Tibber::APP_HOME){

public function sendPushNotification(string $title, string $message, $screenToOpen = Tibber::APP_HOME)
{
$subquery = <<<GQL
mutation{
sendPushNotification(input: {
Expand All @@ -170,6 +182,7 @@ public function sendPushNotification(string $title,string $message, $screenToOpe
}
GQL;

return $this->request($subquery);
}
}
2 changes: 1 addition & 1 deletion src/TibberServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Arnebr\Tibber;

use Arnebr\Tibber\Commands\TibberCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Arnebr\Tibber\Commands\TibberCommand;

class TibberServiceProvider extends PackageServiceProvider
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Arnebr\Tibber\Tests;

use Arnebr\Tibber\TibberServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;
use Arnebr\Tibber\TibberServiceProvider;

class TestCase extends Orchestra
{
Expand Down
23 changes: 11 additions & 12 deletions tests/TibberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
use Arnebr\Tibber\Facades\Tibber;

it('can make request', function () {
$tibber=Tibber::viewer();
expect($tibber)->toBeArray();
$tibber = Tibber::viewer();
expect($tibber)->toBeArray();
});

it('can make viewer request', function () {
$tibber=Tibber::viewer();
expect($tibber)->toBeArray();
$tibber = Tibber::viewer();
expect($tibber)->toBeArray();
});
it('can make home request', function () {
$tibber=Tibber::homes();
expect($tibber)->toBeArray();
$tibber = Tibber::homes();
expect($tibber)->toBeArray();
});
it('can make consumption request', function () {
$tibber=Tibber::consumption();
expect($tibber)->toBeArray();
$tibber = Tibber::consumption();
expect($tibber)->toBeArray();
});
it('can make push notification request', function () {
$tibber=Tibber::sendPushNotification('test','test');
expect($tibber)->toBeArray();
expect($tibber['errors'][0]['message'])->toBe('operation not allowed for demo user');
$tibber = Tibber::sendPushNotification('test', 'test');
expect($tibber)->toBeArray();
expect($tibber['errors'][0]['message'])->toBe('operation not allowed for demo user');
});

0 comments on commit 60cf5b3

Please sign in to comment.