Class: Twsms2::Client
- Inherits:
-
Object
- Object
- Twsms2::Client
- Defined in:
- lib/twsms2.rb
Instance Method Summary collapse
- #account_is_available ⇒ Object
- #get_balance ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #send_message(options = {}) ⇒ Object
Methods included from Formatter
#format_balance_info, #format_send_message_info, #format_time_string, #match_string, #to_asia_taipei_timezone
Methods included from Network
#escape, #get, #parse, #query_string, #request
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 |
# File 'lib/twsms2.rb', line 11 def initialize(={}) @user_agent = .fetch(:agent) { "twsms2/#{VERSION}" } @api_host = .fetch(:host) { 'api.twsms.com' } @username = .fetch(:username) { ENV.fetch('TWSMS_USERNAME') } @password = .fetch(:password) { ENV.fetch('TWSMS_PASSWORD') } end |
Instance Method Details
#account_is_available ⇒ Object
18 19 20 21 22 |
# File 'lib/twsms2.rb', line 18 def account_is_available balance_info = get_balance ok = balance_info[:message_quota] > 0 && balance_info[:access_success] end |
#get_balance ⇒ Object
36 37 38 39 40 |
# File 'lib/twsms2.rb', line 36 def get_balance response = get(@api_host, '/smsQuery.php', deltime: :N, checkpoint: :Y, mobile: '', msgid: '') format_balance_info(response) end |
#send_message(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/twsms2.rb', line 24 def (={}) [:to] ||= nil [:content] ||= nil [:at] = format_time_string([:at]) [:long] = [:long] || [:long].nil? ? :Y : :N [:popup] = [:popup] ? :Y : :N response = get(@api_host, '/smsSend.php', popup: [:popup], mo: :N, longsms: [:long], mobile: [:to], message: [:content], drurl: '', sendtime: [:at]) (response) end |