Class: Smshelper::Api::Aql
- Inherits:
-
Base
- Object
- Base
- Smshelper::Api::Aql
show all
- Defined in:
- lib/smshelper/api/aql.rb
Instance Attribute Summary
Attributes inherited from Base
#extra_options, #sent_message_ids, #sent_message_statuses
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Aql
Returns a new instance of Aql.
6
7
8
9
10
|
# File 'lib/smshelper/api/aql.rb', line 6
def initialize(*args)
config = args.shift
add_query_options! :username => config.aql[:uname], :password => config.aql[:passwd]
super
end
|
Instance Method Details
#get_balance ⇒ Object
27
28
29
|
# File 'lib/smshelper/api/aql.rb', line 27
def get_balance
{'Credits' => (post 'postmsg.php', :extra_query => {:cmd => :credit}).split('=').last}
end
|
#get_callback_response(args = {}) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/smshelper/api/aql.rb', line 35
def get_callback_response(args = {})
DeliveryReport.new(
:message_id => args['message_id'],
:timestamp => Time.now,
:delivered => ((args['status'] == '1') ? true : false),
:original_params => args
)
end
|
#get_status ⇒ Object
31
32
33
|
# File 'lib/smshelper/api/aql.rb', line 31
def get_status
raise NotImplementedError, "Aql does not implement status check"
end
|
#send_message(message) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/smshelper/api/aql.rb', line 12
def send_message(message)
uuid = (Digest::CRC32.hexdigest @uuid.generate).unpack('U*').collect {|x| sprintf '%02X', x}.join
message.utf_8 ? (q = {:allow_unicode => '1'}) : (q = {})
options = {
:destination => message.recipient,
:originator => message.sender,
:message => message.text}
options = options.merge(@extra_options) unless @extra_options.nil?
(options[:dlr_url] = options[:dlr_url] + "?status=%code&destination=%dest&message_id=#{uuid}") if options.include?(:dlr_url)
resp = (post 'sms_gw.php', :extra_query => options.merge(q))
process_response_code(resp.to_s) ? (@sent_message_ids << uuid; uuid) : (raise ErrorDuringSend, resp)
end
|