sasswillio 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sasswillio.rb +40 -0
- data/lib/sasswillio/formatter.rb +12 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62ecfe02406c1d26cca5b1bd1da9c3cfc865d17083482f05dc73b5525d828d00
|
4
|
+
data.tar.gz: 3fab714e4e5ac29fa5e0cf142d36b54a85e9a8b0b4d818f91b1df4d66c4fa0c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cad481e00b9b159757a7c09fa4ab2891b9258f184d700728699f1a79f4775bf809b368e3bd5bda8ff4dc6838f73bc5f383fc86774a38ef1103953bbe8d87c819
|
7
|
+
data.tar.gz: d826f52fadb90598f8d36fc400eee0a78c95185d78e7090255cc69ea131331749bbbe07d5f418642202814aa5725db846b41309625cd86a796313db616507fad
|
data/lib/sasswillio.rb
CHANGED
@@ -8,6 +8,7 @@ require 'twilio-ruby'
|
|
8
8
|
# subaccount = Sasswillio.create_subaccount(@client, '423')
|
9
9
|
# sms_pricing = Sasswillio.get_sms_pricing_for(@client, 'FR')
|
10
10
|
# country_nums = Sasswillio.list_sms_enabled_phone_numbers_for_country(@client, {country_code: 'GB'})
|
11
|
+
# numbers_with_pricing = Sasswillio.list_sms_enabled_phone_numbers_for_country_with_pricing(@client, {country_code: 'CA'})
|
11
12
|
|
12
13
|
module Sasswillio
|
13
14
|
|
@@ -120,6 +121,45 @@ module Sasswillio
|
|
120
121
|
return transformed
|
121
122
|
end
|
122
123
|
|
124
|
+
def self.list_sms_enabled_phone_numbers_for_country_with_pricing(twilio_client, options = {country_code: 'CA'})
|
125
|
+
numbers_with_pricing = Hash.new
|
126
|
+
begin
|
127
|
+
available_nums = Sasswillio.list_sms_enabled_phone_numbers_for_country(twilio_client, options)
|
128
|
+
sms_pricing = Sasswillio.get_sms_pricing_for(twilio_client, options[:country_code])
|
129
|
+
phone_number_monthly_costs = Sasswillio.get_phone_number_pricing_for(twilio_client, options[:country_code])
|
130
|
+
available_nums.keys.each do |k|
|
131
|
+
numbers_with_pricing[k] = available_nums[k].map do |n|
|
132
|
+
if k == :local_numbers
|
133
|
+
{
|
134
|
+
**n,
|
135
|
+
sms_pricing: {
|
136
|
+
inbound_cost: sms_pricing[:complete_pricing_for_country][:local_inbound],
|
137
|
+
average_outbound_cost: sms_pricing[:complete_pricing_for_country][:local_outbound_average]
|
138
|
+
},
|
139
|
+
monthly_cost: phone_number_monthly_costs.phone_number_prices.find{|c| c["number_type"] == 'local'} ? phone_number_monthly_costs.phone_number_prices.find{|c| c["number_type"] == 'local'}["current_price"] : nil
|
140
|
+
}
|
141
|
+
elsif k == :mobile_numbers
|
142
|
+
{
|
143
|
+
**n,
|
144
|
+
sms_pricing: {
|
145
|
+
inbound_cost: sms_pricing[:complete_pricing_for_country][:mobile_inbound],
|
146
|
+
average_outbound_cost: sms_pricing[:complete_pricing_for_country][:mobile_outbound_average]
|
147
|
+
},
|
148
|
+
monthly_cost: phone_number_monthly_costs.phone_number_prices.find{|c| c["number_type"] == 'mobile'} ? phone_number_monthly_costs.phone_number_prices.find{|c| c["number_type"] == 'mobile'}["current_price"] : nil
|
149
|
+
}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
return numbers_with_pricing
|
154
|
+
rescue Twilio::REST::TwilioError => e
|
155
|
+
return {
|
156
|
+
error: true,
|
157
|
+
errors: [e.message],
|
158
|
+
context: 'list sms enabled phone numbers for country with pricing'
|
159
|
+
}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
123
163
|
def self.create_subaccount(twilio_client, options)
|
124
164
|
begin
|
125
165
|
# save the sid + token and associate it with your Saas user. This will be used to buy phone numbers and send messages on their behalf
|
data/lib/sasswillio/formatter.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
module Formatter
|
2
2
|
def self.aggregate_sms_prices_obj(twilio_sms_pricing_res)
|
3
|
+
pricing_hash = Hash.new
|
4
|
+
phone_number_types = twilio_sms_pricing_res.inbound_sms_prices.map{|h| h["number_type"]}
|
5
|
+
phone_number_types.each do |type|
|
6
|
+
transformed_key_for_inbound = type + '_inbound'
|
7
|
+
transformed_key_for_outbound = type + '_outbound_average'
|
8
|
+
pricing_hash[transformed_key_for_inbound.to_sym] = twilio_sms_pricing_res.inbound_sms_prices.find{|n| n["number_type"] == type}
|
9
|
+
pricing_hash[transformed_key_for_outbound.to_sym] = twilio_sms_pricing_res.outbound_sms_prices.map{|n| n["prices"].find{|i| i["number_type"] == type}}.compact.map{|n| n["current_price"].to_f}.inject{|sum, el| sum+el} / twilio_sms_pricing_res.outbound_sms_prices.size
|
10
|
+
end
|
3
11
|
local_price_inbound = twilio_sms_pricing_res.inbound_sms_prices.find{|n| n["number_type"] == 'local'}
|
4
|
-
local_price_outbound = twilio_sms_pricing_res.outbound_sms_prices.map{|n| n["prices"].find{|i| i["number_type"] == 'local'}}
|
12
|
+
local_price_outbound = twilio_sms_pricing_res.outbound_sms_prices.map{|n| n["prices"].find{|i| i["number_type"] == 'local'}}.compact
|
5
13
|
return {
|
6
14
|
inbound_sms_price_for_local_number: local_price_inbound ? local_price_inbound["current_price"] : 'no local numbers available, so no pricing',
|
7
15
|
average_outbound_sms_price_for_local_number: local_price_outbound ? local_price_outbound.map{|n| n["current_price"].to_f}.inject{|sum, el| sum+el} / twilio_sms_pricing_res.outbound_sms_prices.size : 'no local numbers available, so no pricing',
|
8
16
|
currency: twilio_sms_pricing_res.price_unit,
|
17
|
+
complete_pricing_for_country: {
|
18
|
+
**pricing_hash
|
19
|
+
}
|
9
20
|
}
|
10
21
|
end
|
11
22
|
end
|