sasswillio 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: 36748b53a2c4bca267b718a64ad1cf0d05635e3a12c959ab47cd9a90bea78098
4
- data.tar.gz: 591169d80dc3b62517484e79d9758ce49f203565016e7de7eb592f9ea0c1ca87
3
+ metadata.gz: 846da3f8ba8c1607855ba02d78c8d0b17557816e8d94c54ae812a1acbeec52a4
4
+ data.tar.gz: c3bfe454c65b4db675dc23c108c89bc1d5c90ea0de632799fcd8879cf8ff0d70
5
5
  SHA512:
6
- metadata.gz: e3b9955c6348bfeef9c1cedae294a31ac8df35d9e4371ba78ed85b7a3593efa847e4698d476a9390aae35d79c004a4c3c16f08efe15e145e88efac1e995638a3
7
- data.tar.gz: 47a2a75c91085088b60a7fd89430d3903e93508f0aaedcf59a24b52116019c2854a60612ce2da26448c6926b2dd29d1a7c93f5fb49b88bf3a868a0cc645a23b6
6
+ metadata.gz: 87a51d8bd34529a422cb001233335d37969275803b107d550cbf4e4657730598ce5c7139779b2b77cf3708e9f69bd72543684a1e06c25fafb28086e36834ff14
7
+ data.tar.gz: 17f7f0cda49481a995338a0d29641635d0ef71cfd4da6f017348b187ab3198b0421fc5c30e2b28ac30d8245d67062b46a046c8785fe486f878a3f93af49c0dc2
@@ -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,
@@ -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
+ numbers[:mobile] = twilio_client.available_phone_numbers(options[:country_code]).mobile.list(
107
+ sms_enabled: true,
108
+ )
109
+
110
+ transformed = Hash.new
111
+ transformed[:local_numbers] = numbers[:local].map{|n| {number: n.phone_number, capabilities: {**n.capabilities.transform_keys(&:to_sym), friendly_name: n.friendly_name}}}
112
+ transformed[:mobile_numbers] = numbers[:mobile].map{|n| {number: n.phone_number, capabilities: {**n.capabilities.transform_keys(&:to_sym), friendly_name: n.friendly_name}}}
113
+ return transformed
114
+ rescue Twilio::REST::TwilioError => e
115
+ return {
116
+ error: true,
117
+ errors: [e.message],
118
+ context: 'list sms enable phone numbers for country'
119
+ }
120
+ end
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,15 @@
1
+
2
+ # remove
3
+ require 'pry'
4
+
5
+ module Formatter
6
+ def self.aggregate_sms_prices_obj(twilio_sms_pricing_res)
7
+ local_price_inbound = twilio_sms_pricing_res.inbound_sms_prices.find{|n| n["number_type"] == 'local'}
8
+ local_price_outbound = twilio_sms_pricing_res.outbound_sms_prices.map{|n| n["prices"].find{|i| i["number_type"] == 'local'}}
9
+ return {
10
+ inbound_sms_price_for_local_number: local_price_inbound ? local_price_inbound["current_price"] : 'no local numbers available, so no pricing',
11
+ 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',
12
+ currency: twilio_sms_pricing_res.price_unit,
13
+ }
14
+ end
15
+ 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.0.1
4
+ version: 1.0.2
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