Class: Gupshup::Enterprise
- Inherits:
-
Object
- Object
- Gupshup::Enterprise
- Defined in:
- lib/gupshup.rb
Instance Method Summary collapse
-
#initialize(login, password) ⇒ Enterprise
constructor
A new instance of Enterprise.
- #send_flash_message(msg, number, opts = {}) ⇒ Object
- #send_message(msg, number, msg_type = 'TEXT', opts = {}) ⇒ Object
- #send_text_message(msg, number, opts = {}) ⇒ Object
- #send_unicode_message(msg, number, opts = {}) ⇒ Object
- #send_vcard(card, number, opts = {}) ⇒ Object
Constructor Details
#initialize(login, password) ⇒ Enterprise
Returns a new instance of Enterprise.
11 12 13 14 15 16 17 18 |
# File 'lib/gupshup.rb', line 11 def initialize(login,password) @api_url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest' @api_params = {} @api_params[:userid] = login @api_params[:password] = password @api_params[:v] = '1.1' @api_params[:auth_scheme] = 'PLAIN' end |
Instance Method Details
#send_flash_message(msg, number, opts = {}) ⇒ Object
54 55 56 |
# File 'lib/gupshup.rb', line 54 def (msg,number,opts = {}) (msg,number,:FLASH,opts) end |
#send_message(msg, number, msg_type = 'TEXT', opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gupshup.rb', line 20 def (msg,number,msg_type = 'TEXT',opts = {}) raise 'Phone Number is too short' if number.to_s.length < 12 raise 'Phone Number is too long' if number.to_s.length > 12 #raise 'Phone Number should start with "91"' if number.to_s.start_with? "91" raise 'Phone Number should be numerical value' unless number.to_i.to_s == number.to_s raise 'Message should be less than 725 characters long' if msg.to_s.length > 724 msg_params = {} msg_params[:method] = 'sendMessage' msg_params[:msg_type] = msg_type.to_s msg_params[:msg] = msg.to_s msg_params[:send_to] = number.to_s #url = URI.parse(@api_url) #req = Net::HTTP::Post.new(url.path) #puts "--- #{msg_params.merge(@api_params).inspect}" #req.set_form_data(msg_params.merge(@api_params)) #res = Net::HTTP.new(url.host, url.port).start {|http|http.request(req) } res = Net::HTTP.post_form( URI.parse(@api_url), msg_params.merge(@api_params).merge(opts) ) resp = res.body puts "GupShup Response: #{resp}" case res when Net::HTTPSuccess, Net::HTTPRedirection if resp.nil? || resp.include?("success") == false raise "SMS Sending failed: #{resp}" end return true else raise 'GupShup returned HTTP Error' end end |
#send_text_message(msg, number, opts = {}) ⇒ Object
58 59 60 |
# File 'lib/gupshup.rb', line 58 def (msg,number,opts = {}) (msg,number,:TEXT,opts) end |
#send_unicode_message(msg, number, opts = {}) ⇒ Object
66 67 68 |
# File 'lib/gupshup.rb', line 66 def (msg,number,opts = {}) (msg,number,:UNICODE_TEXT,opts) end |
#send_vcard(card, number, opts = {}) ⇒ Object
62 63 64 |
# File 'lib/gupshup.rb', line 62 def send_vcard(card,number,opts = {}) (card,number,:VCARD,opts) end |