Class: Gupshup::Enterprise

Inherits:
Object
  • Object
show all
Defined in:
lib/gupshup.rb

Instance Method Summary collapse

Constructor Details

#initialize(login, password) ⇒ Enterprise

Returns a new instance of Enterprise.



12
13
14
15
16
17
18
19
# File 'lib/gupshup.rb', line 12

def initialize(,password)
  @api_url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest'
  @api_params = {}
  @api_params[:userid] = 
  @api_params[:password] = password
  @api_params[:v] = '1.1'
  @api_params[:auth_scheme] = 'PLAIN'
end

Instance Method Details

#bulk_file_upload(file_path, file_type = 'csv', mime_type = 'text/csv', opts = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gupshup.rb', line 71

def bulk_file_upload(file_path,file_type = 'csv',mime_type = 'text/csv', opts = {})
  msg_params = {}
  msg_params[:method] = 'xlsUpload'
  msg_params[:filetype] = file_type.to_s
  file = File.new(file_path,"r")
  def file.mime_type; "text/csv"; end
  msg_params[:xlsFile] = file
  resp = HTTPClient.post(@api_url,msg_params.merge(@api_params).merge(opts))
  file.close
  puts resp.body.content
end

#send_flash_message(msg, number, opts = {}) ⇒ Object



55
56
57
# File 'lib/gupshup.rb', line 55

def send_flash_message(msg,number,opts = {})
  send_message(msg,number,:FLASH,opts)
end

#send_message(msg, number, msg_type = 'TEXT', opts = {}) ⇒ Object



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
53
# File 'lib/gupshup.rb', line 21

def send_message(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



59
60
61
# File 'lib/gupshup.rb', line 59

def send_text_message(msg,number,opts = {})
  send_message(msg,number,:TEXT,opts)
end

#send_unicode_message(msg, number, opts = {}) ⇒ Object



67
68
69
# File 'lib/gupshup.rb', line 67

def send_unicode_message(msg,number,opts = {})
  send_message(msg,number,:UNICODE_TEXT,opts)
end

#send_vcard(card, number, opts = {}) ⇒ Object



63
64
65
# File 'lib/gupshup.rb', line 63

def send_vcard(card,number,opts = {})
  send_message(card,number,:VCARD,opts)
end