Commit 2d52d4e3 authored by Andrey Shevchuk's avatar Andrey Shevchuk

migrated internal libs

parent 1b7b980e
package Asterisk::API::Documentation::Generic;
use strict;
use warnings;
our $VERSION = '1';
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
return $self;
}
sub prepare_types {
my ( $self, $doc ) = @_;
my $types;
foreach my $type ( @{ $doc->{types} } ) {
my $type_item;
$type_item->{type} = $type->{type};
foreach my $key ( sort keys %{ $type->{structure} } ) {
my $key_type = ref $type->{structure}->{$key}; # Types ( ref($arg) result ): "" - scalar, "HASH" - hash, "ARRAY" - array
if ( $key_type eq "" ) {
if ( length $type->{structure}->{$key} ) {
push @{ $type_item->{items} }, { item => $type->{structure}->{$key}, props => {
type => "string", format => "raw", description => "", required => 0, hidden => 0, transform => $key } };
}
else {
push @{ $type_item->{items} }, { item => $type->{structure}->{$key}, props => { type => "string", format => "raw", description => "", required => 0, hidden => 0, transform => $key } };
}
}
elsif ( $key_type eq "HASH" ) {
next if exists $type->{structure}->{$key}->{hidden} && $type->{structure}->{$key}->{hidden};
if ( exists $type->{structure}->{$key}->{transform} && ref $type->{structure}->{$key}->{transform} eq "ARRAY" ) {
foreach my $transform_key ( @{ $type->{structure}->{$key}->{transform} } ) {
push @{ $type_item->{items} }, { item => $transform_key, props => $type->{structure}->{$key} };
}
}
elsif ( exists $type->{structure}->{$key}->{transform} && length $type->{structure}->{$key}->{transform} ) {
push @{ $type_item->{items} }, { item => $type->{structure}->{$key}->{transform}, props => $type->{structure}->{$key} };
}
else {
push @{ $type_item->{items} }, { item => $key, props => $type->{structure}->{$key} };
}
}
elsif ( $key_type eq "ARRAY" ) {
push @{ $type_item->{items} }, { item => $key, props => { type => "array[string]", format => "array", description => "", required => 0, hidden => 0, transform => $key } };
}
}
push @{ $types }, $type_item;
}
$doc->{types} = $types;
return $doc;
}
1;
package Asterisk::API::Mapper::Generic;
use strict;
use warnings;
use JSON::XS;
use Types::Serialiser;
use Scalar::Util qw(looks_like_number);
our $VERSION = '1';
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
return $self;
}
sub prepare {
my ( $self, $map ) = @_;
my $mapping = { };
foreach my $key ( keys % { $map } ) {
my $key_type = ref $map->{$key}; # Types ( ref($arg) result ): "" - scalar, "HASH" - hash, "ARRAY" - array
if ( $key_type eq "" ) {
if ( length $map->{$key} ) { # assigned transformation name
$mapping->{'map'}->{$key} = $map->{$key};
$mapping->{'reverse'}->{$map->{$key}} = $key;
}
else { # empty value assigned ( map 1:1 )
$mapping->{'map'}->{$key} = $key;
$mapping->{'reverse'}->{$key} = $key;
}
$mapping->{'type'}->{$key} = "string";
}
elsif ( $key_type eq "HASH" ) {
next if exists $map->{$key}->{hidden} && $map->{$key}->{hidden}; # skip field if assigned hidden flag
if ( exists $map->{$key}->{default} ) { # default value exists
$mapping->{defaults}->{$key} = $map->{$key}->{default};
}
if ( exists $map->{$key}->{transform} && ref $map->{$key}->{transform} eq "ARRAY" ) { # transformation name array exists
$mapping->{'map'}->{$key} = $map->{$key}->{transform};
foreach my $transform_key ( @{ $map->{$key}->{transform} } ) {
$mapping->{'reverse'}->{$transform_key} = $key;
}
}
elsif ( exists $map->{$key}->{transform} && length $map->{$key}->{transform} ) { # transformation name exists
$mapping->{'map'}->{$key} = $map->{$key}->{transform};
$mapping->{'reverse'}->{$map->{$key}->{transform}} = $key;
}
else { # transformation name does not exists
$mapping->{'map'}->{$key} = $key;
$mapping->{'reverse'}->{$key} = $key;
}
$mapping->{'type'}->{$key} = $map->{$key}->{type} || "string";
}
elsif ( $key_type eq "ARRAY" ) { # value is ARRAY ? ( map 1:1 )
$mapping->{'map'}->{$key} = $key;
$mapping->{'reverse'}->{$key} = $key;
}
else {
$mapping->{'type'}->{$key} = "string";
}
$mapping->{'type'}->{$key} = "string" unless exists $mapping->{'type'}->{$key};
}
return $mapping;
}
sub fix_type {
my ( $self, $out_hash, $types, $keys ) = @_;
foreach my $key ( keys %{ $out_hash } ) {
my $key_type = $types->{ $keys->{$key} };
if ( $key_type =~ m/^int/i ) {
$out_hash->{$key} = looks_like_number( $out_hash->{$key} ) ? eval { int $out_hash->{$key} } : $out_hash->{$key};
}
elsif ( $key_type =~ m/^bool/i ) {
$out_hash->{$key} = $out_hash->{$key} ? Types::Serialiser::true : Types::Serialiser::false;
}
$out_hash->{$key} = '' unless defined $out_hash->{$key};
}
return $out_hash;
}
sub detect_type {
my ( $self, $out_hash ) = @_;
foreach my $key ( keys %{ $out_hash } ) {
my $key_value = $out_hash->{$key};
$key_value = $self->detect_type($key_value) if ref $key_value eq "HASH";
unless ( ref $key_value ) {
if ( lc $key_value eq "true" ) {
$key_value = Types::Serialiser::true;
}
elsif ( lc $key_value eq "false" ) {
$key_value = Types::Serialiser::false;
}
elsif ( looks_like_number ( $key_value ) ) {
$key_value = eval { int $out_hash->{$key} };
$key_value = $out_hash->{$key} if $@;
}
elsif ( !defined $key_value ) {
$key_value = '';
}
}
$out_hash->{$key} = $key_value;
}
return $out_hash;
}
1;
package Asterisk::API::Structures::Admins;
use strict;
use warnings;
use Asterisk::API::Mapper::Generic;
use Asterisk::API::Documentation::Generic;
our $VERSION = "1";
our %out_hash_map = (
"id" => {
"description" => "Admin ID",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => 1,
"transform" => "id",
"type" => "integer"
},
"user" => {
"description" => "User",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "login",
"type" => "string"
},
"wpass" => {
"description" => "Wpass",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "password",
"type" => "string"
}
);
my %in_hash_map = (
"id" => {
"description" => "Admin ID",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => 1,
"transform" => "id",
"type" => "integer"
},
"login" => {
"description" => "Login",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "user",
"type" => "string"
},
"password" => {
"description" => "Password",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "wpass",
"type" => "string"
}
);
our %requests = (
types => [
{
"type" => "admin",
"structure" => \%out_hash_map
}
],
operations => [
{
"path" => "/api/admin/{tenantName}/",
"method" => "POST",
"summary" => "Add admin",
"notes" => "Add admin record",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "admin",
"parameter" => "request",
"sample" => q({ "login" : "admin-tl", "password" : "4a55w0rd" })
},
{
"name" => "tenantName",
"description" => "Tenant Name or Tenant ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "thirdlane"
}
],
"responses" => [
{
"code" => 200,
"type" => "admin"
}
]
},
{
"path" => "/api/admin/{tenantName}/{adminId}",
"method" => "DELETE",
"summary" => "Delete admin",
"notes" => "Delete admin record",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "tenantName",
"description" => "Tenant Name or Tenant ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "thirdlane"
},
{
"name" => "adminId",
"description" => "Admin ID",
"required" => 1,
"type" => "integer",
"parameter" => "path"
}
],
"responses" => [
{
"code" => 200,
"type" => "admin"
}
]
}
]
);
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
$self->{mapper} = new Asterisk::API::Mapper::Generic;
my $out_mapping = $self->{mapper}->prepare( \%out_hash_map );
$self->{defaults}->{out} = $out_mapping->{defaults};
$self->{map}->{out} = $out_mapping->{map};
$self->{type}->{out} = $out_mapping->{type};
$self->{reverse}->{out} = $out_mapping->{reverse};
my $in_mapping = $self->{mapper}->prepare( \%in_hash_map );
$self->{defaults}->{in} = $in_mapping->{defaults};
$self->{map}->{in} = $in_mapping->{map};
$self->{type}->{in} = $in_mapping->{type};
$self->{reverse}->{in} = $in_mapping->{reverse};
return $self;
}
sub info {
my ( $self ) = @_;
my $doc = new Asterisk::API::Documentation::Generic;
return $doc->prepare_types( \%requests );
}
sub map_out {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{out} } ) { # fill default values
$out_hash->{$self->{map}->{out}->{$key}} = $self->{defaults}->{out}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{out}->{$key}} = $hash->{$key}
if exists $self->{map}->{out}->{$key} && exists $hash->{$key};
}
$out_hash = $self->{mapper}->fix_type($out_hash, $self->{type}->{out}, $self->{reverse}->{out});
return $out_hash;
}
sub map_in {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{in} } ) { # fill default values
$out_hash->{$self->{map}->{in}->{$key}} = $self->{defaults}->{in}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{in}->{$key}} = $hash->{$key}
if exists $self->{map}->{in}->{$key} && exists $hash->{$key};
}
return $out_hash;
}
1;
package Asterisk::API::Structures::BulkExtensions;
use strict;
use warnings;
use Asterisk::API::Mapper::Generic;
use Asterisk::API::Documentation::Generic;
our $VERSION = "1";
our %out_hash_map = (
"email_address" => {
"description" => "Email address",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "email",
"type" => "string"
},
"ext" => {
"description" => "Extension",
"format" => "int64",
"hidden" => 0,
"required" => 1,
"transform" => "ext",
"type" => "integer"
},
"first_name" => {
"description" => "First name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "firstname",
"type" => "string"
},
"last_name" => {
"description" => "Last name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "lastname",
"type" => "string"
},
"phone_mac_address" => {
"description" => "Phone MAC address",
"format" => "6 octets",
"hidden" => 0,
"required" => 0,
"transform" => "mac",
"type" => "string"
},
"phone" => {
"description" => "DID/Phone number",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "did",
"type" => "string"
},
"secret" => {
"description" => "Phone password",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "secret",
"type" => "string"
},
"pass" => {
"description" => "WEB password",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "pass",
"type" => "string"
},
"connect_enabled" => {
"description" => "Thirdlane Connect enabled",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "connect_enabled",
"type" => "boolean"
}
);
my %in_hash_map = (
"email_address" => {
"description" => "Email address",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "email",
"type" => "string"
},
"ext" => {
"description" => "Extension",
"format" => "int64",
"hidden" => 0,
"required" => 1,
"transform" => "ext",
"type" => "integer"
},
"first_name" => {
"description" => "First name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "firstname",
"type" => "string"
},
"last_name" => {
"description" => "Last name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "lastname",
"type" => "string"
},
"phone_mac_address" => {
"description" => "Phone MAC address",
"format" => "6 octets",
"hidden" => 0,
"required" => 0,
"transform" => "mac",
"type" => "string"
},
"phone" => {
"description" => "DID/Phone number",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "did",
"type" => "string"
},
"secret" => {
"description" => "Phone password",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "secret",
"type" => "string"
},
"pass" => {
"description" => "WEB password",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "pass",
"type" => "string"
},
"connect_enabled" => {
"description" => "Thirdlane Connect enabled",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "connect_enabled",
"type" => "boolean"
}
);
our %requests = (
types => [
{
"type" => "extension",
"structure" => \%out_hash_map
}
],
operations => [
{
"path" => "/api/tenants/{tenantName}/extensions/",
"method" => "POST",
"summary" => "Add User Extension",
"notes" => "Add User Extension",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "extension",
"parameter" => "request",
"sample" => q({ "ext" : 201, "last_name" : "Last", "first_name" : "First", "email_address" : "test@dot.net" })
},
{
"name" => "tenantName",
"description" => "Tenant Name or Tenant ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "thirdlane"
}
],
"responses" => [
{
"code" => 200,
"type" => "extension"
}
]
}
]
);
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
$self->{mapper} = new Asterisk::API::Mapper::Generic;
my $out_mapping = $self->{mapper}->prepare( \%out_hash_map );
$self->{defaults}->{out} = $out_mapping->{defaults};
$self->{map}->{out} = $out_mapping->{map};
$self->{type}->{out} = $out_mapping->{type};
$self->{reverse}->{out} = $out_mapping->{reverse};
my $in_mapping = $self->{mapper}->prepare( \%in_hash_map );
$self->{defaults}->{in} = $in_mapping->{defaults};
$self->{map}->{in} = $in_mapping->{map};
$self->{type}->{in} = $in_mapping->{type};
$self->{reverse}->{in} = $in_mapping->{reverse};
return $self;
}
sub info {
my ( $self ) = @_;
my $doc = new Asterisk::API::Documentation::Generic;
return $doc->prepare_types( \%requests );
}
sub map_out {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{out} } ) { # fill default values
$out_hash->{$self->{map}->{out}->{$key}} = $self->{defaults}->{out}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{out}->{$key}} = $hash->{$key}
if exists $self->{map}->{out}->{$key} && exists $hash->{$key};
}
$out_hash = $self->{mapper}->fix_type($out_hash, $self->{type}->{out}, $self->{reverse}->{out});
return $out_hash;
}
sub map_in {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{in} } ) { # fill default values
$out_hash->{$self->{map}->{in}->{$key}} = $self->{defaults}->{in}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{in}->{$key}} = $hash->{$key}
if exists $self->{map}->{in}->{$key} && exists $hash->{$key};
}
return $out_hash;
}
1;
package Asterisk::API::Structures::CallHistory;
use strict;
use warnings;
use Asterisk::API::Mapper::Generic;
use Asterisk::API::Documentation::Generic;
our $VERSION = "1";
use DateTime;
use DateTime::Format::Strptime;
our %out_hash_map = (
"billsec" => {
"description" => "Billsec",
"format" => "int64",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "duration",
"type" => "integer"
},
"direction" => {
"description" => "Call Direction",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "incoming",
"transform" => "direction",
"type" => "string"
},
"disposition" => {
"description" => "Disposition",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "ANSWERED",
"transform" => "status",
"type" => "string"
},
"dst" => {
"description" => "Call Destination",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "901",
"transform" => "destination",
"type" => "string"
},
"lastapp" => {
"description" => "Lastapp",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "last_app",
"type" => "string"
},
"recording" => {
"description" => "Recording",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "recording",
"type" => "string"
},
"uniqueid" => {
"description" => "Uniqueid",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "unique_id",
"type" => "string"
},
"date" => {
"description" => "Call Date",
"format" => "timestamp",
"hidden" => 0,
"required" => 0,
"sample" => "Tue Nov 24 11:05:16 PM EET 2015",
"transform" => "date",
"type" => "string"
},
"date_epoch" => {
"description" => "Call Date in UTC epoch value",
"format" => "unixtime",
"hidden" => 0,
"required" => 0,
"sample" => "1448399116",
"transform" => "date_epoch",
"type" => "integer"
},
"caller_id" => {
"description" => "Caller Information",
"format" => "caller_id",
"hidden" => 0,
"required" => 0,
"sample" => qq({ "number" : "901", "name" : "John Snow" }),
"transform" => "caller_id",
"type" => "caller_id"
},
"user_src" => {
"description" => "Source User",
"format" => "user",
"hidden" => 0,
"required" => 0,
"sample" => "thirdlane-101",
"transform" => "user_src",
"type" => "string"
},
"user_dst" => {
"description" => "Destination User",
"format" => "user",
"hidden" => 0,
"required" => 0,
"sample" => "thirdlane-103",
"transform" => "user_dst",
"type" => "string"
}
);
our %out_hash_map_caller_id = (
"name" => {
"description" => "Caller Name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "Jhon Snow",
"transform" => "name",
"type" => "string"
},
"number" => {
"description" => "Caller Number",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "901",
"transform" => "number",
"type" => "string"
}
);
my %in_hash_map = (
);
our %requests = (
types => [
{
"type" => "call_history",
"structure" => \%out_hash_map
},
{
"type" => "caller_id",
"structure" => \%out_hash_map_caller_id
}
],
operations => [
{
"path" => "/api/user/call_history",
"method" => "GET",
"summary" => "Get User's Call History",
"notes" => "Get User's Call History",
"consumes" => [
"application/json"
],
"parameters" => [
],
"responses" => [
{
"code" => 200,
"type" => "call_history"
}
]
}
]
);
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
$self->{mapper} = new Asterisk::API::Mapper::Generic;
my $out_mapping = $self->{mapper}->prepare( \%out_hash_map );
$self->{defaults}->{out} = $out_mapping->{defaults};
$self->{map}->{out} = $out_mapping->{map};
$self->{type}->{out} = $out_mapping->{type};
$self->{reverse}->{out} = $out_mapping->{reverse};
my $in_mapping = $self->{mapper}->prepare( \%in_hash_map );
$self->{defaults}->{in} = $in_mapping->{defaults};
$self->{map}->{in} = $in_mapping->{map};
$self->{type}->{in} = $in_mapping->{type};
$self->{reverse}->{in} = $in_mapping->{reverse};
return $self;
}
sub info {
my ( $self ) = @_;
my $doc = new Asterisk::API::Documentation::Generic;
return $doc->prepare_types( \%requests );
}
sub map_out {
my ($self, $hash) = @_;
my $out_hash = {};
my @directions_str = ("outgoing", "incoming");
my $hash_map = \%out_hash_map;
my $in_date_format = DateTime::Format::Strptime->new(
time_zone => 'local',
pattern => '%Y-%m-%d %H:%M:%S',
);
my $out_date_format = DateTime::Format::Strptime->new(
time_zone => $hash->{tz},
pattern => $hash->{date_time_format} || '%a %b %d %r %Z %Y', # ctime(3) format?
);
delete $hash->{date_time_format} if exists $hash->{date_time_format};
eval {
my $out_date = $in_date_format->parse_datetime($hash->{calldate});
$out_date->set_time_zone($hash->{tz});
$out_date->set_formatter( $out_date_format );
$out_hash->{date} = sprintf "%s", $out_date;
$out_hash->{date_epoch} = $out_date->epoch();
if (exists $hash->{current_ext}) {
my $direction = $hash->{current_ext} eq $hash->{src} ? 0 : 1;
$out_hash->{direction} = $directions_str[$direction];
}
if (exists $hash->{current_user}) {
my $direction = $hash->{current_user} eq $hash->{user_src} ? 0 : 1;
$out_hash->{direction} = $directions_str[$direction];
}
if ( my ( $name, $number ) = $hash->{clid} =~ m/^"(.*?)"\s+<(.*?)>$/ ) {
$out_hash->{caller_id} = {
name => $name,
number => $number
};
} else {
$out_hash->{caller_id} = { number => $hash->{clid} };
}
foreach my $key (keys %{$hash}) {
$out_hash->{$self->{'map'}->{'out'}->{$key}} = $hash->{$key} if exists $self->{'map'}->{'out'}->{$key};
}
# foreach my $key (keys %{$hash}) {
# my $outkey = $hash_map->{$key};
# $out_hash->{$outkey} = $hash->{$key} if exists $hash_map->{$key};
# }
};
$out_hash = $self->{mapper}->fix_type($out_hash, $self->{type}->{out}, $self->{reverse}->{out});
return $out_hash;
}
sub map_out_natural {
my ($self, $hash) = @_;
return $hash;
my $out_hash = {};
foreach my $key (keys %{$hash}) {
$out_hash->{$self->{'map'}->{'out'}->{$key}} = $hash->{$key} if exists $self->{'map'}->{'out'}->{$key};
}
return $out_hash;
}
sub map_in {
my ($self, $hash) = @_;
return $hash;
my $out_hash = {};
foreach my $key (keys %{$hash}) {
$out_hash->{$self->{'map'}->{'in'}->{$key}} = $hash->{$key} if exists $self->{'map'}->{'in'}->{$key};
}
return $out_hash;
}
1;
package Asterisk::API::Structures::ContactSource;
use strict;
use warnings;
use Asterisk::API::Mapper::Generic;
use Asterisk::API::Documentation::Generic;
our $VERSION = "1";
our %out_hash_map = (
"id" => {
"description" => "Source ID",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => 1,
"transform" => "id",
"type" => "integer"
},
"type" => {
"description" => "Source name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "contact_source_type",
"type" => "string"
},
"description" => {
"description" => "Source description",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "description",
"type" => "string"
},
"status" => {
"description" => "Source status",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "status",
"type" => "integer"
},
"data" => {
"description" => "Source parameters",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "data",
"type" => "source_parameter"
}
);
my %in_hash_map = (
"id" => {
"description" => "Source ID",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => 1,
"transform" => "id",
"type" => "integer"
},
"contact_source_type" => {
"description" => "Source name",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "type",
"type" => "string"
},
"description" => {
"description" => "Source description",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "description",
"type" => "string"
},
"status" => {
"description" => "Source status",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "status",
"type" => "integer"
},
"data" => {
"description" => "Source parameters",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "data",
"type" => "source_parameter"
}
);
our %contact_source_parameter_type = (
"server_url" => {
"description" => "Source URL",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "server_url",
"type" => "string"
},
"api_token" => {
"description" => "Source token",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "api_token",
"type" => "string"
},
"username" => {
"description" => "Source username",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "username",
"type" => "string"
},
"password" => {
"description" => "Source password",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "password",
"type" => "string"
}
);
our %requests = (
types => [
{
"type" => "source_parameter",
"structure" => \%contact_source_parameter_type
},
{
"type" => "contact_source",
"structure" => \%out_hash_map
}
],
operations => [
{
"path" => "/api/contact_source/",
"method" => "GET",
"summary" => "Get Contact Sources",
"notes" => "List all Contact Sources",
"consumes" => [
"application/json"
],
"parameters" => [ ],
"responses" => [
{
"code" => 200,
"type" => "source_parameter"
}
]
},
{
"path" => "/api/contact_source/{contactSourceId}",
"method" => "GET",
"summary" => "Get single Contact Source",
"notes" => "Get exactly one Contact Source",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "contactSourceId",
"description" => "Contact Source ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "1"
}
],
"responses" => [
{
"code" => 200,
"type" => "source_parameter"
}
]
},
{
"path" => "/api/contact_source/",
"method" => "POST",
"summary" => "Add Source",
"notes" => "Add Contact Source",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "source_parameter",
"parameter" => "request",
"sample" => q({ "contact_source_type" : "salesforce", "description" : "Own Salesforce org", "status": 1, "data" : { "username" : "sfuser@org.com", "password" : "securepass" } })
}
],
"responses" => [
{
"code" => 200,
"type" => "source_parameter"
}
]
},
{
"path" => "/api/contact_source/{contactSourceId}",
"method" => "PUT",
"summary" => "Update Source",
"notes" => "Update Contact Source record",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "source_parameter",
"parameter" => "request",
"sample" => q({ "contact_source_type" : "salesforce", "description" : "Own Salesforce org", "status": 1, "data" : { "username" : "sfuser@org.com", "password" : "securepass" } })
},
{
"name" => "contactSourceId",
"description" => "Contact Source ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "1"
}
],
"responses" => [
{
"code" => 200,
"type" => "source_parameter"
}
]
},
{
"path" => "/api/contact_source/{contactSourceId}",
"method" => "DELETE",
"summary" => "Delete Contact Source",
"notes" => "Delete Contact Source record",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "contactSourceId",
"description" => "Contact Source ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "1"
}
],
"responses" => [
{
"code" => 200,
"type" => "source_parameter"
}
]
}
]
);
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
$self->{mapper} = new Asterisk::API::Mapper::Generic;
my $out_mapping = $self->{mapper}->prepare( \%out_hash_map );
$self->{defaults}->{out} = $out_mapping->{defaults};
$self->{map}->{out} = $out_mapping->{map};
$self->{type}->{out} = $out_mapping->{type};
$self->{reverse}->{out} = $out_mapping->{reverse};
my $in_mapping = $self->{mapper}->prepare( \%in_hash_map );
$self->{defaults}->{in} = $in_mapping->{defaults};
$self->{map}->{in} = $in_mapping->{map};
$self->{type}->{in} = $in_mapping->{type};
$self->{reverse}->{in} = $in_mapping->{reverse};
return $self;
}
sub info {
my ( $self ) = @_;
my $doc = new Asterisk::API::Documentation::Generic;
return $doc->prepare_types( \%requests );
}
sub map_out {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{out} } ) { # fill default values
$out_hash->{$self->{map}->{out}->{$key}} = $self->{defaults}->{out}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{out}->{$key}} = $hash->{$key}
if exists $self->{map}->{out}->{$key} && exists $hash->{$key};
}
$out_hash = $self->{mapper}->fix_type($out_hash, $self->{type}->{out}, $self->{reverse}->{out});
return $out_hash;
}
sub map_in {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{in} } ) { # fill default values
$out_hash->{$self->{map}->{in}->{$key}} = $self->{defaults}->{in}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{in}->{$key}} = $hash->{$key}
if exists $self->{map}->{in}->{$key} && exists $hash->{$key};
}
return $out_hash;
}
1;
package Asterisk::API::Structures::Dids;
use strict;
use warnings;
use Asterisk::API::Mapper::Generic;
use Asterisk::API::Documentation::Generic;
our $VERSION = "1";
our %out_hash_map = (
"assigned" => {
"description" => "Assigned",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "assigned_to",
"type" => "string"
},
"note" => {
"description" => "Description",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "Company X main number",
"transform" => "description",
"type" => "string"
},
"number" => {
"description" => "Number",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "did",
"type" => "string"
}
);
my %in_hash_map = (
"assigned_to" => {
"description" => "Assigned to",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "assigned",
"type" => "string"
},
"description" => {
"description" => "Description",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "Description text",
"transform" => "note",
"type" => "string"
},
"did" => {
"description" => "Did",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "number",
"type" => "string"
}
);
our %requests = (
types => [
{
"type" => "did",
"structure" => \%out_hash_map
}
],
operations => [
{
"path" => "/api/dids/",
"method" => "GET",
"summary" => "Get DIDs",
"notes" => "Get all DIDs",
"consumes" => [
"application/json"
],
"parameters" => [
],
"responses" => [
{
"code" => 200,
"type" => "did"
}
]
},
{
"path" => "/api/dids/{did}",
"method" => "GET",
"summary" => "Get one DID",
"notes" => "Get one DID",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "did",
"description" => "DID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "14155551212"
}
],
"responses" => [
{
"code" => 200,
"type" => "did"
}
]
},
{
"path" => "/api/dids/",
"method" => "POST",
"summary" => "Add DID",
"notes" => "Add DID",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "did",
"parameter" => "request",
"sample" => q({"assigned_to" : "thirdlane", "did" : "14155551212", "description" : "DID's description" })
}
],
"responses" => [
{
"code" => 200,
"type" => "did"
}
]
},
{
"path" => "/api/dids/{did}",
"method" => "PUT",
"summary" => "Update DID",
"notes" => "Update DID",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "DID",
"required" => 1,
"type" => "did",
"parameter" => "request",
"sample" => q({ "description" : "New description"})
},
{
"name" => "did",
"description" => "DID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "14155551212"
}
],
"responses" => [
{
"code" => 200,
"type" => "did"
}
]
},
{
"path" => "/api/dids/{did}",
"method" => "DELETE",
"summary" => "Delete DID",
"notes" => "Delete DID",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "did",
"description" => "DID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "14155551212"
}
],
"responses" => [
{
"code" => 200,
"type" => "did"
}
]
}
]
);
sub new {
my( $class, $args ) = @_;
my $self = bless( { }, $class );
$self->{version} = $VERSION;
$self->{mapper} = new Asterisk::API::Mapper::Generic;
my $out_mapping = $self->{mapper}->prepare( \%out_hash_map );
$self->{defaults}->{out} = $out_mapping->{defaults};
$self->{map}->{out} = $out_mapping->{map};
$self->{type}->{out} = $out_mapping->{type};
$self->{reverse}->{out} = $out_mapping->{reverse};
my $in_mapping = $self->{mapper}->prepare( \%in_hash_map );
$self->{defaults}->{in} = $in_mapping->{defaults};
$self->{map}->{in} = $in_mapping->{map};
$self->{type}->{in} = $in_mapping->{type};
$self->{reverse}->{in} = $in_mapping->{reverse};
return $self;
}
sub info {
my ( $self ) = @_;
my $doc = new Asterisk::API::Documentation::Generic;
return $doc->prepare_types( \%requests );
}
sub map_out {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{out} } ) { # fill default values
$out_hash->{$self->{map}->{out}->{$key}} = $self->{defaults}->{out}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{out}->{$key}} = $hash->{$key}
if exists $self->{map}->{out}->{$key} && exists $hash->{$key};
}
$out_hash = $self->{mapper}->fix_type($out_hash, $self->{type}->{out}, $self->{reverse}->{out});
return $out_hash;
}
sub map_in {
my ( $self, $hash, $params ) = @_;
if ( exists $params->{direct} && $params->{direct} ) {
return $hash;
}
my $out_hash = { };
if ( exists $params->{defaults} && $params->{defaults} ) {
foreach my $key ( keys %{ $self->{defaults}->{in} } ) { # fill default values
$out_hash->{$self->{map}->{in}->{$key}} = $self->{defaults}->{in}->{$key};
}
}
foreach my $key ( keys %{ $hash } ) {
$out_hash->{$self->{map}->{in}->{$key}} = $hash->{$key}
if exists $self->{map}->{in}->{$key} && exists $hash->{$key};
}
return $out_hash;
}
1;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment