Class: ActionSmser::DeliveryMethods::SimpleHttp
- Inherits:
-
Object
- Object
- ActionSmser::DeliveryMethods::SimpleHttp
- Defined in:
- lib/action_smser/delivery_methods/simple_http.rb
Overview
Very simple implementation of http request to gateway. Options used are server, use_ssl, username, password overwrite deliver_path(sms, options) with your own if you have different type of path When save_delivery_reports=true it expects collection msg_ids in each line in http response
Direct Known Subclasses
Class Method Summary collapse
- .deliver(sms, options = nil) ⇒ Object
-
.deliver_http_request(sms, options, path) ⇒ Object
This is also used by other delivery methods (e.g. nexmo).
- .deliver_path(sms, options) ⇒ Object
- .logger ⇒ Object
Class Method Details
.deliver(sms, options = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/action_smser/delivery_methods/simple_http.rb', line 12 def self.deliver(sms, = nil) = ? : sms.[:simple_http] deliver_path = self.deliver_path(sms, ) response = self.deliver_http_request(sms, , deliver_path) logger.info "SimpleHttp delivery ||| #{deliver_path} ||| #{response.inspect}" logger.info response.body if !response.blank? sms.delivery_info = response # Results include sms_id or error code in each line results = response.body.split("\n") if sms.[:save_delivery_reports] sms.to_numbers_array.each_with_index do |to, i| sms.delivery_reports.push(ActionSmser::DeliveryReport.create_from_sms(sms, to, results[i].to_s.strip)) end return sms.delivery_reports else return results end end |
.deliver_http_request(sms, options, path) ⇒ Object
This is also used by other delivery methods (e.g. nexmo)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/action_smser/delivery_methods/simple_http.rb', line 36 def self.deliver_http_request(sms, , path) # http://www.rubyinside.com/nethttp-cheat-sheet-2940.html # http://notetoself.vrensk.com/2008/09/verified-https-in-ruby/ response = nil server_port = [:use_ssl] ? 443 : 80 http = Net::HTTP.new([:server], server_port) if [:use_ssl] http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end unless Rails.env.test? http.start do |http| response = http.request(Net::HTTP::Get.new(path)) unless Rails.env.test? #Never request by accident in test environment. end else logger.warn "DeliveryMethods does never make real http requests in test environment!" end response end |
.deliver_path(sms, options) ⇒ Object
60 61 62 |
# File 'lib/action_smser/delivery_methods/simple_http.rb', line 60 def self.deliver_path(sms, ) "/api/sendsms/plain?user=#{[:username]}&password=#{[:password]}&sender=#{sms.from_encoded}&SMSText=#{sms.body_encoded_escaped}&GSM=#{sms.to_encoded}" end |
.logger ⇒ Object
64 65 66 |
# File 'lib/action_smser/delivery_methods/simple_http.rb', line 64 def self.logger ActionSmser::Logger end |