deelay 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/deelay.rb +1 -0
- data/lib/deelay/app.rb +5 -27
- data/lib/deelay/utils.rb +21 -0
- data/lib/deelay/version.rb +1 -1
- metadata +3 -2
data/lib/deelay.rb
CHANGED
data/lib/deelay/app.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'sinatra/async'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
module Deelay
|
5
4
|
class App < Sinatra::Base
|
6
5
|
register Sinatra::Async
|
7
6
|
|
8
7
|
aget '/:delay' do
|
9
|
-
url = parse_query_string(request.query_string)
|
8
|
+
url = Deelay.parse_query_string(request.query_string)
|
10
9
|
redirect_to url
|
11
10
|
end
|
12
11
|
|
13
12
|
aget '/:delay/*' do
|
14
|
-
url = parse_splat(params[:splat].join("/"), request.query_string)
|
13
|
+
url = Deelay.parse_splat(params[:splat].join("/"), request.query_string)
|
15
14
|
redirect_to url
|
16
15
|
end
|
17
16
|
|
17
|
+
|
18
18
|
private
|
19
19
|
|
20
20
|
def redirect_to(url, delay = 0)
|
@@ -23,35 +23,13 @@ module Deelay
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def parse_query_string(raw_url)
|
27
|
-
escaped_url = ::URI.unescape(raw_url)
|
28
|
-
raise ArgumentError, "Missing URL" if request.query_string.empty?
|
29
|
-
|
30
|
-
url = (escaped_url =~ /^http:\/\// ? "" : "http://") + escaped_url
|
31
|
-
return url
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse_splat(raw_url, query_string)
|
35
|
-
raise ArgumentError, "Missing URL" if raw_url.empty?
|
36
|
-
|
37
|
-
escaped_url = ::URI.unescape(raw_url)
|
38
|
-
url = escaped_url.sub(/^http:\//, "http://")
|
39
|
-
url = "http://" + url if url !~ /^http:\/\//
|
40
|
-
url << "?" + request.query_string if !request.query_string.empty?
|
41
|
-
return url
|
42
|
-
end
|
43
|
-
|
44
|
-
def validate(url)
|
45
|
-
raise "Invalid url" if url =~ /(http|https)/
|
46
|
-
end
|
47
|
-
|
48
26
|
# swaps env when testing
|
49
27
|
def em_async_schedule
|
50
|
-
|
28
|
+
env = self.class.environment
|
51
29
|
self.class.set :environment, :normal
|
52
30
|
async_schedule { yield }
|
53
31
|
ensure
|
54
|
-
self.class.set :environment,
|
32
|
+
self.class.set :environment, env
|
55
33
|
end
|
56
34
|
end
|
57
35
|
end
|
data/lib/deelay/utils.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Deelay
|
4
|
+
def self.parse_query_string(query_string)
|
5
|
+
escaped_url = ::URI.unescape(query_string)
|
6
|
+
raise ArgumentError, "Missing URL" if query_string.empty?
|
7
|
+
|
8
|
+
url = (escaped_url =~ /^http:\/\// ? "" : "http://") + escaped_url
|
9
|
+
return url
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_splat(splat, query_string)
|
13
|
+
raise ArgumentError, "Missing URL" if splat.empty?
|
14
|
+
|
15
|
+
escaped_url = ::URI.unescape(splat)
|
16
|
+
url = escaped_url.sub(/^http:\//, "http://")
|
17
|
+
url = "http://" + url if url !~ /^http:\/\//
|
18
|
+
url << "?" + query_string if !query_string.empty?
|
19
|
+
return url
|
20
|
+
end
|
21
|
+
end
|
data/lib/deelay/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deelay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/deelay.rb
|
31
31
|
- lib/deelay/app.rb
|
32
32
|
- lib/deelay/homepage.rb
|
33
|
+
- lib/deelay/utils.rb
|
33
34
|
- lib/deelay/version.rb
|
34
35
|
- test/test_deelay_app.rb
|
35
36
|
homepage: http://deelay.me
|
@@ -46,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
47
|
version: '0'
|
47
48
|
segments:
|
48
49
|
- 0
|
49
|
-
hash:
|
50
|
+
hash: 3462912169812269730
|
50
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
52
|
none: false
|
52
53
|
requirements:
|