Module: KannelRails
- Defined in:
- lib/kannel_rails.rb,
lib/kannel_rails/engine.rb,
lib/kannel_rails/version.rb,
app/controllers/kannel_rails/sms_controller.rb,
app/helpers/kannel_rails/application_helper.rb,
app/controllers/kannel_rails/application_controller.rb
Defined Under Namespace
Modules: ApplicationHelper, Handlers
Classes: ApplicationController, Config, Engine, SmsController
Constant Summary
collapse
- GSM_7BIT =
"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà"
- GSM_7BIT_EX =
"^{}\[~]|€"
- VERSION =
"0.0.8"
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/kannel_rails.rb', line 49
def self.config
unless defined?(@config)
config_file = YAML.load_file(File.join(Rails.root, 'config/kannel_rails.yml'))
if config_file[Rails.env]
@config = KannelRails::Config.new(config_file[Rails.env])
else
raise "Missing section #{Rails.env} in config/kannel_rails.yml!"
end
end
return @config
end
|
.send_message(recipient, message, options = {}) ⇒ Object
14
15
16
17
18
19
20
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
|
# File 'lib/kannel_rails.rb', line 14
def self.send_message(recipient, message, options = {})
query_hash = {
:username => config.username,
:password => config.password,
:to => recipient,
:text => message,
:'dlr-url' => config.dlr_url,
:'dlr-mask' => config.dlr_mask,
:charset => 'utf-8'
}
if config.dlr_url and options[:msg_id]
query_hash[:'dlr-url'] = config.dlr_url.sub('$msg_id', options[:msg_id].to_s)
end
if query_hash[:text] and !/\A[#{GSM_7BIT + GSM_7BIT_EX}]*\z/.match(query_hash[:text].to_s)
query_hash[:coding] = 2
end
query_hash.merge!(options)
query_hash.delete_if { |k, v| v.to_s.blank? }
request_url = config.kannel_url.merge('/cgi-bin/sendsms')
request_url.query = query_hash.to_query
request_url.port = config.sendsms_port
response = Net::HTTP.get_response(request_url)
if response.is_a? Net::HTTPSuccess
return response
else
return false
end
end
|