gupshup 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -8
- data/lib/gupshup.rb +53 -35
- metadata +21 -9
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= gupshup
|
2
2
|
|
3
|
-
* http://github.com/nileshtrivedi/
|
3
|
+
* http://github.com/nileshtrivedi/gupshup
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -10,10 +10,12 @@ masks, keywords, text/flash/vcard/bulk messages, advertising and keyword
|
|
10
10
|
campaigns and so on.
|
11
11
|
|
12
12
|
Documentation of HTTP APIs is available here:
|
13
|
-
http://enterprise.smsgupshup.com/doc/GatewayAPIDoc.
|
13
|
+
http://enterprise.smsgupshup.com/doc/GatewayAPIDoc.pdf
|
14
14
|
|
15
15
|
== FEATURES:
|
16
16
|
|
17
|
+
* V 0.1.5 Added group_post method and a generic call_api method. All methods
|
18
|
+
now expect a hash of API params instead if individual arguments
|
17
19
|
* V 0.1.2 Bulk file upload implemented. Only CSV format supported for now.
|
18
20
|
* V 0.1.0 send_vcard and send_unicode_message implemented. Error checking.
|
19
21
|
* V 0.0.5 send_text_message and send_flash_message are implemented
|
@@ -23,20 +25,20 @@ http://enterprise.smsgupshup.com/doc/GatewayAPIDoc.doc
|
|
23
25
|
|
24
26
|
# "target_phone_number" should be a 12 digit Indian mobile number starting with "919" (either integer or string)
|
25
27
|
|
26
|
-
gup = Gupshup::Enterprise.new('your_gupshup_login',
|
28
|
+
gup = Gupshup::Enterprise.new(:userid => 'your_gupshup_login', :password => 'your_password')
|
27
29
|
|
28
30
|
#send a normal text message
|
29
|
-
gup.send_text_message('sms message text',
|
31
|
+
gup.send_text_message(:msg => 'sms message text', :send_to => '919xxxxxxxxx')
|
30
32
|
|
31
33
|
#flash messages appear on mobile's screen immediately but may not be saved on some handsets
|
32
|
-
gup.send_flash_message('sms message text',
|
34
|
+
gup.send_flash_message(:msg => 'sms message text', :send_to => '919xxxxxxxxx')
|
33
35
|
|
34
36
|
#send a contact in VCARD format
|
35
37
|
vcard = "BEGIN:VCARD\r\nVERSION:1.2\r\nN:ICICI\r\nTEL:18002098888\r\nEND:VCARD"
|
36
|
-
gup.send_vcard(vcard,
|
38
|
+
gup.send_vcard(:msg => vcard, :send_to => '919xxxxxxxxx')
|
37
39
|
|
38
40
|
#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",
|
41
|
+
gup.send_unicode_message(:msg => "\xE0\xA4\x97\xE0\xA4\xAA\xE0\xA4\xB6\xE0\xA4\xAA", :send_to => '919xxxxxxxxx') # will send "gupshup" in Devnagari script
|
40
42
|
|
41
43
|
#Upload a CSV file for bulk messages
|
42
44
|
gup.bulk_file_upload(file_path)
|
@@ -53,7 +55,7 @@ http://enterprise.smsgupshup.com/doc/GatewayAPIDoc.doc
|
|
53
55
|
|
54
56
|
(The MIT License)
|
55
57
|
|
56
|
-
Copyright (c)
|
58
|
+
Copyright (c) 2010 Nilesh Trivedi
|
57
59
|
|
58
60
|
Permission is hereby granted, free of charge, to any person obtaining
|
59
61
|
a copy of this software and associated documentation files (the
|
data/lib/gupshup.rb
CHANGED
@@ -6,42 +6,40 @@ require 'uri'
|
|
6
6
|
require 'cgi'
|
7
7
|
require 'httpclient'
|
8
8
|
|
9
|
+
class NilClass
|
10
|
+
def blank?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class String
|
16
|
+
def blank?
|
17
|
+
self.empty?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
9
21
|
module Gupshup
|
10
|
-
VERSION = '0.1.
|
22
|
+
VERSION = '0.1.5'
|
11
23
|
class Enterprise
|
12
|
-
def initialize(
|
24
|
+
def initialize(opts)
|
13
25
|
@api_url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest'
|
14
26
|
@api_params = {}
|
15
|
-
@api_params[:userid] =
|
16
|
-
@api_params[:password] = password
|
17
|
-
@api_params[:v] = '1.1'
|
18
|
-
@api_params[:auth_scheme] = 'PLAIN'
|
19
|
-
|
27
|
+
@api_params[:userid] = opts[:userid]
|
28
|
+
@api_params[:password] = opts[:password]
|
29
|
+
@api_params[:v] = opts[:v] || '1.1'
|
30
|
+
@api_params[:auth_scheme] = opts[:auth_scheme] || 'PLAIN'
|
31
|
+
unless opts[:token].blank?
|
20
32
|
@api_params[:auth_scheme] = 'TOKEN'
|
21
|
-
@api_params[:token] = token
|
33
|
+
@api_params[:token] = opts[:token]
|
22
34
|
@api_params.delete(:password)
|
23
35
|
end
|
36
|
+
raise "Invalid credentials" if opts[:userid].blank? || (opts[:password].blank? && opts[:token].blank?)
|
24
37
|
end
|
25
|
-
|
26
|
-
def
|
27
|
-
raise 'Phone Number is too short' if number.to_s.length < 12
|
28
|
-
raise 'Phone Number is too long' if number.to_s.length > 12
|
29
|
-
#raise 'Phone Number should start with "91"' if number.to_s.start_with? "91"
|
30
|
-
raise 'Phone Number should be numerical value' unless number.to_i.to_s == number.to_s
|
31
|
-
raise 'Message should be less than 725 characters long' if msg.to_s.length > 724
|
32
|
-
msg_params = {}
|
33
|
-
msg_params[:method] = 'sendMessage'
|
34
|
-
msg_params[:msg_type] = msg_type.to_s
|
35
|
-
msg_params[:msg] = msg.to_s
|
36
|
-
msg_params[:send_to] = number.to_s
|
37
|
-
#url = URI.parse(@api_url)
|
38
|
-
#req = Net::HTTP::Post.new(url.path)
|
39
|
-
#puts "--- #{msg_params.merge(@api_params).inspect}"
|
40
|
-
#req.set_form_data(msg_params.merge(@api_params))
|
41
|
-
#res = Net::HTTP.new(url.host, url.port).start {|http|http.request(req) }
|
38
|
+
|
39
|
+
def call_api(opts = {})
|
42
40
|
res = Net::HTTP.post_form(
|
43
41
|
URI.parse(@api_url),
|
44
|
-
|
42
|
+
@api_params.merge(opts)
|
45
43
|
)
|
46
44
|
resp = res.body
|
47
45
|
puts "GupShup Response: #{resp}"
|
@@ -49,7 +47,7 @@ module Gupshup
|
|
49
47
|
case res
|
50
48
|
when Net::HTTPSuccess, Net::HTTPRedirection
|
51
49
|
if resp.nil? || resp.include?("success") == false
|
52
|
-
raise "
|
50
|
+
raise "API call '#{opts[:method]}' failed: #{resp}"
|
53
51
|
end
|
54
52
|
return true
|
55
53
|
else
|
@@ -57,20 +55,33 @@ module Gupshup
|
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
|
-
def
|
61
|
-
|
58
|
+
def send_message(opts)
|
59
|
+
msg = opts[:msg]
|
60
|
+
number = opts[:send_to]
|
61
|
+
msg_type = opts[:msg_type] || 'TEXT'
|
62
|
+
|
63
|
+
raise 'Phone Number is too short' if number.to_s.length < 12
|
64
|
+
raise 'Phone Number is too long' if number.to_s.length > 12
|
65
|
+
#raise 'Phone Number should start with "91"' if number.to_s.start_with? "91"
|
66
|
+
raise 'Phone Number should be numerical value' unless number.to_i.to_s == number.to_s
|
67
|
+
raise 'Message should be less than 725 characters long' if msg.to_s.length > 724
|
68
|
+
call_api opts.merge({ :method => 'sendMessage' })
|
69
|
+
end
|
70
|
+
|
71
|
+
def send_flash_message(opts)
|
72
|
+
send_message(opts.merge({ :msg_type => 'FLASH'}))
|
62
73
|
end
|
63
74
|
|
64
|
-
def send_text_message(
|
65
|
-
send_message(
|
75
|
+
def send_text_message(opts)
|
76
|
+
send_message(opts.merge({ :msg_type => 'TEXT'}))
|
66
77
|
end
|
67
78
|
|
68
|
-
def send_vcard(
|
69
|
-
send_message(
|
79
|
+
def send_vcard(opts)
|
80
|
+
send_message(opts.merge({ :msg_type => 'VCARD'}))
|
70
81
|
end
|
71
82
|
|
72
|
-
def send_unicode_message(
|
73
|
-
send_message(
|
83
|
+
def send_unicode_message(opts)
|
84
|
+
send_message(opts.merge({ :msg_type => 'UNICODE_TEXT'}))
|
74
85
|
end
|
75
86
|
|
76
87
|
def bulk_file_upload(file_path,file_type = 'csv',mime_type = 'text/csv', opts = {})
|
@@ -84,5 +95,12 @@ module Gupshup
|
|
84
95
|
file.close
|
85
96
|
puts resp.body.content
|
86
97
|
end
|
98
|
+
|
99
|
+
def group_post(opts)
|
100
|
+
raise "Invalid group name" if opts[:group_name].blank?
|
101
|
+
raise "Invalid message" if opts[:msg].blank?
|
102
|
+
raise "Invalid message type" if opts[:msg_type].blank?
|
103
|
+
call_api opts.merge({:method => 'post_group'})
|
104
|
+
end
|
87
105
|
end
|
88
106
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gupshup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Nilesh Trivedi
|
@@ -9,19 +14,24 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-25 00:00:00 +05:30
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: httpclient
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 1
|
30
|
+
- 5
|
31
|
+
- 2
|
23
32
|
version: 2.1.5.2
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
25
35
|
description: Ruby wrapper for SMSGupShup API
|
26
36
|
email:
|
27
37
|
- nilesh@webaroo.com
|
@@ -59,18 +69,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
69
|
requirements:
|
60
70
|
- - ">="
|
61
71
|
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
62
74
|
version: "0"
|
63
|
-
version:
|
64
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
76
|
requirements:
|
66
77
|
- - ">="
|
67
78
|
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
68
81
|
version: "0"
|
69
|
-
version:
|
70
82
|
requirements: []
|
71
83
|
|
72
84
|
rubyforge_project: gupshup
|
73
|
-
rubygems_version: 1.3.
|
85
|
+
rubygems_version: 1.3.6
|
74
86
|
signing_key:
|
75
87
|
specification_version: 3
|
76
88
|
summary: Ruby wrapper for SMSGupShup API
|