Completed
Push — master ( 88a770...3d8ad2 )
by Cedric
05:17 queued 02:24
created

playground.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * This file is part of the adlogix/guzzle-atlassian-connect package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
require_once 'vendor/autoload.php';
10
11
use Adlogix\GuzzleAtlassianConnect\Middleware\ConnectMiddleware;
12
use Adlogix\GuzzleAtlassianConnect\Security\QueryParamAuthentication;
13
use GuzzleHttp\Client;
14
use GuzzleHttp\HandlerStack;
15
16
/**
17
 * See the 'installed' webhook on how to recover this payload.
18
 *
19
 * The sharedSecret is given by the application we installed the add-on to,
20
 * this is needed to sign our request and to validate the requests from the application.
21
 */
22
$sharedSecret = '';
23
$baseUrl = '';
24 View Code Duplication
if (file_exists('payload.json')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    $payload = json_decode(file_get_contents('payload.json'));
26
    $sharedSecret = $payload->sharedSecret;
27
    $baseUrl = $payload->baseUrl;
28
}
29
30
/**
31
 * Here we create the middleware;
32
 * for the authentication method we give the key we defined in our descriptor,
33
 * and the second parameter is the sharedSecret given by atlassian when we installed the add-on.
34
 *
35
 * For more info on the descriptor,
36
 * @see https://developer.atlassian.com/static/connect/docs/latest/modules/
37
 *
38
 * For more info on how to get the sharedKey, you need to define the installed lifecycle in your descriptor.
39
 * @see https://developer.atlassian.com/static/connect/docs/latest/modules/lifecycle.html
40
 *
41
 * The second parameter ro create the middleware is the full path to the application we want to connect to.
42
 * For the demo we use Confluence which resides at http://atlassian-confluence.dev/confluence
43
 *
44
 * If your sharedSecret is empty, there's no need to try to contact the application,
45
 * so be sure you received the 'enabled' webhook call before trying to contact it.
46
 */
47
$middleware = new ConnectMiddleware(
48
    new QueryParamAuthentication('eu.adlogix.atlassian-connect', $sharedSecret),
49
    $baseUrl
50
);
51
52
53
/**
54
 * We start to build ou Guzzle Client by defining the HandlerStack and pushing our middleware in it.
55
 */
56
$stack = HandlerStack::create();
57
$stack->push($middleware);
58
59
/**
60
 * And the Client creation
61
 */
62
$client = new Client(
63
    [
64
        'base_uri' => $baseUrl.'/',
65
        'handler'  => $stack,
66
        'debug'    => true
67
    ]
68
);
69
70
71
$response = $client->get('rest/api/space');
72
var_dump($response->getBody()->getContents());
73
74
echo "\r\n\r\n=======================================================================================================" .
75
        "==============================================================================================\r\n\r\n";
76
77
$response = $client->get(
78
    'download/attachments/197288/Seller%20Admin%20logo%20stats.png?version=1&modificationDate=1459423644007&api=v2'
79
);
80
var_dump($response->getBody()->getContents());
81