sasswillio 1.0.0 → 1.1.1
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 +30 -3
- data/lib/sasswillio/formatter.rb +11 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f861a50f155cb19f302977cc396ccab1bf8efdff26f6c955f9627011d0da1545
|
4
|
+
data.tar.gz: 2be88199b999aa550754c11ed357bc66132f2ac68799f3a81db848dee3f00d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24f156077cc7da11a30afaf2f19c4dbaae32047cd894d98382b47703bd6610c5a34a2655ce8d4a7374f73162ccab930a1e73813c82b3cea948a134ba5fb82f64
|
7
|
+
data.tar.gz: ffe83843cb50362f6f6c01711f77df0c31ba78e2e9d17e6f19ecef81f1a5189fc2a2551750c7e40ce6e0d4679625bc14bb6346a3e3191264bce7948f96ccc9ac
|
data/lib/sasswillio.rb
CHANGED
@@ -6,6 +6,8 @@ require 'twilio-ruby'
|
|
6
6
|
# sms_pricing = Sasswillio.get_sms_pricing_for(@client)
|
7
7
|
# phone_number_pricing = Sasswillio.get_phone_number_pricing_for(@client)
|
8
8
|
# subaccount = Sasswillio.create_subaccount(@client, '423')
|
9
|
+
# sms_pricing = Sasswillio.get_sms_pricing_for(@client, 'FR')
|
10
|
+
# country_nums = Sasswillio.list_sms_enabled_phone_numbers_for_country(@client, {country_code: 'GB'})
|
9
11
|
|
10
12
|
module Sasswillio
|
11
13
|
|
@@ -38,7 +40,7 @@ module Sasswillio
|
|
38
40
|
|
39
41
|
def self.get_sms_pricing_for(twilio_client, country = 'CA')
|
40
42
|
begin
|
41
|
-
return twilio_client.pricing.v1.messaging.countries(country).fetch
|
43
|
+
return Formatter.aggregate_sms_prices_obj(twilio_client.pricing.v1.messaging.countries(country).fetch)
|
42
44
|
rescue Twilio::REST::TwilioError => e
|
43
45
|
return {
|
44
46
|
error: true,
|
@@ -85,7 +87,7 @@ module Sasswillio
|
|
85
87
|
in_region: options[:region],
|
86
88
|
contains: "#{options[:contains]}*******"
|
87
89
|
)
|
88
|
-
return numbers.map{|n| {number: n.phone_number, capabilities: {**n.capabilities.transform_keys(&:to_sym)}}}
|
90
|
+
return numbers.map{|n| {number: n.phone_number, friendly_name: n.friendly_name, capabilities: {**n.capabilities.transform_keys(&:to_sym)}}}
|
89
91
|
rescue Twilio::REST::TwilioError => e
|
90
92
|
return {
|
91
93
|
error: true,
|
@@ -95,6 +97,29 @@ module Sasswillio
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
100
|
+
def self.list_sms_enabled_phone_numbers_for_country(twilio_client, options = {country_code: 'CA'})
|
101
|
+
numbers = Hash.new
|
102
|
+
begin
|
103
|
+
numbers[:local] = twilio_client.available_phone_numbers(options[:country_code]).local.list(
|
104
|
+
sms_enabled: true,
|
105
|
+
)
|
106
|
+
rescue Twilio::REST::TwilioError => e
|
107
|
+
numbers[:local] = []
|
108
|
+
end
|
109
|
+
|
110
|
+
begin
|
111
|
+
numbers[:mobile] = twilio_client.available_phone_numbers(options[:country_code]).mobile.list(
|
112
|
+
sms_enabled: true,
|
113
|
+
)
|
114
|
+
rescue Twilio::REST::TwilioError => e
|
115
|
+
numbers[:mobile] = []
|
116
|
+
end
|
117
|
+
transformed = Hash.new
|
118
|
+
transformed[:local_numbers] = numbers[:local].map{|n| {number: n.phone_number, friendly_name: n.friendly_name, capabilities: {**n.capabilities.transform_keys(&:to_sym)}}}
|
119
|
+
transformed[:mobile_numbers] = numbers[:mobile].map{|n| {number: n.phone_number, friendly_name: n.friendly_name, capabilities: {**n.capabilities.transform_keys(&:to_sym)}}}
|
120
|
+
return transformed
|
121
|
+
end
|
122
|
+
|
98
123
|
def self.create_subaccount(twilio_client, options)
|
99
124
|
begin
|
100
125
|
# 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
|
@@ -193,4 +218,6 @@ module Sasswillio
|
|
193
218
|
}
|
194
219
|
end
|
195
220
|
end
|
196
|
-
end
|
221
|
+
end
|
222
|
+
|
223
|
+
require 'sasswillio/formatter'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Formatter
|
2
|
+
def self.aggregate_sms_prices_obj(twilio_sms_pricing_res)
|
3
|
+
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'}}
|
5
|
+
return {
|
6
|
+
inbound_sms_price_for_local_number: local_price_inbound ? local_price_inbound["current_price"] : 'no local numbers available, so no pricing',
|
7
|
+
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
|
+
currency: twilio_sms_pricing_res.price_unit,
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sasswillio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shashike J
|
@@ -130,6 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- lib/sasswillio.rb
|
133
|
+
- lib/sasswillio/formatter.rb
|
133
134
|
homepage: https://github.com/donrestarone/sasswillio
|
134
135
|
licenses:
|
135
136
|
- MIT
|