Sha256: 1d02d454d384b93e68d5a04fbbdf6c5ef808909f680ac7ea826b5a6a781ca357
Contents?: true
Size: 941 Bytes
Versions: 1
Compression:
Stored size: 941 Bytes
Contents
class Twimlbin attr_reader :external_url, :private_url, :token def initialize require 'net/http' end def create(xml) configure return @external_url if publish(xml) end def configure @http = Net::HTTP.new('twimlbin.com', 80) res = @http.get('/create') @token = res.response['Location'].scan(/[^\/]+$/).last @private_url = "http://twimlbin.com/#{@token}" @external_url = get_external_url end def get_external_url res = @http.get("/#{@token}") find_url_regex = Regexp.escape('http://twimlbin.com/external/') regex = Regexp.new("(#{find_url_regex}[^<]+)") return res.body[regex] end def publish(xml) request = Net::HTTP::Post.new("/#{@token}/update") body = {'id' => @token, 'twiml' => xml} request.set_form_data(body) begin return @http.request(request) rescue => e raise Gem::Exception, "Twimlbin: Error: #{e.message}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
twilio-twimlbin-0.0.5 | lib/twilio-twimlbin.rb |