Class: Mblox::Sms
- Inherits:
-
SmsValidation::Sms
- Object
- SmsValidation::Sms
- Mblox::Sms
show all
- Defined in:
- lib/mblox/sms.rb
Defined Under Namespace
Classes: BatchIdOutOfRangeError, InvalidSenderIdError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(phone, message, batch_id = nil) ⇒ Sms
Returns a new instance of Sms.
14
15
16
17
18
|
# File 'lib/mblox/sms.rb', line 14
def initialize(phone, message, batch_id=nil)
super(phone, message)
raise BatchIdOutOfRangeError, "batch_id must be in the range 1 to #{MAX_BATCH_ID}. The batch_id specified (#{batch_id}) is out of range." if !batch_id.blank? && (MAX_BATCH_ID < batch_id.to_i)
@batch_id = batch_id.to_i unless batch_id.blank?
end
|
Class Method Details
.http ⇒ Object
71
72
73
|
# File 'lib/mblox/sms.rb', line 71
def http
@http ||= Net::HTTP.new(url.host, url.port)
end
|
.request ⇒ Object
74
75
76
77
78
79
|
# File 'lib/mblox/sms.rb', line 74
def request
return @request if @request
@request = Net::HTTP::Post.new(url.request_uri)
@request.content_type = 'text/xml'
@request
end
|
.url ⇒ Object
68
69
70
|
# File 'lib/mblox/sms.rb', line 68
def url
@url ||= URI.parse(URI.escape(Mblox.config.outbound_url))
end
|
Instance Method Details
#send ⇒ Object
29
30
31
|
# File 'lib/mblox/sms.rb', line 29
def send
messages.collect { |message| commit build(message) }
end
|
#send_from(sender_id, service_id = nil) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/mblox/sms.rb', line 20
def send_from(sender_id, service_id=nil)
raise InvalidSenderIdError, "You can only send from a 5-digit shortcode" unless Mblox.is_a_five_digit_number?(sender_id)
@sender_id = sender_id.to_i.to_s
unless service_id.nil?
raise InvalidSenderIdError, "You can only send using a 5-digit service ID. Leave out the 2nd argument of send_from to use the globally configured '#{Mblox.config.service_id}'" unless Mblox.is_a_five_digit_number?(service_id)
@service_id = service_id.to_i.to_s
end
end
|