mobilove 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mobilove/exceptions.rb +10 -7
- data/lib/mobilove/text.rb +82 -41
- data/lib/mobilove/version.rb +1 -1
- metadata +55 -43
data/lib/mobilove/exceptions.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Mobilove
|
2
|
-
|
2
|
+
|
3
3
|
class InvalidNumber < Exception
|
4
4
|
end
|
5
5
|
|
6
6
|
class InvalidSender < Exception
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class MessageTooLong < Exception
|
10
10
|
end
|
11
11
|
|
@@ -14,13 +14,13 @@ module Mobilove
|
|
14
14
|
|
15
15
|
class InvalidRoute < Exception
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
class AuthenticationFailed < Exception
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
class NoCreditLeft < Exception
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
class RouteCannotHandleProvider < Exception
|
25
25
|
end
|
26
26
|
|
@@ -32,5 +32,8 @@ module Mobilove
|
|
32
32
|
|
33
33
|
class UnknownError < Exception
|
34
34
|
end
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
class MessageIsNoUtf8String < Exception
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/lib/mobilove/text.rb
CHANGED
@@ -1,54 +1,95 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'uri'
|
3
|
+
require 'iconv'
|
2
4
|
|
3
5
|
module Mobilove
|
4
|
-
|
6
|
+
|
5
7
|
class Text
|
6
8
|
def initialize(key, route, from)
|
7
9
|
@key, @route, @from = key, route, from
|
8
10
|
end
|
9
|
-
|
10
|
-
def
|
11
|
-
url =
|
11
|
+
|
12
|
+
def send_message(to, message, options={})
|
13
|
+
url = prepare_url(to, message, options)
|
12
14
|
response = RestClient.get(url)
|
13
15
|
respond(response)
|
14
16
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def send_url(to, message, debug_mode)
|
19
|
-
"http://gw.mobilant.net/?key=#{@key}&to=#{to}&message=#{URI.escape(message)}&route=#{@route}&from=#{URI.escape(@from)}&debug=#{debug_mode ? '1' : '0'}&charset=utf-8"
|
17
|
+
|
18
|
+
def flash_message(to, message, options={})
|
19
|
+
send_message(to, message, { :type => "flash" }.merge(options))
|
20
20
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# :debug_mode => true // Message will not be sent
|
25
|
+
# :concat => true // Message will be sent as concatenated texts if it has more than 160 chars (70 unicode)
|
26
|
+
def prepare_url(to, message, options={})
|
27
|
+
|
28
|
+
options[:debug_mode] ||= false
|
29
|
+
options[:concat] ||= false
|
30
|
+
|
31
|
+
url = "http://gw.mobilant.net/"
|
32
|
+
url += "?key=#{@key}&to=#{to}&route=#{@route}&from=#{URI.escape(@from)}"
|
33
|
+
url += "&debug=#{options[:debug_mode] ? '1' : '0'}"
|
34
|
+
url += "&concat=#{options[:concat] ? '1' : '0'}"
|
35
|
+
|
36
|
+
url += "&type=#{options[:type]}" if options[:type]
|
37
|
+
url += "&senddate=#{options[:send_at]}" if options[:send_at]
|
38
|
+
|
39
|
+
if is_gsm0338_encoded?(message)
|
40
|
+
url += "&message=#{URI.escape(message)}&charset=utf-8"
|
41
|
+
else
|
42
|
+
url += "&message=#{string_to_hexadecimal_code_points(message)}&messagetype=unicode"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_gsm0338_encoded?(message)
|
48
|
+
gsm0338 = "@£$¥èéùìòÇ\fØø\nÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>\?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà\^\{\}\[~\]\|€"
|
49
|
+
message.each_char {|c| return false unless gsm0338.include?(c)}
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
def string_to_hexadecimal_code_points(message)
|
54
|
+
if message.class.to_s == 'String' && message.encoding.to_s == 'UTF-8'
|
55
|
+
hex_code = ''
|
56
|
+
Iconv.iconv("UCS-2", "utf-8", message).first.each_char {|unicode_char| hex_code += unicode_char.unpack('H*').first}
|
57
|
+
hex_code
|
58
|
+
else
|
59
|
+
raise MessageIsNoUtf8String.new("The message is either not a string or not UTF-8 encoded. MESSAGE: #{message}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def respond(response)
|
64
|
+
case response.code.to_i
|
65
|
+
when 100
|
66
|
+
true
|
67
|
+
when 200
|
68
|
+
true
|
69
|
+
when 10
|
70
|
+
raise InvalidNumber.new(response.body)
|
71
|
+
when 20
|
72
|
+
raise InvalidSender.new(response.body)
|
73
|
+
when 30
|
74
|
+
raise MessageTooLong.new(response.body)
|
75
|
+
when 31
|
76
|
+
raise InvalidMessageType.new(response.body)
|
77
|
+
when 40
|
78
|
+
raise InvalidRoute.new(response.body)
|
79
|
+
when 50
|
80
|
+
raise AuthenticationFailed.new(response.body)
|
81
|
+
when 60
|
82
|
+
raise NoCreditLeft.new(response.body)
|
83
|
+
when 70
|
84
|
+
raise RouteCannotHandleProvider.new(response.body)
|
85
|
+
when 71
|
86
|
+
raise FeatureNotSupportedByRoute.new(response.body)
|
87
|
+
when 80
|
88
|
+
raise SMSCTransferFailed.new(response.body)
|
89
|
+
else
|
90
|
+
raise UnknownError.new("Response Code: #{response.code} // Response Body: #{response.body}")
|
91
|
+
end
|
50
92
|
end
|
51
93
|
end
|
52
|
-
|
53
|
-
|
54
|
-
end
|
94
|
+
|
95
|
+
end
|
data/lib/mobilove/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobilove
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Red Davis
|
14
9
|
- Tim Schneider
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
date: 2011-11-21 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
requirement: &70092596794260 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70092596794260
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: &70092596793840 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70092596793840
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &70092596793420 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70092596793420
|
48
|
+
description: Use mobilove to send text messages with Ruby. Account on mobilant.de
|
49
|
+
required.
|
24
50
|
email: tim@railslove.com
|
25
51
|
executables: []
|
26
|
-
|
27
52
|
extensions: []
|
28
|
-
|
29
53
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
54
|
+
files:
|
32
55
|
- lib/mobilove.rb
|
33
56
|
- lib/mobilove/exceptions.rb
|
34
57
|
- lib/mobilove/text.rb
|
35
58
|
- lib/mobilove/version.rb
|
36
|
-
has_rdoc: true
|
37
59
|
homepage: http://github.com/railslove/mobilove
|
38
60
|
licenses: []
|
39
|
-
|
40
61
|
post_install_message:
|
41
62
|
rdoc_options: []
|
42
|
-
|
43
|
-
require_paths:
|
63
|
+
require_paths:
|
44
64
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
66
|
none: false
|
47
|
-
requirements:
|
48
|
-
- -
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
|
51
|
-
|
52
|
-
- 0
|
53
|
-
version: "0"
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
72
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
version: "0"
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
63
77
|
requirements: []
|
64
|
-
|
65
|
-
|
66
|
-
rubygems_version: 1.4.1
|
78
|
+
rubyforge_project: ! '[none]'
|
79
|
+
rubygems_version: 1.8.6
|
67
80
|
signing_key:
|
68
81
|
specification_version: 3
|
69
82
|
summary: Small wrapper for sending text messages with mobilant.de
|
70
83
|
test_files: []
|
71
|
-
|