Class: RouteNGNClient::Contact

Inherits:
Model
  • Object
show all
Defined in:
lib/routengn_client/models/contact.rb

Defined Under Namespace

Classes: Template

Instance Attribute Summary

Attributes inherited from Model

#attributes, #request_account_id

Attributes included from Model::ClassMethods

#children, #only_children, #parents

Instance Method Summary collapse

Methods inherited from Model

#initialize, #to_hash, #to_json, #to_log

Methods included from Model::ClassMethods

#belongs_to, #from_hash, #from_json, #has_many, #has_one

Methods included from Logging

#init_logger, #logger

Constructor Details

This class inherits a constructor from RouteNGNClient::Model

Instance Method Details

#aorObject



24
25
26
# File 'lib/routengn_client/models/contact.rb', line 24

def aor
  @attributes.aor
end

#build_aor(sip_request, inbound_end_point_group, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/routengn_client/models/contact.rb', line 28

def build_aor(sip_request, inbound_end_point_group, options = {})
  options = options.with_indifferent_access

  uri = self.build_uri(sip_request)

  template = Template.new(inbound_end_point_group.attributes.contact_template)
  template.sub!(self, uri, :inbound_end_point_host => options[:inbound_end_point_host], :inbound_end_point_port => options[:inbound_end_point_port])

  @attributes.aor = template.contact_template
end

#build_uri(sip_request, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/routengn_client/models/contact.rb', line 39

def build_uri(sip_request, options = {})
  options = options.with_indifferent_access

  request_uri = sip_request.request_uri
  sip_uri = request_uri.clone
  oepg = self.outbound_end_point_group
  oepg_parts = oepg ? oepg.build_uri_parts : {}
  oep_parts = self.end_point ? self.end_point.build_uri_parts : {}

  dialcode = oepg && oepg.attributes.dialcode_expression ? sip_uri.user.dialcode(oepg.dialcode_regexp) : sip_uri.user.user
  dialcode = oepg.attributes.dialcode_template.gsub("${dialcode_match}", dialcode) if dialcode && oepg && oepg.attributes.dialcode_template

  blacklisted_user_params = oepg.attributes.uri_user_params_blacklist || [] if oepg
  blacklisted_params = oepg.attributes.uri_params_blacklist || [] if oepg
  merge_user_params, merge_params = {}, {}

  merge_user_params['rn'] = sip_request.rn if sip_request.rn && !sip_request.request_uri.params.keys.include?('rn') && !sip_request.request_uri.params.keys.include?('rn')
  merge_user_params['npdi'] = sip_request.npdi if sip_request.npdi && !sip_request.request_uri.params.keys.include?('npdi') && !sip_request.request_uri.params.keys.include?('npdi')
  merge_user_params.merge! oepg_parts[:uri_user_params]
  merge_params['rn'] = sip_request.rn if sip_request.rn && !merge_user_params.has_key?('rn')
  merge_params['npdi'] = sip_request.npdi if sip_request.npdi && !merge_user_params.has_key?('npdi')
  merge_params.merge! oepg_parts[:uri_params]

  sip_uri.regenerate(:user => {
                               :user => dialcode,
                               :merge_params => merge_user_params,
                               :blacklisted_params => blacklisted_user_params
                              },
                     :host => oep_parts[:host],
                     :port => oep_parts[:port],
                     :merge_params => merge_params,
                     :blacklisted_params => blacklisted_params)
end

#end_pointObject



8
9
10
# File 'lib/routengn_client/models/contact.rb', line 8

def end_point
  @attributes.end_point
end

#inbound_rateObject



12
13
14
# File 'lib/routengn_client/models/contact.rb', line 12

def inbound_rate
  self.route ? self.route.inbound_rate : nil
end

#outbound_end_point_groupObject



20
21
22
# File 'lib/routengn_client/models/contact.rb', line 20

def outbound_end_point_group
  self.route.outbound_end_point_group if self.route
end

#outbound_rateObject



16
17
18
# File 'lib/routengn_client/models/contact.rb', line 16

def outbound_rate
  self.route ? self.route.outbound_rate : nil
end

#routeObject



4
5
6
# File 'lib/routengn_client/models/contact.rb', line 4

def route
  @attributes.route
end