Class: SmsBroker::VoiceMessageSender
- Inherits:
-
Object
- Object
- SmsBroker::VoiceMessageSender
- Defined in:
- lib/sms_broker/voice_message_sender.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#voice_message_text ⇒ Object
readonly
Returns the value of attribute voice_message_text.
Instance Method Summary collapse
- #build_message(from = :sender_id) ⇒ Object
- #deliver ⇒ Object
-
#initialize(client) ⇒ VoiceMessageSender
constructor
A new instance of VoiceMessageSender.
- #message(text) ⇒ Object
- #to(number) ⇒ Object
- #valid? ⇒ Boolean
- #with(options) ⇒ Object
Constructor Details
#initialize(client) ⇒ VoiceMessageSender
Returns a new instance of VoiceMessageSender.
7 8 9 |
# File 'lib/sms_broker/voice_message_sender.rb', line 7 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/sms_broker/voice_message_sender.rb', line 3 def client @client end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/sms_broker/voice_message_sender.rb', line 3 def errors @errors end |
#voice_message_text ⇒ Object (readonly)
Returns the value of attribute voice_message_text.
3 4 5 |
# File 'lib/sms_broker/voice_message_sender.rb', line 3 def @voice_message_text end |
Instance Method Details
#build_message(from = :sender_id) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/sms_broker/voice_message_sender.rb', line 69 def (from = :sender_id) client.is_a?(SmsBroker::Client::Nexmo) && { text: @voice_message_text, from: get_sender(from), to: @voice_message_to }.merge!(@voice_message_options || {}) end |
#deliver ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sms_broker/voice_message_sender.rb', line 29 def deliver unless valid? return Client::Response::Error.new(client.name, errors, errors) end response = client.() if should_try_with_phone_number?(response) return client.((:phone_number)) end response end |
#message(text) ⇒ Object
17 18 19 20 21 |
# File 'lib/sms_broker/voice_message_sender.rb', line 17 def (text) @voice_message_text = text self end |
#to(number) ⇒ Object
11 12 13 14 15 |
# File 'lib/sms_broker/voice_message_sender.rb', line 11 def to(number) @voice_message_to = number self end |
#valid? ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sms_broker/voice_message_sender.rb', line 43 def valid? = @voice_message_options || {} schema = { message: Compel.string.required.max_length(140), to: Compel.string.required, lang: Compel.string, rate: Compel.integer, repeat: Compel.integer } object = { message: @voice_message_text, to: @voice_message_to, lang: [:lang], rate: [:rate], repeat: [:repeat] } result = Compel.hash.keys(schema).validate(object) @errors = result.errors result.valid? end |
#with(options) ⇒ Object
23 24 25 26 27 |
# File 'lib/sms_broker/voice_message_sender.rb', line 23 def with() @voice_message_options = self end |