class TxtWeb::TxtWebRuby
Public Class Methods
new(opts)
click to toggle source
# File lib/txtweb-ruby.rb, line 19 def initialize(opts) @api_url = opts[:api_url] || 'http://api.txtweb.com/v1/push' @api_params = {} @api_params[:txtweb_pubkey] = opts[:txtweb_pubkey] raise "Invalid credentials" if opts[:txtweb_pubkey].blank? end
Public Instance Methods
call_api(opts = {})
click to toggle source
# File lib/txtweb-ruby.rb, line 27 def call_api(opts = {}) res = Net::HTTP.post_form( URI.parse(@api_url), @api_params.merge(opts) ) resp = XmlSimple.xml_in(res.body) status = resp['status'][0] puts "TxtWeb Response: #{resp}" case res when Net::HTTPSuccess if status['code'] == 0 return true, nil puts "API Call Failed : #{status['code']}" return false,nil else return false, "HTTP Error : #{res}" end end def send_message(opts) msg = opts[:msg] number = opts[:txtweb_mobile] return false, 'Message should be less than 725 characters long' if msg.to_s.length > 724 call_api(opts) end end
send_message(opts)
click to toggle source
# File lib/txtweb-ruby.rb, line 50 def send_message(opts) msg = opts[:msg] number = opts[:txtweb_mobile] return false, 'Message should be less than 725 characters long' if msg.to_s.length > 724 call_api(opts) end