Class: KaveRestApi::SendSimple
- Inherits:
-
RequestBase
- Object
- RequestBase
- KaveRestApi::SendSimple
- Includes:
- Validatable
- Defined in:
- lib/kavenegar-ruby/requests/send.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#date ⇒ Object
Returns the value of attribute date.
-
#localid ⇒ Object
Returns the value of attribute localid.
-
#message ⇒ Object
Returns the value of attribute message.
-
#message_size ⇒ Object
readonly
Returns the value of attribute message_size.
-
#receptor ⇒ Object
Returns the value of attribute receptor.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unixdate ⇒ Object
Returns the value of attribute unixdate.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(args = {}) ⇒ SendSimple
constructor
A new instance of SendSimple.
- #valid_message? ⇒ Boolean
- #valid_receptor? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ SendSimple
Returns a new instance of SendSimple.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 12 def initialize(args = {}) super @ACTION_NAME = [:send,@FORMAT].join('.').freeze @receptor = args.fetch(:receptor) if @receptor.kind_of?(Array) @valid_receptor= false if @receptor.length > 200 @receptor = @receptor.join(',') end @receptor = @receptor.ctsd @date = args.fetch(:date,nil) @message = args.fetch(:message) @message = @message.ctsd if args.fetch(:standard_digit,false) @unixdate = args.fetch(:unixdate,nil) @type = args.fetch(:type,nil) @localid = args.fetch(:localid,nil) @sender = args.fetch(:sender,@DEFAULT_SENDER) @response = ResponseSendSimple.new @message_size=@message.multibyte? ? 268:612 @valid_message= (@message.length > @message_size ) ? false:true end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 5 def config @config end |
#date ⇒ Object
Returns the value of attribute date.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def date @date end |
#localid ⇒ Object
Returns the value of attribute localid.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def localid @localid end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def @message end |
#message_size ⇒ Object (readonly)
Returns the value of attribute message_size.
5 6 7 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 5 def @message_size end |
#receptor ⇒ Object
Returns the value of attribute receptor.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def receptor @receptor end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 5 def response @response end |
#sender ⇒ Object
Returns the value of attribute sender.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def sender @sender end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def type @type end |
#unixdate ⇒ Object
Returns the value of attribute unixdate.
4 5 6 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 4 def unixdate @unixdate end |
Instance Method Details
#call ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 42 def call connection = Faraday.new(url: "#{@API_URL}/sms/") do |faraday| faraday.adapter Faraday.default_adapter faraday.response @FORMAT.to_sym end response = connection.get(@ACTION_NAME, receptor: @receptor , message: @message,localid: @localid,sender: @sender,date: @date,type: @type) @response.validate(response.body) end |
#valid_message? ⇒ Boolean
34 35 36 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 34 def @valid_message end |
#valid_receptor? ⇒ Boolean
38 39 40 |
# File 'lib/kavenegar-ruby/requests/send.rb', line 38 def valid_receptor? @valid_receptor end |