1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: evert |
||
5 | * Date: 27/09/2017 |
||
6 | * Time: 09:38 |
||
7 | */ |
||
8 | |||
9 | namespace PragmaBroadvertising\SolarEdge\Models; |
||
10 | |||
11 | use Ixudra\Curl\Facades\Curl; |
||
12 | use PragmaBroadvertising\SolarEdge\Interfaces\ApiConnectorInterface; |
||
13 | |||
14 | class SolarEdgeClient implements ApiConnectorInterface |
||
15 | { |
||
16 | public function __construct() |
||
17 | { |
||
18 | $this->key = '?api_key=' . env('SOLAREDGE_API_KEY',''); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
19 | $this->id = env('SOLAREDGE_INSTALLATION_ID',''); |
||
0 ignored issues
–
show
|
|||
20 | $this->endpoint = env('SOLAREDGE_ENDPOINT','https://monitoringapi.solaredge.com/'); |
||
0 ignored issues
–
show
|
|||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Get from Site |
||
25 | * - endpoint |
||
26 | * - id |
||
27 | * - key |
||
28 | * @param $siteProperty |
||
29 | * @return mixed |
||
30 | */ |
||
31 | function getFromSite($siteProperty){ |
||
0 ignored issues
–
show
|
|||
32 | $request = Curl::to($this->endpoint . 'site/' . $this->id . '/' . $siteProperty . $this->key)->asJson()->get()->{$siteProperty}; |
||
33 | return $request; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Get from Site with start- and end date |
||
38 | * - endpoint |
||
39 | * - id |
||
40 | * - key |
||
41 | * - timeUnit |
||
42 | * - startDate |
||
43 | * - endDate |
||
44 | * - withTime |
||
45 | * @param $siteProperty |
||
46 | * @return mixed |
||
47 | */ |
||
48 | function getFromSiteWithStartAndEnd($siteProperty,$timeUnit,$startDate,$endDate,$withTime = false){ |
||
0 ignored issues
–
show
|
|||
49 | if(!$withTime) { |
||
50 | $request = |
||
51 | Curl::to($this->endpoint . 'site/' . $this->id . '/' . $siteProperty . |
||
52 | $this->key . |
||
53 | '&startDate=' . $startDate . |
||
54 | '&endDate=' . $endDate . |
||
55 | '&timeUnit=' . $timeUnit |
||
56 | )->asJson()->get()->{$siteProperty}; |
||
57 | } |
||
58 | else { |
||
59 | $request = |
||
60 | Curl::to($this->endpoint . 'site/' . $this->id . '/' . $siteProperty . |
||
61 | $this->key . |
||
62 | '&startTime=' . $startDate . |
||
63 | '&endTime=' . $endDate |
||
64 | )->asJson()->get()->{$siteProperty}; |
||
65 | } |
||
66 | |||
67 | return $request; |
||
68 | } |
||
69 | } |