voipms_rates 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7dbba975776307743338eaaea14dfcc16ac458
4
- data.tar.gz: ed82f5766454b66d3d54ee26ce3e04dab092f1d4
3
+ metadata.gz: 6cf6662e6e349dcb6c70f6d332ae8e3a78002324
4
+ data.tar.gz: 537ef583c571d0be3181a16d4d6f332d64bac9c6
5
5
  SHA512:
6
- metadata.gz: 42206a0d55a8e60b0fe57b6b37c8f4bc971b29484e63c8b917df2d05f1ad45e6a070401df39e33942f19f6ebf57c9f3b2f8b8045742b8da92458657b74fa66ac
7
- data.tar.gz: f8d81ff82ea99a071c7d2ee74f42fdcb382f77170c6f0964d02dc2eaf7a1680f8b09abae47055509305247237e3abfe2ea29e638b12e11a14f12859c47a43e47
6
+ metadata.gz: 6089e3f79a9f9f1a10d9e11d5353ee76620076914fe2f1b4bee65fb1ba1a7c89c43d536b3fe6f38983cab79e20ced17b348508a657dead8f0226334a5ea7b1a5
7
+ data.tar.gz: a34112c627adef82de063d13f2859040f7af588db046d78a931e9c5d626bae2c08b670461d657eacd539f691e8c079de36f474379721e1cc99d287509221d496
@@ -1,3 +1,3 @@
1
1
  module VoipmsRates
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module VoipmsRates
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voipms_rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coaxial
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adhearsion
@@ -150,8 +150,8 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.9.3
153
- description: Uses the voip.ms public API to fetch premium or value rates per minute
154
- for any phone number.
153
+ description: An Adhearsion plugin using the voip.ms public API to fetch premium or
154
+ value rates per minute for any phone number.
155
155
  email:
156
156
  - py@poujade.org
157
157
  executables: []
@@ -162,20 +162,14 @@ files:
162
162
  - README.md
163
163
  - Rakefile
164
164
  - lib/voipms_rates.rb
165
- - lib/voipms_rates.rb~
166
165
  - lib/voipms_rates/controller_methods.rb
167
- - lib/voipms_rates/controller_methods.rb~
168
166
  - lib/voipms_rates/plugin.rb
169
- - lib/voipms_rates/plugin.rb~
170
167
  - lib/voipms_rates/version.rb
171
168
  - lib/voipms_rates/version.rb~
172
169
  - spec/spec_helper.rb
173
- - spec/spec_helper.rb~
174
170
  - spec/support/vcr_setup.rb
175
- - spec/support/vcr_setup.rb~
176
171
  - spec/voipms_rates/controller_methods_spec.rb
177
- - spec/voipms_rates/controller_methods_spec.rb~
178
- homepage: ''
172
+ homepage: https://github.com/Coaxial/voipms_rates
179
173
  licenses:
180
174
  - MIT
181
175
  metadata: {}
@@ -195,14 +189,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
189
  version: '0'
196
190
  requirements: []
197
191
  rubyforge_project: voipms_rates
198
- rubygems_version: 2.2.2
192
+ rubygems_version: 2.4.6
199
193
  signing_key:
200
194
  specification_version: 4
201
- summary: Get voip.ms calling rates for given phone numbers.
195
+ summary: voip.ms calling rates within your Adhearsion app.
202
196
  test_files:
203
197
  - spec/spec_helper.rb
204
- - spec/spec_helper.rb~
205
198
  - spec/support/vcr_setup.rb
206
- - spec/support/vcr_setup.rb~
207
199
  - spec/voipms_rates/controller_methods_spec.rb
208
- - spec/voipms_rates/controller_methods_spec.rb~
data/lib/voipms_rates.rb~ DELETED
@@ -1,4 +0,0 @@
1
- # VoipmsRates = Module.new
2
- require "voipms_rates/version"
3
- require "voipms_rates/plugin"
4
- require "voipms_rates/controller_methods"
@@ -1,69 +0,0 @@
1
- module VoipmsRates
2
- module ControllerMethods
3
-
4
- require 'rest-client'
5
- require 'nokogiri'
6
-
7
- # Parameters:
8
- # phone_number [Int] The number for which we want to get the rate
9
- def get_rate_for(phone_number)
10
- if phone_number.match(/(\d*)@.*/)
11
- @digits = phone_number.match(/(\d*)@.*/)[1]
12
- elsif phone_number.match(/[\d]+/)
13
- @digits = phone_number.match(/(\d+)/)[1]
14
- else
15
- raise(TypeError)
16
- end
17
-
18
- return try_patterns(@digits)
19
- end
20
-
21
- def try_patterns(digits)
22
- rates_endpoint = Adhearsion.config[:voipms_rates].rates_endpoint
23
- # The rates API only works with part of the phone number. If it gets the full phone number, it won't find the
24
- # rate. If it doesn't get enough digits, it won't find the rate either. And if it gets too many digits, it won't
25
- # find the rate...
26
- # For example:
27
- # To get the rate for '33912345678' (France), you would need to send '339'
28
- # To get the rate for '15145551234' (Canada), you would need to send '1514'
29
- # To get the rate for '12125551234' (USA), you would need to send '1'
30
- #
31
- high_count = digits.length >= 5 ? 5 : digits.length # This speeds things up with shorter numbers
32
- for i in high_count.downto(1) do
33
- pattern = digits[0, i]
34
- api_response = RestClient.get(rates_endpoint, {
35
- params: {
36
- pattern: pattern
37
- }
38
- })
39
-
40
- xml_doc = Nokogiri::XML(api_response)
41
-
42
- if xml_doc.xpath('/results')[0]
43
- country = xml_doc.at_xpath('/results/item/short_description').content.to_s
44
- return xml_doc.at_xpath('/results/item/rate_premium').content.to_f if ((country === 'Canada' && Adhearsion.config[:voipms_rates].canada_use_premium) || ((country != 'Canada' || country != 'USA') && Adhearsion.config[:voipms_rates].intl_use_premium))
45
- return xml_doc.at_xpath('/results/item/rate').content.to_f
46
-
47
- # We use the premium route for Canada but the value route for all other destinations.
48
- # Because the API sends back both premium and value rates, this has to be done:
49
- #
50
- # country = xml_doc.at_xpath('/results/item/short_description').content.to_s
51
- # case country
52
- # when 'Canada'
53
- # return xml_doc.at_xpath('/results/item/rate_premium').content.to_f
54
- # else
55
- # return xml_doc.at_xpath('/results/item/rate').content.to_f
56
- # end
57
- elsif i === 1 && xml_doc.xpath('error')[0]
58
- error_code = xml_doc.at_xpath('/error/code').content.to_s
59
- error_desc = xml_doc.at_xpath('/error/description').content.to_s
60
-
61
- logger.error("No rate found for '#{pattern}', error code '#{error_code}' (#{error_desc})")
62
- return nil
63
- end
64
- end
65
- end
66
-
67
- private :try_patterns
68
- end
69
- end
@@ -1,53 +0,0 @@
1
- module VoipmsRates
2
- class Plugin < Adhearsion::Plugin
3
-
4
- require_relative "version"
5
-
6
- # Actions to perform when the plugin is loaded
7
- #
8
- init :voipms_rates do
9
- logger.warn "VoipmsRates has been loaded"
10
- end
11
-
12
- # Basic configuration for the plugin
13
- #
14
- config :voipms_rates do
15
- rates_endpoint 'https://www.voip.ms/rates/xmlapi.php', desc: "The URL for voip.ms' rates API endpoint"
16
- canada_use_premium false, desc: "Set to true if you are using premium routing for calls to Canada or false for
17
- standard routing (change this setting on voip.ms > Account Settings > Account Routing)"
18
- intl_use_premium false, desc: "Set to true if you are using premium routing for International calls or false for
19
- standard routing (change this setting on voip.ms > Account Settings > Account Routing)"
20
- end
21
-
22
- # Defining a Rake task is easy
23
- # The following can be invoked with:
24
- # rake plugin_demo:info
25
- #
26
- tasks do
27
- namespace :voipms_rates do
28
- desc "Prints the PluginTemplate information"
29
- task :info do
30
- STDOUT.puts "VoipmsRates plugin v. #{VERSION}"
31
- end
32
-
33
- desc "Checks the current Canada routing setting (Should match your settings on voip.ms > Account Settings >
34
- Account Routing)"
35
- task :canada_use_premium do
36
- rate = Adhearsion.config[:voipms_rates].canada_use_premium ? 'premium' : 'standard'
37
- STDOUT.puts "Using Canada #{rate} routes rate."
38
- # TODO edit with instructions to set in config file
39
- STDOUT.puts "The value can be changed in your app's config file at config/adhearsion.rb"
40
- end
41
-
42
- desc "Checks the current International routing setting (Should match your settings on voip.ms > Account
43
- Settings > Account Routing)"
44
- task :intl_use_premium do
45
- rate = Adhearsion.config[:voipms_rates].intl_use_premium ? 'premium' : 'standard'
46
- STDOUT.puts "Using international #{rate} routes rate."
47
- STDOUT.puts "The value can be changed in your app's config file at config/adhearsion.rb"
48
- end
49
- end
50
- end
51
-
52
- end
53
- end
data/spec/spec_helper.rb~ DELETED
@@ -1,21 +0,0 @@
1
- require 'adhearsion'
2
- require 'voipms_rates'
3
- require 'webmock/rspec'
4
-
5
- # Require any .rb file in spec/support
6
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
-
8
- RSpec.configure do |config|
9
- config.color = true
10
- config.tty = true
11
-
12
- config.filter_run :focus => true
13
- config.run_all_when_everything_filtered = true
14
-
15
- config.before(:each) do
16
- stub_request(:get, /https:\/\/www\.voip\.ms\/rates\/xmlapi\.php/).
17
- with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
18
- to_return(:status => 200, :body => "", :headers => {})
19
- end
20
- end
21
-
@@ -1,5 +0,0 @@
1
- require 'vcr'
2
- VCR.configure do |config|
3
- config.cassette_library_dir = 'fixtures/vcr_cassettes'
4
- config.hook_into :webmock
5
- end
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module VoipmsRates
4
- describe ControllerMethods do
5
- describe "mixed in to a CallController" do
6
-
7
- class TestController < Adhearsion::CallController
8
- include VoipmsRates::ControllerMethods
9
- end
10
-
11
- let(:mock_call) { double 'Call' }
12
-
13
- subject do
14
- TestController.new mock_call
15
- end
16
-
17
- describe '#get_rate_for' do
18
-
19
- let(:canadian_number) { '15145551234' }
20
- let(:us_number) { '12125551234' }
21
- let(:french_number) { '33953123456' }
22
- let(:unroutable_number) { '9' }
23
- let(:sip_string) { 'sip:15145551234@127.0.0.1' }
24
- let(:invalid_string) { 'invalid number' }
25
-
26
- context 'when the premium rate is requested' do
27
-
28
- context 'with a valid number' do
29
- it 'returns the premium rate for Canada' do
30
- # This setting is toggled with `rake voipms_rates:canada_use_premium`
31
- Adhearsion.config[:voipms_rates].canada_use_premium = true
32
- VCR.use_cassette('canada_premium_rate') do
33
- expect(subject.get_rate_for(canadian_number)).to eq(0.009)
34
- end
35
- Adhearsion.config[:voipms_rates].canada_use_premium = false
36
- end
37
-
38
- it 'returns the premium rate for the US' do
39
- VCR.use_cassette('us_premium_rate') do
40
- expect(subject.get_rate_for(us_number)).to eq(0.01)
41
- end
42
- end
43
-
44
- it 'returns the premium rate for France' do
45
- # This setting is toggled with `rake voipms_rates:intl_use_premium`
46
- Adhearsion.config[:voipms_rates].intl_use_premium = true
47
- VCR.use_cassette('france_premium_rate') do
48
- expect(subject.get_rate_for(french_number)).to eq(0.0431)
49
- end
50
- Adhearsion.config[:voipms_rates].intl_use_premium = false
51
- end
52
- end
53
-
54
- context 'with an unroutable number' do
55
- it 'returns "nil"' do
56
- VCR.use_cassette('unroutable_number') do
57
- expect(subject.get_rate_for(unroutable_number)).to eq(nil)
58
- end
59
- end
60
- end
61
- end
62
-
63
- context "when the premium rate isn't requested" do
64
- context 'with a valid number' do
65
- it 'returns the value rate' do
66
- VCR.use_cassette('canada_standard_rate') do
67
- expect(subject.get_rate_for(canadian_number)).to eq(0.0052)
68
- end
69
- end
70
- end
71
-
72
- context 'with an unroutable number' do
73
- it 'returns "nil"' do
74
- VCR.use_cassette('unroutable_number') do
75
- expect(subject.get_rate_for(unroutable_number)).to eq(nil)
76
- end
77
- end
78
- end
79
-
80
- context 'with a sip string' do
81
- it 'returns the rate' do
82
- VCR.use_cassette('sip_string') do
83
- expect(subject.get_rate_for(sip_string)).to eq(0.0052)
84
- end
85
- end
86
- end
87
- end
88
-
89
- context 'with an invalid string' do
90
- it 'returns a TypeError' do
91
- VCR.use_cassette('invalid_string') do
92
- expect{subject.get_rate_for(invalid_string)}.to raise_error
93
- end
94
- end
95
- end
96
- end
97
-
98
- end
99
- end
100
- end