gupshup 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +1 -0
  2. data/lib/gupshup.rb +23 -18
  3. metadata +6 -7
@@ -14,6 +14,7 @@ http://enterprise.smsgupshup.com/doc/GatewayAPIDoc.pdf
14
14
 
15
15
  == FEATURES:
16
16
 
17
+ * V 0.2.0 Return boolean status instead of raising expectations. API_URL is now configurable.
17
18
  * V 0.1.5 Added group_post method and a generic call_api method. All methods
18
19
  now expect a hash of API params instead if individual arguments
19
20
  * V 0.1.2 Bulk file upload implemented. Only CSV format supported for now.
@@ -7,22 +7,26 @@ require 'cgi'
7
7
  require 'httpclient'
8
8
 
9
9
  class NilClass
10
- def blank?
11
- true
10
+ unless defined? :blank?
11
+ def blank?
12
+ true
13
+ end
12
14
  end
13
15
  end
14
16
 
15
17
  class String
16
- def blank?
17
- self.empty?
18
+ unless defined? :blank?
19
+ def blank?
20
+ self.empty?
21
+ end
18
22
  end
19
23
  end
20
24
 
21
25
  module Gupshup
22
- VERSION = '0.1.5'
26
+ VERSION = '0.2.0'
23
27
  class Enterprise
24
28
  def initialize(opts)
25
- @api_url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest'
29
+ @api_url = opts[:api_url] || 'http://enterprise.smsgupshup.com/GatewayAPI/rest'
26
30
  @api_params = {}
27
31
  @api_params[:userid] = opts[:userid]
28
32
  @api_params[:password] = opts[:password]
@@ -45,13 +49,14 @@ module Gupshup
45
49
  puts "GupShup Response: #{resp}"
46
50
 
47
51
  case res
48
- when Net::HTTPSuccess, Net::HTTPRedirection
52
+ when Net::HTTPSuccess
49
53
  if resp.nil? || resp.include?("success") == false
50
- raise "API call '#{opts[:method]}' failed: #{resp}"
54
+ puts "API call '#{opts[:method]}' failed: #{resp}"
55
+ return false, resp
51
56
  end
52
- return true
57
+ return true, nil
53
58
  else
54
- raise 'GupShup returned HTTP Error'
59
+ return false, "HTTP Error : #{res}"
55
60
  end
56
61
  end
57
62
 
@@ -60,11 +65,11 @@ module Gupshup
60
65
  number = opts[:send_to]
61
66
  msg_type = opts[:msg_type] || 'TEXT'
62
67
 
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
+ return (false, 'Phone Number is too short') if number.to_s.length < 12
69
+ return (false, 'Phone Number is too long') if number.to_s.length > 12
70
+ #return (false, 'Phone Number should start with "91"') if number.to_s.start_with? "91"
71
+ return (false, 'Phone Number should be numerical value') unless number.to_i.to_s == number.to_s
72
+ return (false, 'Message should be less than 725 characters long') if msg.to_s.length > 724
68
73
  call_api opts.merge({ :method => 'sendMessage' })
69
74
  end
70
75
 
@@ -97,9 +102,9 @@ module Gupshup
97
102
  end
98
103
 
99
104
  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?
105
+ return (false,"Invalid group name") if opts[:group_name].blank?
106
+ return (false,"Invalid message") if opts[:msg].blank?
107
+ return (false,"Invalid message type") if opts[:msg_type].blank?
103
108
  call_api opts.merge({:method => 'post_group'})
104
109
  end
105
110
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nilesh Trivedi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-25 00:00:00 +05:30
17
+ date: 2010-04-07 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -60,9 +60,8 @@ homepage: http://github.com/nileshtrivedi/gupshup
60
60
  licenses: []
61
61
 
62
62
  post_install_message: PostInstall.txt
63
- rdoc_options:
64
- - --main
65
- - README.rdoc
63
+ rdoc_options: []
64
+
66
65
  require_paths:
67
66
  - lib
68
67
  required_ruby_version: !ruby/object:Gem::Requirement