sasswillio 1.0.0
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 +7 -0
- data/lib/sasswillio.rb +196 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1dc88f07f2fb3da77ffae1f287f4e82e5eea22143d78dc937cc8c7dba99ee554
|
4
|
+
data.tar.gz: 9ec23a849d765dbfcdca1d71dc9e6bb9592b5c9f1b416bcf6a5587ac40eabdf6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7963585429ee068f8c7fdf5cfcad63f1a48a47d17b18fc010b5dfad47a1c8f2eea77dd97515b1475b7fc0183b17565cd81f7a206fd38909ce9bc21c21f388abf
|
7
|
+
data.tar.gz: 72362e01bfa3754296020f6aa57af308379838f07e7a295522c66453db54f2ce07c0c56f7140a73ef2ff69db88ade859d9085ac6e68fa195dc3ffefc30a8314d
|
data/lib/sasswillio.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'twilio-ruby'
|
2
|
+
# usage
|
3
|
+
# require 'sasswillio'
|
4
|
+
# @client = Sasswillio.init
|
5
|
+
# nums = Sasswillio.list_sms_enabled_phone_numbers_for(@client)
|
6
|
+
# sms_pricing = Sasswillio.get_sms_pricing_for(@client)
|
7
|
+
# phone_number_pricing = Sasswillio.get_phone_number_pricing_for(@client)
|
8
|
+
# subaccount = Sasswillio.create_subaccount(@client, '423')
|
9
|
+
|
10
|
+
module Sasswillio
|
11
|
+
|
12
|
+
def self.get_credentials
|
13
|
+
if ENV['TWILIO_ACCOUNT_SID'] && ENV['TWILIO_ACCOUNT_AUTH_TOKEN']
|
14
|
+
return {
|
15
|
+
sid: ENV['TWILIO_ACCOUNT_SID'],
|
16
|
+
token: ENV['TWILIO_ACCOUNT_AUTH_TOKEN']
|
17
|
+
}
|
18
|
+
else
|
19
|
+
return {
|
20
|
+
sid: 'AC7fbd312e3dbfc2a44499e7ef59d5b303',
|
21
|
+
token: '1df1dbcdac772278cc7091a0584d3858'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.init
|
27
|
+
credentials = Sasswillio.get_credentials
|
28
|
+
begin
|
29
|
+
return Twilio::REST::Client.new credentials[:sid], credentials[:token]
|
30
|
+
rescue Twilio::REST::TwilioError => e
|
31
|
+
return {
|
32
|
+
error: true,
|
33
|
+
errors: [e.message],
|
34
|
+
context: 'client initialization'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get_sms_pricing_for(twilio_client, country = 'CA')
|
40
|
+
begin
|
41
|
+
return twilio_client.pricing.v1.messaging.countries(country).fetch
|
42
|
+
rescue Twilio::REST::TwilioError => e
|
43
|
+
return {
|
44
|
+
error: true,
|
45
|
+
errors: [e.message],
|
46
|
+
context: 'sms pricing for country'
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.get_phone_number_pricing_for(twilio_client, country = 'CA')
|
52
|
+
begin
|
53
|
+
return twilio_client.pricing.v1.phone_numbers.countries(country).fetch
|
54
|
+
rescue Twilio::REST::TwilioError => e
|
55
|
+
return {
|
56
|
+
error: true,
|
57
|
+
errors: [e.message],
|
58
|
+
context: 'monthly cost for local & toll free numbers'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.provision_sms_number_for_subaccount(twilio_client, sid, options)
|
64
|
+
begin
|
65
|
+
return Sasswillio.fetch_subaccount(twilio_client, sid).incoming_phone_numbers.create(
|
66
|
+
phone_number: options[:phone_number],
|
67
|
+
sms_method: 'POST',
|
68
|
+
sms_url: options[:sms_path],
|
69
|
+
status_callback: options[:sms_status_path],
|
70
|
+
status_callback_method: 'POST',
|
71
|
+
)
|
72
|
+
rescue Twilio::REST::TwilioError => e
|
73
|
+
return {
|
74
|
+
error: true,
|
75
|
+
errors: [e.message],
|
76
|
+
context: 'provision sms number for subaccount'
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.list_sms_enabled_phone_numbers_for(twilio_client, options = {country_code: 'CA', region: 'ON', contains: '647'})
|
82
|
+
begin
|
83
|
+
numbers = twilio_client.available_phone_numbers(options[:country_code]).local.list(
|
84
|
+
sms_enabled: true,
|
85
|
+
in_region: options[:region],
|
86
|
+
contains: "#{options[:contains]}*******"
|
87
|
+
)
|
88
|
+
return numbers.map{|n| {number: n.phone_number, capabilities: {**n.capabilities.transform_keys(&:to_sym)}}}
|
89
|
+
rescue Twilio::REST::TwilioError => e
|
90
|
+
return {
|
91
|
+
error: true,
|
92
|
+
errors: [e.message],
|
93
|
+
context: 'list sms enable phone numbers'
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.create_subaccount(twilio_client, options)
|
99
|
+
begin
|
100
|
+
# 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
|
101
|
+
return twilio_client.api.accounts.create(
|
102
|
+
friendly_name: options[:reference],
|
103
|
+
)
|
104
|
+
rescue Twilio::REST::TwilioError => e
|
105
|
+
return {
|
106
|
+
error: true,
|
107
|
+
errors: [e.message],
|
108
|
+
context: 'create subaccount'
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.fetch_subaccount(twilio_client, sid)
|
114
|
+
begin
|
115
|
+
return twilio_client.api.accounts(sid).fetch
|
116
|
+
rescue Twilio::REST::TwilioError => e
|
117
|
+
return {
|
118
|
+
error: true,
|
119
|
+
errors: [e.message],
|
120
|
+
context: 'fetch subaccount'
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.suspend_subaccount(twilio_client, sid)
|
126
|
+
# sending and recieving messages is disabled when suspended
|
127
|
+
begin
|
128
|
+
return Sasswillio.fetch_subaccount(twilio_client, sid).update(status: 'suspended')
|
129
|
+
rescue Twilio::REST::TwilioError => e
|
130
|
+
return {
|
131
|
+
error: true,
|
132
|
+
errors: [e.message],
|
133
|
+
context: 'suspend subaccount'
|
134
|
+
}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.close_subaccount(twilio_client, sid)
|
139
|
+
# when closed owned numbers are released back to twilio
|
140
|
+
begin
|
141
|
+
return Sasswillio.fetch_subaccount(twilio_client, sid).update(status: 'closed')
|
142
|
+
rescue Twilio::REST::TwilioError => e
|
143
|
+
return {
|
144
|
+
error: true,
|
145
|
+
errors: [e.message],
|
146
|
+
context: 'close subaccount'
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.activate_subaccount(twilio_client, sid)
|
152
|
+
# sending and recieving messages is possible when activated
|
153
|
+
begin
|
154
|
+
return Sasswillio.fetch_subaccount(twilio_client, sid).update(status: 'active')
|
155
|
+
rescue Twilio::REST::TwilioError => e
|
156
|
+
return {
|
157
|
+
error: true,
|
158
|
+
errors: [e.message],
|
159
|
+
context: 'activate subaccount'
|
160
|
+
}
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.get_subaccount_usage(subaccount_sid, subaccount_token, options)
|
165
|
+
begin
|
166
|
+
sub_account_client = Twilio::REST::Client.new subaccount_sid, subaccount_token
|
167
|
+
return sub_account_client.usage.records.list(
|
168
|
+
category: 'totalprice',
|
169
|
+
start_date: options[:start_date],
|
170
|
+
end_date: options[:end_date]
|
171
|
+
)
|
172
|
+
rescue Twilio::REST::TwilioError => e
|
173
|
+
return {
|
174
|
+
error: true,
|
175
|
+
errors: [e.message],
|
176
|
+
context: 'subaccount usage query'
|
177
|
+
}
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.send_text_message(twilio_client, body, to_number, from_number = "+15005550006")
|
182
|
+
begin
|
183
|
+
return twilio_client.messages.create(
|
184
|
+
body: body,
|
185
|
+
to: to_number,
|
186
|
+
from: from_number
|
187
|
+
)
|
188
|
+
rescue Twilio::REST::TwilioError => e
|
189
|
+
return {
|
190
|
+
error: true,
|
191
|
+
errors: [e.message],
|
192
|
+
context: 'send message'
|
193
|
+
}
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sasswillio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shashike J
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twilio-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.34'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.34'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.9.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-core
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.9.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-expectations
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.9.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.9.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.17.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.17.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov-html
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: twilio_mock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.4.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.12.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.12.2
|
125
|
+
description: a simple ruby gem that wraps around the twilio API allowing you to build
|
126
|
+
an SMS enabled SaaS product more erganomically.
|
127
|
+
email: shashikejayatunge@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- lib/sasswillio.rb
|
133
|
+
homepage: https://github.com/donrestarone/sasswillio
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubygems_version: 3.0.3
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: a thin twillio API wrapper
|
156
|
+
test_files: []
|