-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient
executable file
·54 lines (42 loc) · 1.3 KB
/
client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env php
<?php
namespace Shimoning\ColorMeShopApi;
require_once __DIR__ . '/vendor/autoload.php';
echo __NAMESPACE__ . " shell\n";
echo "-----\nexample:\n";
echo "\$client = new Client;\n\n";
echo "// get url for OAuth\n";
echo "\$oAuthUrl = \$client->getOAuthUrl(\$oAuthOptions, \$oAuthScopes);\n\n";
echo "// get sales\n";
echo "\$sales = \$client->getSales();\n";
// load .env
if (\file_exists(__DIR__ . \DIRECTORY_SEPARATOR . '.env')) {
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
echo "-----\n'.env' loaded.\n-----\n";
}
$sh = new \Psy\Shell();
$sh->addCode(sprintf("namespace %s;", __NAMESPACE__));
// set default
// - OAuth
$oAuthOptions = null;
if (!empty($_ENV['CLIENT_ID']) && !empty($_ENV['CLIENT_SECRET'])) {
$oAuthOptions = new Entities\OAuth\Options(
$_ENV['CLIENT_ID'],
$_ENV['CLIENT_SECRET'],
$_ENV['REDIRECT_URI'] ?? Constants\AuthRedirectUri::NO_REDIRECT,
);
}
$oAuthScopes = new Values\Scopes(Constants\AuthScope::cases());
// - Access token
$token = $_ENV['TOKEN'] ?? null;
// - Client
$client = $token ? new Client($token) : null;
$sh->setScopeVariables([
'oAuthOptions' => $oAuthOptions,
'oAuthScopes' => $oAuthScopes,
'token' => $token,
'client' => $client,
]);
$sh->run();
echo "\n-----\nBye.\n";