Class: Smshelper::Api::Clickatell
- Inherits:
-
Base
- Object
- Base
- Smshelper::Api::Clickatell
show all
- Defined in:
- lib/smshelper/api/clickatell.rb
Instance Attribute Summary
Attributes inherited from Base
#extra_options, #sent_message_ids, #sent_message_statuses
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Clickatell
Returns a new instance of Clickatell.
6
7
8
9
10
|
# File 'lib/smshelper/api/clickatell.rb', line 6
def initialize(*args)
config = args.shift
add_query_options! :api_id => config.clickatell[:api_key], :user => config.clickatell[:uname], :password => config.clickatell[:passwd]
super
end
|
Instance Method Details
#get_balance ⇒ Object
33
34
35
|
# File 'lib/smshelper/api/clickatell.rb', line 33
def get_balance
{'Credits' => (post 'getbalance').split(':').last.strip}
end
|
#get_status(message_id) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/smshelper/api/clickatell.rb', line 37
def get_status(message_id)
resp = (post 'querymsg', :extra_query => {:apimsgid => message_id}).split(':')
@sent_message_statuses[message_id] = []
if process_response_code(resp.first.strip)
@sent_message_statuses[message_id] << {"Part 01" => @response_code.clickatell(resp.last.strip)}
{message_id => @sent_message_statuses[message_id]}
else
raise ErrorDuringSend, resp.last.strip
end
end
|
#send_message(message) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/smshelper/api/clickatell.rb', line 12
def send_message(message)
if message.utf_8
message.to_hex_be
q = {:unicode => '1', :req_feat => '40'}
else
q = {:req_feat => '32'}
end
options = {
:to => message.recipient,
:text => message.text,
:from => message.sender,
:queue => '1',
:escalate => '1',
:validity => '1',
:concat => '3'}
options = options.merge(@extra_options) unless @extra_options.nil?
resp = (post 'sendmsg', :extra_query => options.merge(q)).split(':')
process_response_code(resp.first.strip) ? (@sent_message_ids << resp.last.strip; resp.last.strip) : (raise ErrorDuringSend, resp.last.strip)
end
|