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.3.0"

Class Method Summary collapse

Methods included from API

messages_uri, send_response

Class Method Details

.configurationObject


8
9
10
# File 'lib/twilito/configuration.rb', line 8

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:


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
20
21
22
23
24
25
# File 'lib/twilito.rb', line 15

def send_sms(**args)
  response = send_sms!(**args)
  Result.success(
    response: response,
    sid: JSON.parse(response.read_body)['sid']
  )
rescue SendError => e
  Result.failure(errors: [e.message], response: e.response)
rescue JSON::ParserError
  Result.failure(errors: ['Unable to parse response'], response: response)
end

.send_sms!(**args) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/twilito.rb', line 27

def send_sms!(**args)
  args = merge_configuration(args)

  send_response(args).tap do |response|
    raise SendError.new('Error from Twilio API', response) unless response.is_a? Net::HTTPSuccess
  end
end