Skip to content

Commit

Permalink
add admin API for active calls
Browse files Browse the repository at this point in the history
  • Loading branch information
senid231 committed Jun 10, 2019
1 parent ae3844b commit 8cfe75a
Show file tree
Hide file tree
Showing 6 changed files with 471 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/active_calls_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::ActiveCallsController < Api::Rest::Admin::BaseController
end
106 changes: 106 additions & 0 deletions app/resources/api/rest/admin/active_call_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# frozen_string_literal: true

class Api::Rest::Admin::ActiveCallResource < ::BaseResource
model_name 'RealtimeData::ActiveCall'
paginator :none
key_type :string

attributes :start_time,
:connect_time,
:duration,
:time_limit,
:dst_prefix_in,
:dst_prefix_routing,
:lrn,
:dst_prefix_out,
:src_prefix_in,
:src_prefix_routing,
:src_prefix_out,
:diversion_in,
:diversion_out,
:dst_country_id,
:dst_network_id,
:customer_id,
:vendor_id,
:customer_acc_id,
:vendor_acc_id,
:customer_auth_id,
:destination_id,
:dialpeer_id,
:orig_gw_id,
:term_gw_id,
:routing_group_id,
:rateplan_id,
:destination_initial_rate,
:destination_next_rate,
:destination_initial_interval,
:destination_next_interval,
:destination_fee,
:destination_rate_policy_id,
:dialpeer_initial_rate,
:dialpeer_next_rate,
:dialpeer_initial_interval,
:dialpeer_next_interval,
:dialpeer_fee,
:legA_remote_ip,
:legA_remote_port,
:orig_call_id,
:legA_local_ip,
:legA_local_port,
:local_tag,
:legB_local_ip,
:legB_local_port,
:term_call_id,
:legB_remote_ip,
:legB_remote_port,
:node_id,
:pop_id

has_one :customer, class_name: 'Contractor'
has_one :vendor, class_name: 'Contractor'
has_one :customer_acc, class_name: 'Account'
has_one :vendor_acc, class_name: 'Account'
has_one :customer_auth, class_name: 'CustomersAuth'
has_one :destination, class_name: 'Destination'
has_one :dialpeer, class_name: 'Dialpeer'
has_one :orig_gw, class_name: 'Gateway'
has_one :term_gw, class_name: 'Gateway'
has_one :routing_group, class_name: 'RoutingGroup'
has_one :rateplan, class_name: 'Rateplan'
has_one :destination_rate_policy, class_name: 'DestinationRatePolicy'
has_one :node, class_name: 'Node', foreign_key: :node_id

filter :node_id_eq
filter :dst_country_id_eq
filter :dst_network_id_eq
filter :vendor_id_eq
filter :customer_id_eq
filter :vendor_acc_id_eq
filter :customer_acc_id_eq
filter :orig_gw_id_eq
filter :term_gw_id_eq
filter :duration_equals
filter :duration_greater_than
filter :duration_less_than

def self.sortable_fields(_context = nil)
[]
end

def self.find_by_key(key, options = {})
context = options[:context]
opts = options.except(:paginator, :sort_criteria)
model = apply_includes(records(opts), opts).find(key)
raise JSONAPI::Exceptions::RecordNotFound, key if model.nil?

new(model, context)
end

def self.sort_records(records, _order_options, _context = {})
records
end

def self.find_count(_verified_filters, _options)
0
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
jsonapi_resources :sdp_c_locations
jsonapi_resources :session_refresh_methods
jsonapi_resources :sortings
jsonapi_resources :active_calls, only: %i[index show destroy]

namespace :cdr do
jsonapi_resources :cdrs, only: %i[index show] do
Expand Down
111 changes: 111 additions & 0 deletions spec/factories/active_calls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# frozen_string_literal: true

FactoryGirl.define do
factory :active_call, class: RealtimeData::ActiveCall do
trait :filled do
duration { (rand(60) + rand).round(7) }
start_time { rand(120..179).seconds.ago.to_f }
connect_time { 2.minute.ago.to_f }
end_time nil
local_tag { [1, 2, 16, 8].map { |n| SecureRandom.hex(n).upcase }.join('-') }
local_time { Time.now.to_f }
sequence(:node_id, 1)
vendor_acc_id { Account.vendors_accounts.last&.id || 124 }
vendor_id { Contractor.vendors.last&.id || 123 }

active_resources '[]'
active_resources_json []
attempt_num 1
audio_record_enabled false
auth_orig_ip '192.168.88.23'
auth_orig_port 5060
auth_orig_protocol_id 1
cdr_born_time { 1.minute.ago.to_f }
customer_acc_check_balance true
customer_acc_external_id nil
customer_acc_id 25
customer_acc_vat '0'
customer_auth_external_id nil
customer_auth_id 20_085
customer_auth_name 'test auth'
customer_external_id nil
customer_id 5
destination_fee '0.0'
destination_id 4_201_541
destination_initial_interval 1
destination_initial_rate '0.11'
destination_next_interval 1
destination_next_rate '0.11'
destination_prefix '380'
destination_rate_policy_id 1
destination_reverse_billing false
dialpeer_fee '0.0'
dialpeer_id 1_376_786
dialpeer_initial_interval 1
dialpeer_initial_rate '0.005'
dialpeer_next_interval 1
dialpeer_next_rate '0.001'
dialpeer_prefix '380'
dialpeer_reverse_billing false
disconnect_code 0
disconnect_initiator 4
disconnect_internal_code 0
disconnect_internal_reason 'Unhandled sequence'
disconnect_reason ''
diversion_in nil
diversion_out nil
dst_area_id nil
dst_country_id 222
dst_network_id 1522
dst_prefix_in '9810441492550028'
dst_prefix_out '3800000000000000000'
dst_prefix_routing '3800000000000000000'
dump_level_id 0
from_domain '192.168.88.23'
global_tag ''
legA_local_ip '192.168.88.23'
legA_local_port 5061
legA_remote_ip '192.168.88.23'
legA_remote_port 5060
legB_local_ip ''
legB_local_port 0
legB_remote_ip ''
legB_remote_port 0
lnp_database_id nil
lrn nil
orig_call_id '2141402782-1223087865-286388420'
orig_gw_external_id nil
orig_gw_id 19
pai_in nil
pai_out nil
pop_id 4
ppi_in nil
ppi_out nil
privacy_in nil
privacy_out nil
rateplan_id 18
resources ''
routing_group_id 24
routing_plan_id 3
routing_tag_ids '{}'
rpid_in nil
rpid_out nil
rpid_privacy_in nil
rpid_privacy_out nil
ruri_domain '192.168.88.23'
src_area_id nil
src_name_in ''
src_name_out ''
src_prefix_in '10317'
src_prefix_out '10317'
src_prefix_routing '10317'
term_call_id '8-5D73A55A-5CFB77360000494D-19C01700'
term_gw_external_id nil
term_gw_id 20
time_limit 4909
to_domain '192.168.12.88'
vendor_acc_external_id nil
vendor_external_id nil
end
end
end
Loading

0 comments on commit 8cfe75a

Please sign in to comment.