kannel_rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -10
- data/lib/kannel_rails/config.rb +4 -0
- data/lib/kannel_rails/version.rb +1 -1
- data/lib/kannel_rails.rb +7 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -25,7 +25,6 @@ development:
|
|
25
25
|
username: username # Kannel sendsms-user username
|
26
26
|
password: password # Kannel sendsms-user password
|
27
27
|
api_secret: testing # A secret key you will also configure in Kannel for extra security
|
28
|
-
dlr_mask: 31 # Set this if you want to receive delivery reports from Kannel.
|
29
28
|
```
|
30
29
|
|
31
30
|
In config/routes.rb, add:
|
@@ -62,13 +61,13 @@ KannelRails.send_message("+639001234567", "Hello Flash!", :mclass => 0)
|
|
62
61
|
|
63
62
|
To handle incoming SMS, create handler classes and register them.
|
64
63
|
|
65
|
-
Classes have an invoke method which is called when handle
|
64
|
+
Classes have an `invoke` method which is called when `handle?` is true
|
66
65
|
|
67
|
-
The return value of invoke will be the response to Kannel, which will be sent back to the sender as SMS. omit-empty is set in the sms-service so that empty strings will not be sent back.
|
66
|
+
The return value of `invoke` will be the response to Kannel, which will be sent back to the sender as SMS. omit-empty is set in the sms-service so that empty strings will not be sent back.
|
68
67
|
|
69
|
-
Sample handler is in spec/dummy/lib/echo_handler.rb
|
68
|
+
Sample handler is in `spec/dummy/lib/echo_handler.rb`
|
70
69
|
|
71
|
-
Register the handler class in config/initializers/sms_handlers.rb (or some other place if you want):
|
70
|
+
Register the handler class in `config/initializers/sms_handlers.rb` (or some other place if you want):
|
72
71
|
|
73
72
|
```ruby
|
74
73
|
KannelRails::Handlers.register HandlerClass
|
@@ -76,12 +75,21 @@ KannelRails::Handlers.register HandlerClass
|
|
76
75
|
|
77
76
|
### Delivery Reports
|
78
77
|
|
79
|
-
To receive delivery reports, you must have the dlr_mask set. Check Kannel docs for possible values.
|
78
|
+
To receive delivery reports, you must have the dlr_mask and dlr_url set. Check Kannel docs for possible values.
|
80
79
|
|
81
|
-
|
82
|
-
dlr_url = "http://rails_app/some_endpoint?msg_id=123&type=%d&smsc_id=%i"
|
80
|
+
In your config:
|
83
81
|
|
84
|
-
|
82
|
+
```yaml
|
83
|
+
development:
|
84
|
+
...
|
85
|
+
dlr_url: http://rails_app/some_endpoint?msg_id=$msg_id&type=%d&smsc_id=%i
|
86
|
+
dlr_mask: 31
|
87
|
+
```
|
88
|
+
|
89
|
+
Note: The `$msg_id` in the DLR URL is a special string that will be replaced with the value of `:msg_id` option when you call `send_message`.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
KannelRails.send_message("+639001234567", "Hello World!", :msg_id => '1234')
|
85
93
|
```
|
86
94
|
|
87
|
-
|
95
|
+
This will result in Kannel calling something similar to the URL: `http://rails_app/some_endpoint?msg_id=1234&type=1&smsc_id=the_smsc_id`
|
data/lib/kannel_rails/config.rb
CHANGED
@@ -8,7 +8,9 @@ class KannelRails::Config
|
|
8
8
|
attr_accessor :username
|
9
9
|
attr_accessor :password
|
10
10
|
|
11
|
+
attr_accessor :dlr_url
|
11
12
|
attr_accessor :dlr_mask
|
13
|
+
|
12
14
|
attr_accessor :api_secret
|
13
15
|
|
14
16
|
def initialize(config_hash = {})
|
@@ -19,7 +21,9 @@ class KannelRails::Config
|
|
19
21
|
self.username = config_hash['username']
|
20
22
|
self.password = config_hash['password']
|
21
23
|
|
24
|
+
self.dlr_url = config_hash['dlr_url']
|
22
25
|
self.dlr_mask = config_hash['dlr_mask']
|
26
|
+
|
23
27
|
self.api_secret = config_hash['api_secret']
|
24
28
|
end
|
25
29
|
|
data/lib/kannel_rails/version.rb
CHANGED
data/lib/kannel_rails.rb
CHANGED
@@ -12,9 +12,15 @@ module KannelRails
|
|
12
12
|
:password => config.password,
|
13
13
|
:to => recipient,
|
14
14
|
:text => message,
|
15
|
+
:'dlr-url' => config.dlr_url,
|
15
16
|
:'dlr-mask' => config.dlr_mask
|
16
|
-
}
|
17
|
+
}
|
17
18
|
|
19
|
+
if config.dlr_url and options[:msg_id]
|
20
|
+
query_hash[:'dlr-url'] = config.dlr_url.sub('$msg_id', options[:msg_id])
|
21
|
+
end
|
22
|
+
|
23
|
+
query_hash.merge!(options)
|
18
24
|
query_hash.delete_if { |k, v| v.to_s.blank? }
|
19
25
|
|
20
26
|
request_url = config.kannel_url.merge('/cgi-bin/sendsms')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kannel_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|