Skip to content

Commit 20e0a87

Browse files
committed
API 4.0
1 parent e2b6ba5 commit 20e0a87

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Looker PHP SDK Advanced
22

3-
API version: 3.1.0
3+
API version: 4.0
44

55
This package is an advanced version of generated [Looker PHP SDK](https://github.com/alexkart/looker-php-sdk).
66
It adds additional functionality and simplifies the work with the Looker API. You can interact with the whole API
@@ -80,9 +80,10 @@ $looker = new \Alexkart\Looker\Looker($config);
8080
```
8181
The access token you provided will be used until it is valid and when it expires a new token will be
8282
requested automatically. You can check if the token has been renewed like this:
83+
8384
```php
84-
if ($looker->getConfig()->isAccessTokenRenewed()) {
85-
$token = $looker->getConfig()->getAccessToken();
85+
if ($looker->getLookerConfig()->isAccessTokenRenewed()) {
86+
$token = $looker->getLookerConfig()->getAccessToken();
8687
}
8788
```
8889
If you want the access token to be stored into the persistent storage (database, cache, file, etc.)

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
}
1818
},
1919
"require": {
20-
"alexkart/looker-php-sdk": "^0.1.0"
20+
"php": ">=8.1",
21+
"alexkart/looker-php-sdk": "0.2.*"
2122
},
2223
"require-dev": {
2324
"phpunit/phpunit": "^9.5",

examples/basic.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
$dotenv = Dotenv::createImmutable(__DIR__);
88
$dotenv->load();
99

10-
$config = new \Alexkart\Looker\LookerConfiguration(
10+
$lookerConfig = new \Alexkart\Looker\LookerConfiguration(
1111
$_SERVER['LOOKER_HOST'],
1212
$_SERVER['LOOKER_CLIENT_ID'],
1313
$_SERVER['LOOKER_CLIENT_SECRET'],
1414
$_SERVER['LOOKER_ACCESS_TOKEN']
1515
);
16-
$looker = new \Alexkart\Looker\Looker($config);
16+
$clientConfig = [
17+
'verify' => false, // disable SSL verification
18+
];
19+
$looker = new \Alexkart\Looker\Looker($lookerConfig, $clientConfig);
1720

1821
$looks = $looker->lookApi->searchLooks(null, 'test');
1922
var_dump($looks);

examples/custom_configuration.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
$dotenv = Dotenv::createImmutable(__DIR__);
88
$dotenv->load();
99

10-
$config = new \App\CustomLookerConfiguration(
10+
$lookerConfig = new \App\CustomLookerConfiguration(
1111
$_SERVER['LOOKER_HOST'],
1212
$_SERVER['LOOKER_CLIENT_ID'],
1313
$_SERVER['LOOKER_CLIENT_SECRET'],
1414
$_SERVER['LOOKER_ACCESS_TOKEN']
1515
);
16-
$looker = new \Alexkart\Looker\Looker($config);
16+
$clientConfig = [
17+
'verify' => false, // disable SSL verification
18+
];
19+
$looker = new \Alexkart\Looker\Looker($lookerConfig, $clientConfig);
1720

1821
$looks = $looker->lookApi->searchLooks(null, 'test');
1922
var_dump($looks);

src/Looker.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,29 @@
3939
class Looker {
4040
private Client $authenticatedClient;
4141
private Configuration $apiConfig;
42-
private LookerConfiguration $config;
42+
private LookerConfiguration $lookerConfig;
43+
private array $clientConfig;
4344

44-
public function __construct(LookerConfiguration $config) {
45-
$this->config = $config;
45+
public function __construct(LookerConfiguration $lookerConfig, array $clientConfig = []) {
46+
$this->lookerConfig = $lookerConfig;
47+
$this->clientConfig = $clientConfig;
4648
$this->login();
4749
}
4850

4951
public function login(): void {
5052
$this->apiConfig = new Configuration();
51-
$this->apiConfig->setHost($this->config->getHost());
53+
$this->apiConfig->setHost($this->lookerConfig->getHost());
5254

53-
if ($this->config->getAccessToken() === '') {
55+
if ($this->lookerConfig->getAccessToken() === '') {
5456
$apiInstance = new ApiAuthApi(
55-
new Client(),
57+
new Client($this->clientConfig),
5658
$this->apiConfig
5759
);
5860

5961
try {
60-
$result = $apiInstance->login($this->config->getClientId(), $this->config->getClientSecret());
61-
$this->config->setAccessToken($result->getAccessToken());
62-
$this->config->setAccessTokenRenewed(true);
62+
$result = $apiInstance->login($this->lookerConfig->getClientId(), $this->lookerConfig->getClientSecret());
63+
$this->lookerConfig->setAccessToken($result->getAccessToken());
64+
$this->lookerConfig->setAccessTokenRenewed(true);
6365
} catch (\Throwable $e) {
6466
echo 'Exception when calling ApiAuthApi->login: ', $e->getMessage(), PHP_EOL;
6567
}
@@ -68,26 +70,26 @@ public function login(): void {
6870
$this->authenticatedClient = new Client([
6971
'verify' => false,
7072
'headers' => [
71-
'Authorization' => 'token ' . $this->config->getAccessToken(),
73+
'Authorization' => 'token ' . $this->lookerConfig->getAccessToken(),
7274
],
7375
]);
7476

75-
if ($this->config->isAccessTokenRenewed()) {
76-
$this->config->storeAccessToken($this->config->getAccessToken());
77-
$this->config->setAccessTokenRenewed(false);
77+
if ($this->lookerConfig->isAccessTokenRenewed()) {
78+
$this->lookerConfig->storeAccessToken($this->lookerConfig->getAccessToken());
79+
$this->lookerConfig->setAccessTokenRenewed(false);
7880
}
7981
}
8082

8183
public function invalidateAccessToken(): void {
82-
$this->config->setAccessToken('');
84+
$this->lookerConfig->setAccessToken('');
8385
}
8486

8587
public function getAuthenticatedClient(): Client {
8688
return $this->authenticatedClient;
8789
}
8890

8991
public function getAccessToken(): string {
90-
return $this->config->getAccessToken();
92+
return $this->lookerConfig->getAccessToken();
9193
}
9294

9395
public function __get(string $name) {
@@ -96,7 +98,11 @@ public function __get(string $name) {
9698
return new $class($this, $this->authenticatedClient, $this->apiConfig);
9799
}
98100

99-
public function getConfig(): LookerConfiguration {
100-
return $this->config;
101+
public function getLookerConfig(): LookerConfiguration {
102+
return $this->lookerConfig;
103+
}
104+
105+
public function getClientConfig(): array {
106+
return $this->clientConfig;
101107
}
102108
}

0 commit comments

Comments
 (0)