bulksms 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ * 0.5.2
2
+ Added mappings for special characters including euro symbol according to Bulksms api.
3
+
4
+ * 0.5.1
5
+ Fixing issues with encoding.
6
+
1
7
  * 0.5.0
2
8
  Completely re-written.
3
9
  Simple API via Bulksms module.
@@ -53,6 +53,11 @@ If you prefer more control, the <tt>Service</tt> and <tt>Message</tt> objects ar
53
53
  m.want_report = 1
54
54
  s.deliver(m)
55
55
 
56
+ == Encoding
57
+
58
+ All messages will be converted to ISO-8859-15 before being sent to the Bulksms servers. Some special characters, including the euro symbol, will be converted and prepended with a special escape character, suitable for GSM-7, so that they will be received correctly. For more details on character encoding, checkout the Bulksms API:
59
+
60
+ http://www.bulksms.com/int/docs/eapi/submission/character_encoding/
56
61
 
57
62
  == Checking your account balance
58
63
 
@@ -1,10 +1,13 @@
1
+ # encoding: utf-8
1
2
 
2
3
  require 'cgi'
4
+ require 'iconv'
3
5
 
4
6
  module Bulksms
5
7
 
6
8
  class AccountError < Exception; end
7
9
 
10
+
8
11
  class Account
9
12
 
10
13
  attr_reader :username, :password, :host, :port
@@ -54,9 +57,28 @@ module Bulksms
54
57
  end
55
58
 
56
59
  def params_to_query_string(params)
57
- params.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
60
+ params.collect{|k,v| "#{k}=#{encode_cgi_string(v.to_s)}"}.join('&')
58
61
  end
59
62
 
63
+ def encode_cgi_string(string)
64
+ CGI.escape(Iconv.iconv('ISO-8859-15//ignore', 'UTF-8', string)[0]).gsub(/%[0-9A-F]{2}/) do |match|
65
+ code = GSM0338_EXTENDED_MAP[match]
66
+ code ? "%BB%#{code}" : match
67
+ end
68
+ end
69
+
70
+ GSM0338_EXTENDED_MAP = {
71
+ '%5E' => '14', # ^
72
+ '%7B' => '28', # {
73
+ '%7D' => '29', # }
74
+ '%5C' => '2F', # \
75
+ '%5B' => '3C', # [
76
+ '%7E' => '3D', # ~
77
+ '%5D' => '3E', # ]
78
+ '%7C' => '40', # |
79
+ '%A4' => '65', # EURO
80
+ }
81
+
60
82
  end
61
83
 
62
84
  end
@@ -1,3 +1,3 @@
1
1
  module Bulksms
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -83,12 +83,23 @@ describe Bulksms::Account do
83
83
  end
84
84
 
85
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")
86
+ it "converts normal params to string" do
87
+ txt = @account.send(:params_to_query_string, :msg => "Random cháráctérs -and- symbols +34123123123", :some => :symbol)
88
+ txt.should include("Random+ch%E1r%E1ct%E9")
89
89
  txt.should include("%2B34123")
90
90
  txt.should include("some=symbol")
91
91
  end
92
+
93
+ it "converts special characters in params to string" do
94
+ txt = @account.send(:params_to_query_string, :msg => "[special] {characters} tilde~ pipe| hat^ euro€")
95
+ txt.should include("%BB%3Cspecial%BB%3E")
96
+ txt.should include("%BB%28characters%BB%29")
97
+ txt.should include("tilde%BB%3D")
98
+ txt.should include("pipe%BB%40")
99
+ txt.should include("hat%BB%14")
100
+ txt.should include("euro%BB%65")
101
+ end
102
+
92
103
  end
93
104
 
94
105
  end
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.1
4
+ version: 0.5.2
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-30 00:00:00.000000000 Z
14
+ date: 2012-02-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
18
- requirement: &14000900 !ruby/object:Gem::Requirement
18
+ requirement: &2164746900 !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: *14000900
26
+ version_requirements: *2164746900
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fakeweb
29
- requirement: &13999120 !ruby/object:Gem::Requirement
29
+ requirement: &2164745660 !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: *13999120
37
+ version_requirements: *2164745660
38
38
  description: Send SMS text messages via the BulkSMS API.
39
39
  email:
40
40
  - me@samlown.com
@@ -88,4 +88,10 @@ rubygems_version: 1.8.10
88
88
  signing_key:
89
89
  specification_version: 3
90
90
  summary: Simple BulkSMS API
91
- test_files: []
91
+ test_files:
92
+ - spec/account_spec.rb
93
+ - spec/bulksms_spec.rb
94
+ - spec/configuration_spec.rb
95
+ - spec/message_spec.rb
96
+ - spec/service_spec.rb
97
+ - spec/spec_helper.rb