Class: SmsBroker::MessageSender
- Inherits:
-
Object
- Object
- SmsBroker::MessageSender
- Defined in:
- lib/sms_broker/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.
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(client) ⇒ MessageSender
constructor
A new instance of MessageSender.
- #message(text) ⇒ Object
- #to(number) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(client) ⇒ MessageSender
Returns a new instance of MessageSender.
6 7 8 |
# File 'lib/sms_broker/message_sender.rb', line 6 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/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/message_sender.rb', line 3 def errors @errors end |
Instance Method Details
#deliver ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sms_broker/message_sender.rb', line 22 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
16 17 18 19 20 |
# File 'lib/sms_broker/message_sender.rb', line 16 def (text) @message_text = text self end |
#to(number) ⇒ Object
10 11 12 13 14 |
# File 'lib/sms_broker/message_sender.rb', line 10 def to(number) @message_to = number self end |
#valid? ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sms_broker/message_sender.rb', line 36 def valid? schema = { message: Compel.string.required.max_length(140), to: Compel.string.required } object = { message: @message_text, to: @message_to } result = Compel.hash.keys(schema).validate(object) @errors = result.errors result.valid? end |