twilio-twimlbin 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +14 -0
- data/README.md +38 -0
- data/Rakefile +10 -0
- data/lib/twilio-twimlbin.rb +41 -0
- data/test/helper.rb +26 -0
- data/test/test_twimlbin.rb +18 -0
- data/twilio-twimlbin.gemspec +19 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (c) 2013- Kentaro Yoshida
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
twilio-twimlbin
|
2
|
+
=====================
|
3
|
+
|
4
|
+
## Overview
|
5
|
+
Twimlbin ruby wrapper class.
|
6
|
+
You can use [twimlbin.com](http://twimlbin.com/) to host twilio markup language without your own server.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
`````
|
11
|
+
$ sudo gem install twilio-twimlbin
|
12
|
+
`````
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
`````ruby
|
17
|
+
# -*- encoding: utf-8 -*-
|
18
|
+
require 'twilio-twimlbin'
|
19
|
+
require 'twilio-ruby'
|
20
|
+
|
21
|
+
response = Twilio::TwiML::Response.new do |r|
|
22
|
+
r.Say 'Hello World', :voice => 'woman', :language => 'ja-jp'
|
23
|
+
end
|
24
|
+
|
25
|
+
twiml = Twimlbin.new
|
26
|
+
url = twiml.create(response.text)
|
27
|
+
puts url
|
28
|
+
`````
|
29
|
+
|
30
|
+
## TODO
|
31
|
+
Pull requests are very welcome!!
|
32
|
+
|
33
|
+
## Copyright
|
34
|
+
Copyright © 2013- Kentaro Yoshida ([@yoshi_ken](https://twitter.com/yoshi_ken))
|
35
|
+
|
36
|
+
## License
|
37
|
+
Apache License, Version 2.0
|
38
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class Twimlbin
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
require 'net/http'
|
5
|
+
end
|
6
|
+
|
7
|
+
def create(xml)
|
8
|
+
configure
|
9
|
+
return @external_url if publish(xml)
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
@http = Net::HTTP.new('twimlbin.com', 80)
|
14
|
+
res = @http.get('/create')
|
15
|
+
cookie = res.response['set-cookie'].split('; ')[0]
|
16
|
+
@header = { "Cookie" => cookie }
|
17
|
+
@token = res.response['Location'].scan(/[^\/]+$/).last
|
18
|
+
@private_url = "http://twimlbin.com/#{@token}"
|
19
|
+
@external_url = get_external_url
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_external_url
|
23
|
+
res = @http.get("/#{@token}", @header)
|
24
|
+
find_url_regex = Regexp.escape('http://twimlbin.com/external/')
|
25
|
+
regex = Regexp.new("(#{find_url_regex}[^<]+)")
|
26
|
+
return res.body[regex]
|
27
|
+
end
|
28
|
+
|
29
|
+
def publish(xml)
|
30
|
+
request = Net::HTTP::Post.new("/save_data", @header)
|
31
|
+
body = {'index' => @token, 'twiml' => xml}
|
32
|
+
request.set_form_data(body)
|
33
|
+
begin
|
34
|
+
return @http.request(request)
|
35
|
+
rescue => e
|
36
|
+
raise Gem::Exception, "Twimlbin: Error: #{e.message}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
unless ENV.has_key?('VERBOSE')
|
15
|
+
nulllogger = Object.new
|
16
|
+
nulllogger.instance_eval {|obj|
|
17
|
+
def method_missing(method, *args)
|
18
|
+
# pass
|
19
|
+
end
|
20
|
+
}
|
21
|
+
$log = nulllogger
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'twilio-twimlbin'
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TwimlbinTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_publish
|
6
|
+
twiml = Twimlbin.new
|
7
|
+
external_url = twiml.create('twimlbin_ruby_unit_test')
|
8
|
+
|
9
|
+
uri = URI.parse(external_url)
|
10
|
+
req = Net::HTTP::Get.new(external_url)
|
11
|
+
req.add_field('User-Agent', 'TwilioProxy')
|
12
|
+
res = Net::HTTP.start(uri.host, uri.port) {|http| http.request(req) }
|
13
|
+
|
14
|
+
assert_equal 'twimlbin_ruby_unit_test', res.body
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "twilio-twimlbin"
|
6
|
+
s.version = "0.0.2"
|
7
|
+
s.authors = ["Kentaro Yoshida"]
|
8
|
+
s.email = ["y.ken.studio@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/y-ken/twimlbin"
|
10
|
+
s.summary = %q{Twimlbin wrapper class. You can use twimlbin.com to host twilio markup language without your own server.}
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
# specify any dependencies here; for example:
|
18
|
+
s.add_development_dependency "rake"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twilio-twimlbin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kentaro Yoshida
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description:
|
31
|
+
email:
|
32
|
+
- y.ken.studio@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/twilio-twimlbin.rb
|
43
|
+
- test/helper.rb
|
44
|
+
- test/test_twimlbin.rb
|
45
|
+
- twilio-twimlbin.gemspec
|
46
|
+
homepage: https://github.com/y-ken/twimlbin
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.23
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Twimlbin wrapper class. You can use twimlbin.com to host twilio markup language
|
70
|
+
without your own server.
|
71
|
+
test_files:
|
72
|
+
- test/helper.rb
|
73
|
+
- test/test_twimlbin.rb
|