Commit 1b7b980e authored by Andrey Shevchuk's avatar Andrey Shevchuk

fixed InboundRoutes maps

parent c495a28b
...@@ -81,6 +81,15 @@ our %out_hash_map = ( ...@@ -81,6 +81,15 @@ our %out_hash_map = (
"sample" => "", "sample" => "",
"transform" => "routetype", "transform" => "routetype",
"type" => "string" "type" => "string"
},
"options" => {
"description" => "Routetype",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "[{args:[],action:'tl-check-voicemail',schedule:'day'}]",
"transform" => "options",
"type" => "inbound_route_option"
} }
); );
...@@ -157,15 +166,59 @@ my %in_hash_map = ( ...@@ -157,15 +166,59 @@ my %in_hash_map = (
"sample" => "schedule", "sample" => "schedule",
"transform" => "routetype", "transform" => "routetype",
"type" => "string" "type" => "string"
},
"options" => {
"description" => "Routetype",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "[{args:[],action:'tl-check-voicemail',schedule:'day'}]",
"transform" => "options",
"type" => "inbound_route_option"
} }
); );
our %out_option_hash_map = (
"args" => {
"description" => "Action arguments",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "[]",
"transform" => "args",
"type" => "string"
},
"action" => {
"description" => "Action",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "tl-check-voicemail",
"transform" => "action",
"type" => "string"
},
"schedule" => {
"description" => "Schedule",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "day",
"transform" => "schedule",
"type" => "string"
},
);
our %requests = ( our %requests = (
types => [ types => [
{ {
"type" => "inbound_route", "type" => "inbound_route",
"structure" => \%out_hash_map "structure" => \%out_hash_map
},
{
"type" => "inbound_route_option",
"structure" => \%out_option_hash_map
} }
], ],
operations => [ operations => [
{ {
......
package Asterisk::API::Structures::SingleInboundRoutes;
use strict;
use warnings;
use Asterisk::API::Mapper::Generic;
use Asterisk::API::Documentation::Generic;
our $VERSION = "1";
our %out_hash_map = (
"billable" => {
"description" => "Billable",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "billable",
"type" => "bool"
},
"channels" => {
"description" => "Channels",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "channels",
"type" => "string"
},
"description" => {
"description" => "Description",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "description",
"type" => "string"
},
"extension" => {
"description" => "Extension",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "did",
"type" => "string"
},
"id" => {
"description" => "Route ID",
"format" => "int64",
"hidden" => 0,
"required" => 1,
"sample" => 1,
"transform" => "internal_id",
"type" => "integer"
},
"prompt_language" => {
"description" => "Prompt language",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "prompt_language",
"type" => "string"
},
"tz" => {
"default" => "",
"description" => "Time zone",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "",
"transform" => "tz",
"type" => "string"
},
"routetype" => {
"description" => "Routetype",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "routetype",
"type" => "string"
},
"options" => {
"description" => "Routetype",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "[{args:[],action:'tl-check-voicemail',schedule:'day'}]",
"transform" => "options",
"type" => "inbound_route_option"
}
);
my %in_hash_map = (
"billable" => {
"description" => "Billable",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "billable",
"type" => "bool"
},
"channels" => {
"description" => "Channels",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "channels",
"type" => "string"
},
"description" => {
"description" => "Description",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "description",
"type" => "string"
},
"did" => {
"description" => "Did",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "extension",
"type" => "string"
},
"internal_id" => {
"description" => "Route ID",
"format" => "int64",
"hidden" => 1,
"required" => 0,
"transform" => "id",
"type" => "integer"
},
"prompt_language" => {
"description" => "Prompt language",
"format" => "raw",
"hidden" => 0,
"required" => 0,
"sample" => "",
"transform" => "prompt_language",
"type" => "string"
},
"tz" => {
"default" => "",
"description" => "Time zone",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "",
"transform" => "tz",
"type" => "string"
},
"routetype" => {
"default" => "schedule",
"description" => "Route type",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "schedule",
"transform" => "routetype",
"type" => "string"
},
"options" => {
"description" => "Routetype",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "[{args:[],action:'tl-check-voicemail',schedule:'day'}]",
"transform" => "options",
"type" => "inbound_route_option"
}
);
our %out_option_hash_map = (
"args" => {
"description" => "Action arguments",
"format" => "array",
"hidden" => 0,
"required" => 0,
"sample" => "[]",
"transform" => "args",
"type" => "string"
},
"action" => {
"description" => "Action",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "tl-check-voicemail",
"transform" => "action",
"type" => "string"
},
"schedule" => {
"description" => "Schedule",
"format" => "raw",
"hidden" => 0,
"required" => 1,
"sample" => "day",
"transform" => "schedule",
"type" => "string"
},
);
our %requests = (
types => [
{
"type" => "inbound_route",
"structure" => \%out_hash_map
},
{
"type" => "inbound_route_option",
"structure" => \%out_option_hash_map
}
],
operations => [
{
"path" => "/api/inbound_routes/",
"method" => "GET",
"summary" => "Get Inbound Routes",
"notes" => "Get Inbound Routes for tenant",
"consumes" => [
"application/json"
],
"parameters" => [
],
"responses" => [
{
"code" => 200,
"type" => "inbound_route"
}
]
},
{
"path" => "/api/inbound_routes/{routeId}",
"method" => "GET",
"summary" => "Get one Inbound Route",
"notes" => "Get one Inbound Route",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "routeId",
"description" => "Route ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "14152223333"
}
],
"responses" => [
{
"code" => 200,
"type" => "inbound_route"
}
]
},
{
"path" => "/api/inbound_routes/{routeId}",
"method" => "PUT",
"summary" => "Update Inbound Route",
"notes" => "Update Inbound Route",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "inbound_route",
"parameter" => "request",
"sample" => q({"routetype" : "Time Based 5", "tenant" : "thirdlane"})
},
{
"name" => "routeId",
"description" => "Route ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "14152223333"
}
],
"responses" => [
{
"code" => 200,
"type" => "inbound_route"
}
]
},
{
"path" => "/api/inbound_routes/",
"method" => "POST",
"summary" => "Add Inbound Route",
"notes" => "Add Inbound Route",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "body",
"description" => "No description",
"required" => 1,
"type" => "inbound_route",
"parameter" => "request",
"sample" => q({"did" : "14152223333", "routetype" : "Time Based", "description" : "Route description" })
}
],
"responses" => [
{
"code" => 200,
"type" => "inbound_route"
}
]
},
{
"path" => "/api/inbound_routes/{routeId}",
"method" => "DELETE",
"summary" => "Delete Inbound Route",
"notes" => "Delete Inbound Route",
"consumes" => [
"application/json"
],
"parameters" => [
{
"name" => "routeId",
"description" => "Route ID",
"required" => 1,
"type" => "string",
"parameter" => "path",
"sample" => "14152223333"
}
],
"responses" => [
{
"code" => 200,
"type" => "inbound_route"
}
]
}
]
);
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});
$out_hash->{options} = [ ];
my $options = { };
foreach my $key ( keys %{ $hash } ) {
if ($key =~ m/^(.*?)_(\d+)_(\d+)$/) {
$options->{$2}->{args}->{$3} = $hash->{$key};
} elsif ($key =~ m/^(.*?)_(\d+)$/) {
if ( $1 eq "args" ) {
my $i = 0;
foreach my $arg ( split /,/, $hash->{$key} ) {
$options->{$2}->{args}->{$i++} = $arg;
}
}
elsif ( not grep { $1 eq $_ } qw(var schedule_name) ) {
$options->{$2}->{$1} = $hash->{$key};
}
}
}
foreach my $key ( keys %{ $options } ) {
$options->{$key}->{args} = [ map { $options->{$key}->{args}->{$_} } sort { int( $a ) <=> int ( $b ) } keys %{ $options->{$key}->{args} //= {} } ];
}
$out_hash->{options} = [ map { $options->{$_} } sort { int( $a ) <=> int ( $b ) } keys %{ $options } ];
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};
}
if ( exists $hash->{options} ) {
for ( my $i = 0; $i < scalar @{ $hash->{options} }; $i++ ) {
$out_hash->{"schedule_$i"} = $hash->{options}->[$i]->{schedule};
$out_hash->{"action_$i"} = $hash->{options}->[$i]->{action};
if ( exists $hash->{options}->[$i]->{args} ) {
$out_hash->{"args_$i"} = join ",", @{ $hash->{options}->[$i]->{args} };
for ( my $t = 0; $t < scalar @{ $hash->{options}->[$i]->{args} }; $t++ ) {
$out_hash->{$hash->{options}->[$i]->{action} . "_" . $i . "_" . $t} = $hash->{options}->[$i]->{args}->[$t];
}
}
}
}
return $out_hash;
}
1;
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