Module: Twilito
- Extended by:
- API
- Defined in:
- lib/twilito.rb,
lib/twilito/api.rb,
lib/twilito/result.rb,
lib/twilito/version.rb,
lib/twilito/send_error.rb,
lib/twilito/configuration.rb
Defined Under Namespace
Modules: API
Classes: ArgumentError, Configuration, Result, SendError
Constant Summary
collapse
- VERSION =
"0.5.0"
Class Method Summary
collapse
Methods included from API
messages_uri, send_response
Class Method Details
.configuration ⇒ Object
8
9
10
|
# File 'lib/twilito/configuration.rb', line 8
def self.configuration
@configuration ||= Configuration.new
end
|
4
5
6
|
# File 'lib/twilito/configuration.rb', line 4
def self.configure
yield(configuration)
end
|
.reset_configuration! ⇒ Object
12
13
14
|
# File 'lib/twilito/configuration.rb', line 12
def self.reset_configuration!
@configuration = Configuration.new
end
|
.send_sms(**args) ⇒ Object
15
16
17
18
19
|
# File 'lib/twilito.rb', line 15
def send_sms(**args)
send_sms!(**args)
rescue SendError => e
Result.failure(errors: [e.message], response: e.response)
end
|
.send_sms!(**args) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/twilito.rb', line 21
def send_sms!(**args)
args = merge_configuration(args)
response = send_response(args)
unless response.is_a? Net::HTTPSuccess
raise SendError.new('Error from Twilio API', response)
end
Result.success(response: response, sid: JSON.parse(response.body)['sid'])
rescue JSON::ParserError => e
raise SendError.new("Unable to parse response from Twilio API. Error: #{e.message}", response)
end
|