Skip to content

Commit 1ef1b70

Browse files
committed
Add documentation
1 parent 13aeb81 commit 1ef1b70

File tree

5 files changed

+117
-2
lines changed

5 files changed

+117
-2
lines changed

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Looker PHP SDK Advanced
2+
3+
API version: 3.1.0
4+
5+
This package is an advanced version of generated [Looker PHP SDK](https://github.com/alexkart/looker-php-sdk).
6+
It adds additional functionality and simplifies the work with the Looker API. You can interact with the whole API
7+
that Looker provides with just one Looker object and don't worry about anything else.
8+
Currently, it provides the following additional functionality:
9+
- Provides a single wrapper object for various SDK classes
10+
- Automates authentication process
11+
- Automatically renews expired access tokens and stores them into the persistent storage
12+
- ... more will be added later
13+
14+
## Installation & Usage
15+
### Composer
16+
17+
```
18+
composer require alexkart/looker-php-sdk-advanced
19+
```
20+
21+
### Manual Installation
22+
23+
Download the files and include `autoload.php`:
24+
25+
```php
26+
require_once('/path/to/looker-php-sdk-advanced/vendor/autoload.php');
27+
```
28+
29+
30+
## Getting Started
31+
32+
See usage examples in the [**examples**](examples) folder.
33+
34+
### Basic example
35+
In order to start interacting with the API you just need to instantiate Looker object and provide a
36+
config with the Looker host and valid credentials (API client id and API client secret):
37+
38+
```php
39+
$config = new \App\CustomLookerConfiguration(
40+
'https://looker-host:19999/api/3.1',
41+
'client-id',
42+
'client-secret',
43+
);
44+
$looker = new \Alexkart\Looker\Looker($config);
45+
```
46+
47+
Then you can call any API endpoint like this:
48+
```php
49+
$looks = $looker->lookApi->searchLooks(null, 'test');
50+
$dashboards = $looker->dashboardApi->allDashboards(['title']);
51+
$folders = $looker->folderApi->allFolders();
52+
```
53+
54+
The complete working example you can find here [**basic.php**](examples/basic.php)
55+
56+
This is the simplest way to interact with the API, it will request a new access token each time the
57+
Looker object is instantiated. Alternatively you can provide an existing access token and it
58+
will be used to authenticate requests to the API.
59+
60+
```php
61+
$config = new \Alexkart\Looker\LookerConfiguration(
62+
'https://looker-host:19999/api/3.1',
63+
'',
64+
'',
65+
'access-token'
66+
);
67+
$looker = new \Alexkart\Looker\Looker($config);
68+
```
69+
70+
You can provide both access token and API credentials:
71+
```php
72+
$config = new \Alexkart\Looker\LookerConfiguration(
73+
'https://looker-host:19999/api/3.1',
74+
'client-id',
75+
'client-secret',
76+
'optional-access-token'
77+
);
78+
$looker = new \Alexkart\Looker\Looker($config);
79+
```
80+
The access token you provided will be used until it is valid and when it expires a new token will be
81+
requested automatically. You can check if the token has been renewed like this:
82+
```php
83+
if ($looker->getConfig()->isAccessTokenRenewed()) {
84+
$token = $looker->getConfig()->getAccessToken();
85+
}
86+
```
87+
If you want the access token to be stored into the persistent storage (database, cache, file, etc.)
88+
automatically when it is renewed you can extend `LookerConfiguration` class and provide implementation
89+
for the `storeAccessToken()` method and use this class to instantiate `Looker` object:
90+
```php
91+
class CustomLookerConfiguration extends \Alexkart\Looker\LookerConfiguration {
92+
public function storeAccessToken($accessToken): void {
93+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'looker_access_token.txt', $accessToken);
94+
}
95+
}
96+
```
97+
This method will be called when new access token is requested from the API.
98+
Additionally, you can implement `loadAccessToken()` method and it will be used to get the access token
99+
from your storage. You will just need to provide API credentials and it will handle the work with access
100+
tokens for you.
101+
```php
102+
class CustomLookerConfiguration extends \Alexkart\Looker\LookerConfiguration {
103+
public function storeAccessToken($accessToken): void {
104+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'looker_access_token.txt', $accessToken);
105+
}
106+
public function loadAccessToken(): string {
107+
return (string)file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'looker_access_token.txt');
108+
}
109+
}
110+
```
111+
The complete working example you can see here [**custom_configuration.php**](examples/custom_configuration.php)

examples/LookerConfiguration.php renamed to examples/CustomLookerConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App;
44

5-
class LookerConfiguration extends \Alexkart\Looker\LookerConfiguration {
5+
class CustomLookerConfiguration extends \Alexkart\Looker\LookerConfiguration {
66
public function storeAccessToken($accessToken): void {
77
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'looker_access_token.txt', $accessToken);
88
}
File renamed without changes.

examples/test1.php renamed to examples/custom_configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require_once(dirname(__DIR__) . '/vendor/autoload.php');
44

5-
$config = new \App\LookerConfiguration(
5+
$config = new \App\CustomLookerConfiguration(
66
'https://looker-host:19999/api/3.1',
77
'client-id',
88
'client-secret',

src/Looker.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,8 @@ public function __get(string $name) {
9595

9696
return new $class($this, $this->authenticatedClient, $this->apiConfig);
9797
}
98+
99+
public function getConfig(): LookerConfiguration {
100+
return $this->config;
101+
}
98102
}

0 commit comments

Comments
 (0)