mobilove 0.0.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/lib/mobilove.rb +4 -0
- data/lib/mobilove/exceptions.rb +36 -0
- data/lib/mobilove/text.rb +52 -0
- data/lib/mobilove/version.rb +3 -0
- metadata +71 -0
data/lib/mobilove.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mobilove
|
2
|
+
|
3
|
+
class InvalidNumber < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class InvalidSender < Exception
|
7
|
+
end
|
8
|
+
|
9
|
+
class MessageTooLong < Exception
|
10
|
+
end
|
11
|
+
|
12
|
+
class InvalidMessageType < Exception
|
13
|
+
end
|
14
|
+
|
15
|
+
class InvalidRoute < Exception
|
16
|
+
end
|
17
|
+
|
18
|
+
class AuthenticationFailed < Exception
|
19
|
+
end
|
20
|
+
|
21
|
+
class NoCreditLeft < Exception
|
22
|
+
end
|
23
|
+
|
24
|
+
class RouteCannotHandleProvider < Exception
|
25
|
+
end
|
26
|
+
|
27
|
+
class FeatureNotSupportedByRoute < Exception
|
28
|
+
end
|
29
|
+
|
30
|
+
class SMSCTransferFailed < Exception
|
31
|
+
end
|
32
|
+
|
33
|
+
class UnknownError < Exception
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Mobilove
|
4
|
+
|
5
|
+
class Text
|
6
|
+
def initialize(key, route, from)
|
7
|
+
@key, @route, @from = key, route, from
|
8
|
+
end
|
9
|
+
|
10
|
+
def send(to, message, debug_mode = false)
|
11
|
+
url = send_url(to, message, debug_mode)
|
12
|
+
response = RestClient.get(url)
|
13
|
+
respond(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
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'}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def respond(response)
|
23
|
+
case response.code.to_i
|
24
|
+
when 100
|
25
|
+
true
|
26
|
+
when 10
|
27
|
+
raise InvalidNumber.new(response.body)
|
28
|
+
when 20
|
29
|
+
raise InvalidSender.new(response.body)
|
30
|
+
when 30
|
31
|
+
raise MessageTooLong.new(response.body)
|
32
|
+
when 31
|
33
|
+
raise InvalidMessageType.new(response.body)
|
34
|
+
when 40
|
35
|
+
raise InvalidRoute.new(response.body)
|
36
|
+
when 50
|
37
|
+
raise AuthenticationFailed.new(response.body)
|
38
|
+
when 60
|
39
|
+
raise NoCreditLeft.new(response.body)
|
40
|
+
when 70
|
41
|
+
raise RouteCannotHandleProvider.new(response.body)
|
42
|
+
when 71
|
43
|
+
raise FeatureNotSupportedByRoute.new(response.body)
|
44
|
+
when 80
|
45
|
+
raise SMSCTransferFailed.new(response.body)
|
46
|
+
else
|
47
|
+
raise UnknownError.new("Response Code: #{response.code} // Response Body: #{response.body}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobilove
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Red Davis
|
14
|
+
- Tim Schneider
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-04-19 00:00:00 +02:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description: Use mobilove to send text messages with Ruby. Account on mobilant.de required.
|
24
|
+
email: tim@railslove.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- lib/mobilove.rb
|
33
|
+
- lib/mobilove/exceptions.rb
|
34
|
+
- lib/mobilove/text.rb
|
35
|
+
- lib/mobilove/version.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/railslove/mobilove
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: "[none]"
|
66
|
+
rubygems_version: 1.4.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Small wrapper for sending text messages with mobilant.de
|
70
|
+
test_files: []
|
71
|
+
|