Giter Site home page Giter Site logo

cybercog / youtrack-rest-php Goto Github PK

View Code? Open in Web Editor NEW
35.0 4.0 25.0 202 KB

JetBrains YouTrack REST API PHP Client

Home Page: https://komarev.com/sources/php-youtrack-rest

License: MIT License

PHP 96.24% Dockerfile 3.76%
youtrack youtrack-rest-php cog api-client issue-tracker sdk sdk-php jetbrains cybercog laravel

youtrack-rest-php's People

Contributors

adam187 avatar antonkomarev avatar ilzrv avatar marchagen avatar pacant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

youtrack-rest-php's Issues

Refactor Client

Goals

  • Provide an ability to write HTTP Clint adapters for custom PSR-7 implementations.
  • Separation of concerns.
  • Exceptions should be related to their namespace classes responsibilities.
  • Client version should be part of Client contract.
  • User-Agent headers should be more verbose: CLIENT/VERSION HTTP_CLIENT/VERSION PHP/VERSION.

Refactor authorizers

Goals

  • Tell Authorizers what to do, and don't ask them.
  • Remove authenticate method from Authorizer contract (not it's responsibility).
  • Delegate authentication process to Authenticators.
  • Create factory for Authorizer building since this process is more complicated.

New API proposals will be described below.

Wrong Authenticator behavior

Authenticator shouldn't append headers to Client request. Authorizer should do it.

This change will lead us to extend Authenticator contract by adding token method.

GET request error

In example for time tracking of issue we refer to the next request
GET /api/issues/{issueID}/timeTracking?{fields}

For GET request we need send params in 'query' key for Guzzle Http, but in function buildOptions we can see that it is impossible to do.
image

In result we got wrong request
image

The solution is to change the $defaultOptions parameter
$defaultOptions = [ 'headers' => $this->buildHeaders() ];
and add additional action for value $options

API client connection design

Version 1

Token Authenticator

$http = new \GuzzleHttp\Client([
    'base_uri' => 'https://example.com',
]);

$client = new \Cog\YouTrack\Services\YouTrackClient($http, [
    'driver' => \Cog\YouTrack\Authenticators\TokenAuthenticator::class,
    'token' => 'YOUTRACK_API_TOKEN',
]);

Cookie Authenticator

$http = new \GuzzleHttp\Client([
    'base_uri' => 'https://example.com',
]);

$client = new \Cog\YouTrack\Services\YouTrackClient($http, [
    'driver' => \Cog\YouTrack\Authenticators\CookieAuthenticator::class,
    'username' => 'YOUTRACK_USERNAME',
    'password' => 'YOUTRACK_PASSWORD',
]);

Container Binding

$this->app->bind(YouTrackClientContract::class, function () {
    $config = $this->app->make('config');

    $http = new Client([
        'base_uri' => $config->get('youtrack.base_uri'),
    ]);

    $options = $config->get('youtrack.authenticators.' . $config->get('youtrack.authenticator'));

    return new YouTrackClient($http, $options);
});

Conclusion

Pros

  • All drivers has same API.

Cons

  • Authenticator building encapsulated inside YouTrackClient.
  • Violate Single Responsibility Principle.

Guzzle 7

At the moment this module holds us from upgrading to Guzzle 7. Any plans to support it please?

Request options & headers

Goals

  • Building request is very complicated and requires simplification.
  • buildHeaders never accept $options variable, remove param or make it usable.
  • request method $options revert back to $formData and add new $options param which will overwrite HTTP client options.

Refactor exceptions

  • Stop using *Exception postfix on each exception. Make them more verbose.
  • Cog\Contracts\YouTrack\Rest\Client\Exceptions\ClientException should extend RuntimeException?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.