gupshup 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2009-08-17
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -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
@@ -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/nileshtrivedi
3
+
4
+
5
+
6
+
@@ -0,0 +1,75 @@
1
+ = gupshup
2
+
3
+ * http://github.com/nileshtrivedi/smsgupshup
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.doc
14
+
15
+ == FEATURES:
16
+
17
+ * V 0.1.2 Bulk file upload implemented. Only CSV format supported for now.
18
+ * V 0.1.0 send_vcard and send_unicode_message implemented. Error checking.
19
+ * V 0.0.5 send_text_message and send_flash_message are implemented
20
+ * V 0.0.1 send_message is implemented.
21
+
22
+ == USAGE:
23
+
24
+ # "target_phone_number" should be a 12 digit Indian mobile number starting with "919" (either integer or string)
25
+
26
+ gup = Gupshup::Enterprise.new('your_gupshup_login','password')
27
+
28
+ #send a normal text message
29
+ gup.send_text_message('sms message text',target_phone_number)
30
+
31
+ #flash messages appear on mobile's screen immediately but may not be saved on some handsets
32
+ gup.send_flash_message('sms message text',target_phone_number)
33
+
34
+ #send a contact in VCARD format
35
+ vcard = "BEGIN:VCARD\r\nVERSION:1.2\r\nN:ICICI\r\nTEL:18002098888\r\nEND:VCARD"
36
+ gup.send_vcard(vcard,target_phone_number)
37
+
38
+ #send a non-english message with a hex-encoded UTF-8 string
39
+ gup.send_unicode_message("\xE0\xA4\x97\xE0\xA4\xAA\xE0\xA4\xB6\xE0\xA4\xAA",target_phone_number) # will send "gupshup" in Devnagari script
40
+
41
+ #Upload a CSV file for bulk messages
42
+ gup.bulk_file_upload(file_path)
43
+
44
+ == REQUIREMENTS:
45
+
46
+ * httpclient
47
+
48
+ == INSTALL:
49
+
50
+ sudo gem install gupshup
51
+
52
+ == LICENSE:
53
+
54
+ (The MIT License)
55
+
56
+ Copyright (c) 2009 Nilesh Trivedi
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ 'Software'), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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 'Nilesh Trivedi', 'nilesh.tr@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,83 @@
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
+ module Gupshup
10
+ VERSION = '0.1.2'
11
+ class Enterprise
12
+ def initialize(login,password)
13
+ @api_url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest'
14
+ @api_params = {}
15
+ @api_params[:userid] = login
16
+ @api_params[:password] = password
17
+ @api_params[:v] = '1.1'
18
+ @api_params[:auth_scheme] = 'PLAIN'
19
+ end
20
+
21
+ def send_message(msg,number,msg_type = 'TEXT',opts = {})
22
+ raise 'Phone Number is too short' if number.to_s.length < 12
23
+ raise 'Phone Number is too long' if number.to_s.length > 12
24
+ #raise 'Phone Number should start with "91"' if number.to_s.start_with? "91"
25
+ raise 'Phone Number should be numerical value' unless number.to_i.to_s == number.to_s
26
+ raise 'Message should be less than 725 characters long' if msg.to_s.length > 724
27
+ msg_params = {}
28
+ msg_params[:method] = 'sendMessage'
29
+ msg_params[:msg_type] = msg_type.to_s
30
+ msg_params[:msg] = msg.to_s
31
+ msg_params[:send_to] = number.to_s
32
+ #url = URI.parse(@api_url)
33
+ #req = Net::HTTP::Post.new(url.path)
34
+ #puts "--- #{msg_params.merge(@api_params).inspect}"
35
+ #req.set_form_data(msg_params.merge(@api_params))
36
+ #res = Net::HTTP.new(url.host, url.port).start {|http|http.request(req) }
37
+ res = Net::HTTP.post_form(
38
+ URI.parse(@api_url),
39
+ msg_params.merge(@api_params).merge(opts)
40
+ )
41
+ resp = res.body
42
+ puts "GupShup Response: #{resp}"
43
+
44
+ case res
45
+ when Net::HTTPSuccess, Net::HTTPRedirection
46
+ if resp.nil? || resp.include?("success") == false
47
+ raise "SMS Sending failed: #{resp}"
48
+ end
49
+ return true
50
+ else
51
+ raise 'GupShup returned HTTP Error'
52
+ end
53
+ end
54
+
55
+ def send_flash_message(msg,number,opts = {})
56
+ send_message(msg,number,:FLASH,opts)
57
+ end
58
+
59
+ def send_text_message(msg,number,opts = {})
60
+ send_message(msg,number,:TEXT,opts)
61
+ end
62
+
63
+ def send_vcard(card,number,opts = {})
64
+ send_message(card,number,:VCARD,opts)
65
+ end
66
+
67
+ def send_unicode_message(msg,number,opts = {})
68
+ send_message(msg,number,:UNICODE_TEXT,opts)
69
+ end
70
+
71
+ def bulk_file_upload(file_path,file_type = 'csv',mime_type = 'text/csv', opts = {})
72
+ msg_params = {}
73
+ msg_params[:method] = 'xlsUpload'
74
+ msg_params[:filetype] = file_type.to_s
75
+ file = File.new(file_path,"r")
76
+ def file.mime_type; "text/csv"; end
77
+ msg_params[:xlsFile] = file
78
+ resp = HTTPClient.post(@api_url,msg_params.merge(@api_params).merge(opts))
79
+ file.close
80
+ puts resp.body.content
81
+ end
82
+ end
83
+ end
@@ -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"
@@ -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)
@@ -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,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestGupshup < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/gupshup'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gupshup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Nilesh Trivedi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-05 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httpclient
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.5.2
24
+ version:
25
+ description: Ruby wrapper for SMSGupShup API
26
+ email:
27
+ - nilesh.tr@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
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/gupshup.rb
43
+ - script/console
44
+ - script/destroy
45
+ - script/generate
46
+ - test/test_gupshup.rb
47
+ - test/test_helper.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/nileshtrivedi/gupshup
50
+ licenses: []
51
+
52
+ post_install_message: PostInstall.txt
53
+ rdoc_options:
54
+ - --main
55
+ - README.rdoc
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: gupshup
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Ruby wrapper for SMSGupShup API
77
+ test_files:
78
+ - test/test_gupshup.rb
79
+ - test/test_helper.rb