bulksms 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,4 +85,5 @@ Modifications include:
85
85
  * simple helper module for direct access to classes
86
86
  * DRYer support libraries
87
87
  * Railtie support for configuration
88
+ * Encoding messages correctly
88
89
 
@@ -22,6 +22,7 @@ Bulksms.config do |c|
22
22
  c.username = username
23
23
  c.password = password
24
24
  c.country = country
25
+ c.routing_group = 3 # Normally 2!
25
26
  end
26
27
 
27
28
  begin
@@ -42,7 +43,7 @@ message = gets.strip
42
43
 
43
44
  puts "\nThank you. Processing...\n\n"
44
45
 
45
- response = Bulksms.send(:message => message, :recipient => recipient, :test_always_success => 1)
46
+ response = Bulksms.deliver(:message => message, :recipient => recipient)
46
47
 
47
48
  if response.success?
48
49
  puts "Your SMS was sent successfully.\n\n"
@@ -50,7 +51,7 @@ if response.success?
50
51
  puts "Goodbye!"
51
52
  else
52
53
  puts "Sorry, but your SMS was not sent this time. The service returned the error:"
53
- puts "\n\t#{response.code}: #{response.description}\n\n"
54
+ puts "\n\t#{response.code}: #{response.result}\n\n"
54
55
  puts "Please try again later. Goodbye."
55
56
  end
56
57
 
@@ -1,3 +1,6 @@
1
+
2
+ require 'cgi'
3
+
1
4
  module Bulksms
2
5
 
3
6
  class AccountError < Exception; end
@@ -51,7 +54,7 @@ module Bulksms
51
54
  end
52
55
 
53
56
  def params_to_query_string(params)
54
- URI.encode(params.collect{|x,y| "#{x}=#{y}"}.join('&'))
57
+ params.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
55
58
  end
56
59
 
57
60
  end
@@ -2,15 +2,30 @@ module Bulksms
2
2
 
3
3
  class Configuration
4
4
 
5
+ # Standard connection details
5
6
  attr_accessor :username
6
7
  attr_accessor :password
7
- attr_accessor :country
8
8
  attr_accessor :host
9
9
  attr_accessor :port
10
+
11
+ # Set the country code when no host has been provided. Should be
12
+ # one of:
13
+ # :uk, :usa, :safrica, :spain, :international (default)
14
+ attr_accessor :country
15
+
16
+ # Path added to host to send a message
17
+ # Known as send_sms method in BulkSMS API.
10
18
  attr_accessor :message_path
19
+
20
+ # Path added to host to request credits
11
21
  attr_accessor :credits_path
22
+
23
+ # Message Class, 0 (Flash SMS), 1, 2 (default, normal SMS, stored to SIM card), 3.
12
24
  attr_accessor :message_class
13
25
 
26
+ # Routing group, possible values are 1, 2, 3
27
+ attr_accessor :routing_group
28
+
14
29
  def initialize
15
30
  # Prepare default options
16
31
  self.country = :international
@@ -18,6 +33,7 @@ module Bulksms
18
33
  self.message_path = "/eapi/submission/send_sms/2/2.0"
19
34
  self.credits_path = "/eapi/user/get_credits/1/1.1"
20
35
  self.message_class = 2
36
+ self.routing_group = 2
21
37
  end
22
38
 
23
39
  # Overide the default host config so that a short name will be converted
@@ -15,9 +15,9 @@ module Bulksms
15
15
  def initialize(opts = {})
16
16
  @message = opts[:message]
17
17
  @recipient = opts[:recipient]
18
- @msg_class = Bulksms.config.message_class
18
+ @msg_class = opts[:message_class] || Bulksms.config.message_class
19
19
  @want_report = 0
20
- @routing_group = 2
20
+ @routing_group = opts[:routing_group] || Bulksms.config.routing_group
21
21
  @source_id = ''
22
22
  @test_always_succeed = opts[:test_always_succeed] || 0
23
23
  @test_always_fail = opts[:test_always_fail] || 0
@@ -1,3 +1,3 @@
1
1
  module Bulksms
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  require 'spec_helper'
3
4
 
@@ -81,6 +82,15 @@ describe Bulksms::Account do
81
82
 
82
83
  end
83
84
 
85
+ describe "#params_to_query_string" do
86
+ it "converts params to string" do
87
+ txt = @account.send(:params_to_query_string, :msg => "Random çharacters -and- symbols +34123123123", :some => :symbol)
88
+ txt.should include("Random+%C3%A7hara")
89
+ txt.should include("%2B34123")
90
+ txt.should include("some=symbol")
91
+ end
92
+ end
93
+
84
94
  end
85
95
 
86
96
  end
@@ -9,7 +9,7 @@ describe Bulksms::Configuration do
9
9
  describe "accessors" do
10
10
  it "should be provided" do
11
11
  [:username, :password, :country, :host, :port, :message_path,
12
- :credits_path, :message_class].each do |accessor|
12
+ :credits_path, :message_class, :routing_group].each do |accessor|
13
13
  @config.should respond_to accessor
14
14
  end
15
15
  end
@@ -23,6 +23,7 @@ describe Bulksms::Configuration do
23
23
  @config.message_path.should_not be_empty
24
24
  @config.credits_path.should_not be_empty
25
25
  @config.message_class.should eql(2)
26
+ @config.routing_group.should eql(2)
26
27
  end
27
28
 
28
29
  end
@@ -15,6 +15,14 @@ describe Bulksms::Message do
15
15
  @msg.recipient.should eql("1234")
16
16
  end
17
17
 
18
+ it "should allow overrides" do
19
+ @msg = Bulksms::Message.new :message => "foo", :recipient => '1234', :routing_group => 3,
20
+ :test_always_succeed => 1, :message_class => 1
21
+ @msg.routing_group.should eql(3)
22
+ @msg.msg_class.should eql(1)
23
+ @msg.test_always_succeed.should eql(1)
24
+ end
25
+
18
26
  end
19
27
 
20
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulksms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-11-28 00:00:00.000000000 Z
14
+ date: 2011-11-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
18
- requirement: &21179040 !ruby/object:Gem::Requirement
18
+ requirement: &14000900 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *21179040
26
+ version_requirements: *14000900
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fakeweb
29
- requirement: &21178380 !ruby/object:Gem::Requirement
29
+ requirement: &13999120 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *21178380
37
+ version_requirements: *13999120
38
38
  description: Send SMS text messages via the BulkSMS API.
39
39
  email:
40
40
  - me@samlown.com