WebService-BitbucketServer

 view release on metacpan or  search on metacpan

lib/WebService/BitbucketServer/Spec.pm  view on Meta::CPAN


use warnings;
use strict;

our $VERSION = '0.605'; # VERSION

use Exporter qw(import);
use namespace::clean -except => [qw(import)];

our @EXPORT_OK = qw(api_info documentation_url package_name sub_name);


our $DOCUMENTATION_URL = 'https://developer.atlassian.com/static/rest/bitbucket-server/latest/';

our %API = (
    'access-tokens/1.0'         => {
        id                      => 'access_tokens',
        documentation_filename  => 'bitbucket-access-tokens-rest',
        package                 => 'AccessTokens::V1',
    },
    'api/1.0'                   => {
        id                      => 'core',
        documentation_filename  => 'bitbucket-rest',
        package                 => 'Core::V1',
    },
    'audit/1.0'                 => {
        id                      => 'audit',
        documentation_filename  => 'bitbucket-audit-rest',
        package                 => 'Audit::V1',
    },
    'branch-permissions/2.0'    => {
        id                      => 'ref_restriction',
        documentation_filename  => 'bitbucket-ref-restriction-rest',
        package                 => 'RefRestriction::V2',
    },
    'branch-utils/1.0'          => {
        id                      => 'branch',
        documentation_filename  => 'bitbucket-branch-rest',
        package                 => 'Branch::V1',
    },
    'build-status/1.0'          => {
        id                      => 'build',
        documentation_filename  => 'bitbucket-build-rest',
        package                 => 'Build::V1',
    },
    'comment-likes/1.0'         => {
        id                      => 'comment_likes',
        documentation_filename  => 'bitbucket-comment-likes-rest',
        package                 => 'CommentLikes::V1',
    },
    'default-reviewers/1.0'     => {
        id                      => 'default_reviewers',
        documentation_filename  => 'bitbucket-default-reviewers-rest',
        package                 => 'DefaultReviewers::V1',
    },
    'git/1.0'                   => {
        id                      => 'git',
        documentation_filename  => 'bitbucket-git-rest',
        package                 => 'Git::V1',
    },
    'gpg/1.0'                   => {
        id                      => 'gpg',
        documentation_filename  => 'bitbucket-gpg-rest',
        package                 => 'GPG::V1',
    },
    'jira/1.0'                  => {
        id                      => 'jira',
        documentation_filename  => 'bitbucket-jira-rest',
        package                 => 'JIRA::V1',
    },
    'ssh/1.0'                  => {
        id                      => 'ssh',
        documentation_filename  => 'bitbucket-ssh-rest',
        package                 => 'SSH::V1',
    },
    'mirroring/1.0'             => {
        id                      => 'mirroring_upstream',
        documentation_filename  => 'bitbucket-mirroring-upstream-rest',
        package                 => 'MirroringUpstream::V1',
    },
    'sync/1.0'                  => {
        id                      => 'repository_ref_sync',
        documentation_filename  => 'bitbucket-repository-ref-sync-rest',
        package                 => 'RepositoryRefSync::V1',
    },
);
$API{'keys/1.0'} = $API{'ssh/1.0'};


sub api_info {
    my $endpoint = shift;

    $endpoint = $endpoint->[0] if ref($endpoint) eq 'ARRAY';

    my $namespace = ref($endpoint) eq 'HASH' ? _endpoint_namespace($endpoint) : $endpoint;

    return $API{$namespace || ''};
}

sub _endpoint_namespace {
    my $endpoint = shift;

    my $path = $endpoint->{path};

    my ($namespace) = $path =~ m!^([^/]+/[^/]+)!;
    return $namespace;
}


sub documentation_url {
    my $endpoint    = shift;
    my $type        = shift || 'html';
    my $version     = shift;

    my $namespace   = ref($endpoint) eq 'HASH' ? _endpoint_namespace($endpoint) : $endpoint;
    my $api_info    = api_info($namespace);
    my $filename    = $api_info && $api_info->{documentation_filename} || $namespace;

    my $url = "${DOCUMENTATION_URL}${filename}.${type}";

    $url =~ s/latest/$version/g if $version;

    return $url



( run in 0.744 second using v1.01-cache-2.11-cpan-df04353d9ac )