twilreapi-active_call_router-pin_cambodia 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60f3cf3683abbdd76c0a1c4f0a23e2991748f465
4
+ data.tar.gz: c501f78b59b8c1332543a8d80057971714f6d681
5
+ SHA512:
6
+ metadata.gz: c6ae599b25205e2d034db12da56c3bc6175021ae23b546b1cd3df9f238e3b38f7ab477b775141ab5b66481d1efef99bbb18c1eb1b2c94fa810d48826a4ce7067
7
+ data.tar.gz: 1f61a19d6b88e194c43519ba8f31d27eb920adaf217b04559aaa1ed8ecda6e279d58db936e775a3acaa9b49a1c25f79d8a895fa6a4adf04ffdc8ad8ac2e1550f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/ruby/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in twilreapi-active_call_router-pin_cambodia.gemspec
4
+
5
+ gem 'twilreapi-active_call_router', :github => "dwilkie/twilreapi-active_call_router"
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 David Wilkie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Twilreapi::ActiveCallRouter::PinCambodia
2
+
3
+ [![Build Status](https://travis-ci.org/somleng/twilreapi-active_call_router-pin_cambodia.svg?branch=master)](https://travis-ci.org/somleng/twilreapi-active_call_router-pin_cambodia)
4
+
5
+ This gem contains call routing logic for People In Need Cambodia for [Twilreapi.](https://github.com/somleng/twilreapi)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'twilreapi-active_call_router-pin_cambodia', :github => "somleng/twilreapi-active_call_router-pin_cambodia"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Configuration
20
+
21
+ To configure [Twilreapi](https://github.com/somleng/twilreapi) to use `Twilreapi::ActiveBiller::PinCambodia::CallRouter`, set the environment variable `ACTIVE_CALL_ROUTER_CLASS_NAME=Twilreapi::ActiveCallRouter::PinCambodia::CallRouter`
22
+
23
+ The following environment variables can be set to determine the call routing logic:
24
+
25
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_DEFAULT_DIAL_STRING_FORMAT`
26
+ * Defaults to international format. Set to `NATIONAL` to default to national dial string format
27
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_MHEALTH_SOURCE_NUMBER`
28
+ * The source number which determines the call is for mHealth
29
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_MHEALTH_CALLER_ID`
30
+ * The caller id to display for mHealth calls
31
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_EWS_SOURCE_NUMBER`
32
+ * The source number which determines the call is for EWS
33
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_EWS_CALLER_ID`
34
+ * The caller id to display for EWS calls
35
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_TRUNK_PREFIX_REPLACEMENT`
36
+ * The replacement of the trunk prefix. Unset to nil to disable trunk prefix replacement
37
+ * `TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_TRUNK_PREFIX`
38
+ * The trunk prefix to replace. Defaults to '0'
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/somleng/twilreapi-active_call_router-pin_cambodia.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "twilreapi/active_call_router/pin_cambodia"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "twilreapi/active_call_router/pin_cambodia/version"
2
+
3
+ module Twilreapi
4
+ module ActiveCallController
5
+ module PinCambodia
6
+ end
7
+ end
8
+ end
9
+
10
+ require_relative "pin_cambodia/call_router"
@@ -0,0 +1,146 @@
1
+ require "twilreapi/active_call_router/base"
2
+ require_relative "torasup"
3
+
4
+ class Twilreapi::ActiveCallRouter::PinCambodia::CallRouter < Twilreapi::ActiveCallRouter::Base
5
+ DEFAULT_TRUNK_PREFIX = "0"
6
+ attr_accessor :gateway, :caller_id
7
+
8
+ def normalize_from
9
+ if source && trunk_prefix_replacement
10
+ source.sub(/\A((\+)?#{trunk_prefix})/, "\\2#{trunk_prefix_replacement}")
11
+ else
12
+ source
13
+ end
14
+ end
15
+
16
+ def routing_instructions
17
+ @routing_instructions ||= generate_routing_instructions
18
+ end
19
+
20
+ private
21
+
22
+ def phone_call
23
+ options[:phone_call]
24
+ end
25
+
26
+ def from_host
27
+ phone_call.variables["sip_from_host"]
28
+ end
29
+
30
+ def source
31
+ phone_call.from
32
+ end
33
+
34
+ def destination
35
+ phone_call.to
36
+ end
37
+
38
+ def generate_routing_instructions
39
+ set_routing_variables
40
+ gateway_configuration = gateway || {}
41
+ gateway_name = gateway_configuration["name"]
42
+ gateway_host = gateway_configuration["host"]
43
+ gateway_caller_id = gateway_configuration["caller_id"]
44
+ address = normalized_destination
45
+
46
+ address = Phony.format(
47
+ address,
48
+ :format => :national,
49
+ :spaces => ""
50
+ ) if gateway_configuration["prefix"] == false || default_to_national_dial_string_format?
51
+
52
+ if gateway_configuration["trunk"] == false
53
+ address = address.sub(/^0/, "")
54
+ end
55
+
56
+ if gateway_name
57
+ dial_string_path = "gateway/#{gateway_name}/#{address}"
58
+ elsif gateway_host
59
+ dial_string_path = "external/#{address}@#{gateway_host}"
60
+ end
61
+
62
+ routing_instructions = {
63
+ "source" => gateway_caller_id || caller_id || source,
64
+ "destination" => normalized_destination
65
+ }
66
+
67
+ if dial_string_path
68
+ routing_instructions.merge!("dial_string_path" => dial_string_path)
69
+ else
70
+ routing_instructions.merge!("disable_originate" => "1")
71
+ end
72
+
73
+ routing_instructions
74
+ end
75
+
76
+ def set_routing_variables
77
+ case source
78
+ when mhealth_source_number
79
+ self.caller_id = mhealth_caller_id
80
+ self.gateway = mhealth_gateway
81
+ when ews_source_number
82
+ self.caller_id = ews_caller_id
83
+ end
84
+ self.gateway ||= default_gateway
85
+ end
86
+
87
+ def default_gateway
88
+ gateways["default"]
89
+ end
90
+
91
+ def mhealth_gateway
92
+ gateways["mhealth"]
93
+ end
94
+
95
+ def gateways
96
+ operator.gateways || {}
97
+ end
98
+
99
+ def operator
100
+ destination_torasup_number.operator
101
+ end
102
+
103
+ def destination_torasup_number
104
+ @destination_torasup_number ||= Torasup::PhoneNumber.new(normalized_destination)
105
+ end
106
+
107
+ def normalized_destination
108
+ @normalized_destination ||= Phony.normalize(destination)
109
+ end
110
+
111
+ def self.configuration(key)
112
+ ENV["TWILREAPI_ACTIVE_CALL_ROUTER_PIN_CAMBODIA_#{key.to_s.upcase}"]
113
+ end
114
+
115
+ def mhealth_source_number
116
+ self.class.configuration("mhealth_source_number")
117
+ end
118
+
119
+ def mhealth_caller_id
120
+ self.class.configuration("mhealth_caller_id")
121
+ end
122
+
123
+ def ews_source_number
124
+ self.class.configuration("ews_source_number")
125
+ end
126
+
127
+ def ews_caller_id
128
+ self.class.configuration("ews_caller_id")
129
+ end
130
+
131
+ def default_dial_string_format
132
+ self.class.configuration("default_dial_string_format")
133
+ end
134
+
135
+ def default_to_national_dial_string_format?
136
+ default_dial_string_format == "NATIONAL"
137
+ end
138
+
139
+ def trunk_prefix
140
+ self.class.configuration("trunk_prefix") || DEFAULT_TRUNK_PREFIX
141
+ end
142
+
143
+ def trunk_prefix_replacement
144
+ self.class.configuration("trunk_prefix_replacement")
145
+ end
146
+ end
@@ -0,0 +1,2 @@
1
+ require 'torasup'
2
+ require_relative "torasup/configuration"
@@ -0,0 +1,3 @@
1
+ Torasup.configure do |config|
2
+ config.custom_pstn_data_file = File.expand_path('data/pin_cambodia.yml', __dir__)
3
+ end
@@ -0,0 +1,24 @@
1
+ kh:
2
+ operators:
3
+ smart:
4
+ metadata:
5
+ gateways:
6
+ default:
7
+ host: "27.109.112.80"
8
+ prefix: false
9
+ mobitel:
10
+ metadata:
11
+ gateways:
12
+ default:
13
+ host: "103.193.204.7"
14
+ prefix: false
15
+ metfone:
16
+ metadata:
17
+ gateways:
18
+ default:
19
+ host: "175.100.32.29"
20
+ prefix: false
21
+ mhealth:
22
+ host: "103.193.204.7"
23
+ prefix: false
24
+ trunk: false
@@ -0,0 +1,7 @@
1
+ module Twilreapi
2
+ module ActiveCallRouter
3
+ module PinCambodia
4
+ VERSION = "0.2.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twilreapi/active_call_router/pin_cambodia/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twilreapi-active_call_router-pin_cambodia"
8
+ spec.version = Twilreapi::ActiveCallRouter::PinCambodia::VERSION
9
+ spec.authors = ["David Wilkie"]
10
+ spec.email = ["dwilkie@gmail.com"]
11
+
12
+ spec.summary = %q{Call routing for People In Cambodia}
13
+ spec.homepage = "https://github.com/dwilkie/twilreapi-active_call_router-pin_cambodia"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "twilreapi-active_call_router", "~> 0.2.0"
22
+ spec.add_dependency "torasup", "~> 0.1.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry"
28
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twilreapi-active_call_router-pin_cambodia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - David Wilkie
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: twilreapi-active_call_router
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: torasup
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - dwilkie@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/twilreapi/active_call_router/pin_cambodia.rb
114
+ - lib/twilreapi/active_call_router/pin_cambodia/call_router.rb
115
+ - lib/twilreapi/active_call_router/pin_cambodia/torasup.rb
116
+ - lib/twilreapi/active_call_router/pin_cambodia/torasup/configuration.rb
117
+ - lib/twilreapi/active_call_router/pin_cambodia/torasup/data/pin_cambodia.yml
118
+ - lib/twilreapi/active_call_router/pin_cambodia/version.rb
119
+ - twilreapi-active_call_router-pin_cambodia.gemspec
120
+ homepage: https://github.com/dwilkie/twilreapi-active_call_router-pin_cambodia
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.13
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Call routing for People In Cambodia
144
+ test_files: []