Class: SmsFactor
- Inherits:
-
Object
- Object
- SmsFactor
- Defined in:
- lib/sms_factor.rb
Defined Under Namespace
Classes: Configuration, Init, SmsResponse
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#sender ⇒ Object
Returns the value of attribute sender.
Class Method Summary collapse
Instance Method Summary collapse
- #auth_credentials ⇒ Object
- #build ⇒ Object
- #deliver(delay: :now, check: false) ⇒ Object
-
#initialize(message, recipients, sender = nil) ⇒ SmsFactor
constructor
A new instance of SmsFactor.
Constructor Details
#initialize(message, recipients, sender = nil) ⇒ SmsFactor
Returns a new instance of SmsFactor.
7 8 9 10 11 12 13 |
# File 'lib/sms_factor.rb', line 7 def initialize(, recipients, sender = nil) raise "The configuration is not complete. Please define api_url, api_login, api_password and api_default_from" unless SmsFactor::Init.configuration.is_valid? @sender ||= SmsFactor::Init.configuration.api_default_from @recipients = recipients.kind_of?(Array) ? recipients : [recipients] @message = end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/sms_factor.rb', line 5 def @message end |
#recipients ⇒ Object
Returns the value of attribute recipients.
5 6 7 |
# File 'lib/sms_factor.rb', line 5 def recipients @recipients end |
#sender ⇒ Object
Returns the value of attribute sender.
5 6 7 |
# File 'lib/sms_factor.rb', line 5 def sender @sender end |
Class Method Details
Instance Method Details
#auth_credentials ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/sms_factor.rb', line 26 def auth_credentials @auth_credentials ||= { authentication: { username: SmsFactor::Init.configuration.api_login, password: SmsFactor::Init.configuration.api_password } } end |
#build ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sms_factor.rb', line 15 def build { sms: auth_credentials.merge( message: {text: @message, sender: @sender, pushtype: 'alert'}, recipients: { gsm: @recipients.collect{|recipient| {value: recipient}} } ) } end |
#deliver(delay: :now, check: false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sms_factor.rb', line 35 def deliver(delay: :now, check: false) data = case delay when nil, :now build else build[:sms].merge!({delay: delay}) end url = "#{SmsFactor::Init.configuration.api_url}/send" url = "#{url}/simulate" if check SmsFactor::SmsResponse.new( RestClient.post( url, { data: data.to_json }, content_type: :json, accept: :json, verify_ssl: false ) ) end |