parity-gupshup 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51f08a2eac81546f3fc1ef012873629d484ee230
4
+ data.tar.gz: 395305135e166bdba411d4c22b12353034d3ab07
5
+ SHA512:
6
+ metadata.gz: 5fa6f769c19fb8144b9464c539bbdf0664ce873e4e421215acb8a270debd85ce052dc41097132850fd20d68cfb433db99e31935f6dcdc28f74245465128c3d6c
7
+ data.tar.gz: 1bf81ef8bfada13b059e3dec69b5203fe6a34c58864ad6f876624465425316405201c9486b8e1147987104940ce3bdfa1c966d4b5ea68afe2def04ea27e6df06
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2009-08-17
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/gupshup.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/test_gupshup.rb
11
+ test/test_helper.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,6 @@
1
+ For more information on SMS GupShup product, see http://enterprise.smsgupshup.com
2
+ For more information on gupshup gem, see http://github.com/parity
3
+
4
+
5
+
6
+
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ = gupshup
2
+
3
+ * http://github.com/parity/gupshup
4
+
5
+ == DESCRIPTION
6
+
7
+ gupshup is a Ruby wrapper for the HTTP APIs provided by SMS GupShup which
8
+ is a Group SMS Platform for the enterprises with advanced features such as
9
+ masks, keywords, text/flash/vcard/bulk messages, advertising and keyword
10
+ campaigns and so on.
11
+
12
+ Documentation of HTTP APIs is available here:
13
+ http://enterprise.smsgupshup.com/doc/GatewayAPIDoc.pdf
14
+
15
+ == FEATURES
16
+
17
+ * V 0.2.0 Return boolean status instead of raising exceptions. API_URL is now configurable.
18
+ * V 0.1.5 Added group_post method and a generic call_api method. All methods now expect a hash of API params instead if individual arguments
19
+ * V 0.1.2 Bulk file upload implemented. Only CSV format supported for now.
20
+ * V 0.1.0 send_vcard and send_unicode_message implemented. Error checking.
21
+ * V 0.0.5 send_text_message and send_flash_message are implemented
22
+ * V 0.0.1 send_message is implemented.
23
+
24
+ == USAGE
25
+
26
+ # "target_phone_number" should be a 12 digit Indian mobile number starting with "91" (either integer or string)
27
+
28
+ gup = Gupshup::Enterprise.new(:userid => 'your_gupshup_login', :password => 'your_password')
29
+
30
+ #optional parameters
31
+ mask - An alphanumeric string with maximum length of 8 characters. Each enterprise account has a default mask. Each account can have multiple masks, preapproved by Enterprise Support team. If no mask is specified, the default mask is chosen.
32
+
33
+ override_dnd - Specifies if the message to be sent to a number listed in DND(Do Not Disturb) list. By default value is false
34
+
35
+ gup = Gupshup::Enterprise.new(:userid => 'your_gupshup_login', :password => 'your_password', :mask => 'maskname', :override_dnd => true)
36
+
37
+
38
+ #send a normal text message
39
+ gup.send_text_message(:msg => 'sms message text', :send_to => '91xxxxxxxxxx')
40
+
41
+ #flash messages appear on mobile's screen immediately but may not be saved on some handsets
42
+ gup.send_flash_message(:msg => 'sms message text', :send_to => '91xxxxxxxxxx')
43
+
44
+ #send a contact in VCARD format
45
+ vcard = "BEGIN:VCARD\r\nVERSION:1.2\r\nN:ICICI\r\nTEL:18002098888\r\nEND:VCARD"
46
+ gup.send_vcard(:msg => vcard, :send_to => '91xxxxxxxxxx')
47
+
48
+ #send a non-english message with a hex-encoded UTF-8 string
49
+ gup.send_unicode_message(:msg => "\xE0\xA4\x97\xE0\xA4\xAA\xE0\xA4\xB6\xE0\xA4\xAA", :send_to => '91xxxxxxxxxx') # will send "gupshup" in Devnagari script
50
+
51
+ #Upload a CSV file for bulk messages
52
+ gup.bulk_file_upload(file_path)
53
+
54
+ == REQUIREMENTS
55
+
56
+ * httpclient
57
+
58
+ == Installation
59
+ * Include the gem in your Gemfile:
60
+
61
+ gem 'parity-gupshup', '~> 1.0.0'
62
+
63
+ * Or
64
+
65
+ sudo gem install parity-gupshup
66
+
67
+
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/gupshup'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'gupshup' do
14
+ self.developer 'Beena Shetty', 'binu.shetty@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,109 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'cgi'
7
+ require 'httpclient'
8
+
9
+ class NilClass
10
+ def blank?
11
+ true
12
+ end unless nil.respond_to? :blank?
13
+ end
14
+
15
+ class String
16
+ def blank?
17
+ self !~ /\S/
18
+ end unless "".respond_to? :blank?
19
+ end
20
+
21
+ module Gupshup
22
+ VERSION = '0.2.1'
23
+ class Enterprise
24
+ def initialize(opts)
25
+ @api_url = opts[:api_url] || 'http://enterprise.smsgupshup.com/GatewayAPI/rest'
26
+ @api_params = {}
27
+ @api_params[:userid] = opts[:userid]
28
+ @api_params[:password] = opts[:password]
29
+ @api_params[:mask] = opts[:mask] if opts[:mask]
30
+ @api_params[:override_dnd] = opts[:override_dnd] || false
31
+ @api_params[:v] = opts[:v] || '1.1'
32
+ @api_params[:auth_scheme] = opts[:auth_scheme] || 'PLAIN'
33
+ unless opts[:token].blank?
34
+ @api_params[:auth_scheme] = 'TOKEN'
35
+ @api_params[:token] = opts[:token]
36
+ @api_params.delete(:password)
37
+ end
38
+ raise "Invalid credentials" if opts[:userid].blank? || (opts[:password].blank? && opts[:token].blank?)
39
+ end
40
+
41
+ def call_api(opts = {})
42
+ res = Net::HTTP.post_form(
43
+ URI.parse(@api_url),
44
+ @api_params.merge(opts)
45
+ )
46
+ resp = res.body
47
+ puts "GupShup Response: #{resp}"
48
+
49
+ case res
50
+ when Net::HTTPSuccess
51
+ if resp.nil? || resp.include?("success") == false
52
+ puts "API call '#{opts[:method]}' failed: #{resp}"
53
+ return false, resp
54
+ end
55
+ return true, nil
56
+ else
57
+ return false, "HTTP Error : #{res}"
58
+ end
59
+ end
60
+
61
+ def send_message(opts)
62
+ msg = opts[:msg]
63
+ number = opts[:send_to]
64
+ msg_type = opts[:msg_type] || 'TEXT'
65
+
66
+ return false, 'Phone Number is too short' if number.to_s.length < 12
67
+ return false, 'Phone Number is too long' if number.to_s.length > 12
68
+ #return false, 'Phone Number should start with "91"' if number.to_s.start_with? "91"
69
+ return false, 'Phone Number should be numerical value' unless number.to_i.to_s == number.to_s
70
+ return false, 'Message cannot be empty' if msg.to_s.length == 0
71
+ return false, 'Message should be less than 725 characters long' if msg.to_s.length > 724
72
+ call_api opts.merge({ :method => 'sendMessage' })
73
+ end
74
+
75
+ def send_flash_message(opts)
76
+ send_message(opts.merge({ :msg_type => 'FLASH'}))
77
+ end
78
+
79
+ def send_text_message(opts)
80
+ send_message(opts.merge({ :msg_type => 'TEXT'}))
81
+ end
82
+
83
+ def send_vcard(opts)
84
+ send_message(opts.merge({ :msg_type => 'VCARD'}))
85
+ end
86
+
87
+ def send_unicode_message(opts)
88
+ send_message(opts.merge({ :msg_type => 'UNICODE_TEXT'}))
89
+ end
90
+
91
+ def bulk_file_upload(file_path,file_type = 'csv',mime_type = 'text/csv', opts = {})
92
+ msg_params = {}
93
+ msg_params[:method] = 'xlsUpload'
94
+ msg_params[:filetype] = file_type.to_s
95
+ file = File.new(file_path,"r")
96
+ def file.mime_type; "text/csv"; end
97
+ msg_params[:xlsFile] = file
98
+ resp = HTTPClient.post(@api_url,msg_params.merge(@api_params).merge(opts))
99
+ file.close
100
+ end
101
+
102
+ def group_post(opts)
103
+ return false,"Invalid group name" if opts[:group_name].blank?
104
+ return false,"Invalid message" if opts[:msg].blank?
105
+ return false,"Invalid message type" if opts[:msg_type].blank?
106
+ call_api opts.merge({:method => 'post_group'})
107
+ end
108
+ end
109
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/gupshup.rb'}"
9
+ puts "Loading gupshup gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,37 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
3
+ class TestGupshup < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @gup = Gupshup::Enterprise.new(:userid => '19009888', :password => 'test')
7
+ end
8
+
9
+ def test_truth
10
+ assert_equal([true, nil], @gup.send_text_message(msg: "Testing", send_to: "919453456689"))
11
+ end
12
+
13
+ def test_failure
14
+ assert_not_equal([true, nil], @gup.send_text_message(msg: "Testing", send_to: "4567777888"))
15
+ end
16
+
17
+ def test_creditional
18
+ assert_raise( RuntimeError ){Gupshup::Enterprise.new(userid: "")}
19
+ end
20
+
21
+ def test_short_phone_number
22
+ assert_equal([false, "Phone Number is too short"], @gup.send_text_message(msg: "Testing", send_to: "9194567890"))
23
+ end
24
+
25
+ def test_long_phone_number
26
+ assert_equal([false, "Phone Number is too long"], @gup.send_text_message(msg: "Testing", send_to: "91945678901123"))
27
+ end
28
+
29
+ def test_string
30
+ assert_equal([false, "Phone Number should be numerical value"], @gup.send_text_message(msg: "Testing", send_to: "hellotest123"))
31
+ end
32
+
33
+ def test_empty_msg
34
+ assert_equal([false, "Message cannot be empty"], @gup.send_text_message(msg: "", send_to: "919453456689"))
35
+ end
36
+
37
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/gupshup'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parity-gupshup
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Beena Shetty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.5.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.5.2
27
+ description: Ruby wrapper for SMSGupShup API
28
+ email:
29
+ - binu.shetty@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - PostInstall.txt
40
+ - README.rdoc
41
+ - Rakefile
42
+ - lib/parity-gupshup.rb
43
+ - script/console
44
+ - script/destroy
45
+ - script/generate
46
+ - test/test_gupshup.rb
47
+ - test/test_helper.rb
48
+ homepage: http://github.com/parity/gupshup
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message: PostInstall.txt
52
+ rdoc_options:
53
+ - "--main"
54
+ - README.rdoc
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: parity-gupshup
69
+ rubygems_version: 2.4.8
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Ruby wrapper for SMSGupShup API
73
+ test_files:
74
+ - test/test_gupshup.rb
75
+ - test/test_helper.rb
76
+ has_rdoc: