uri_shortener 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uri_shortener.rb +6 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc958e10a0269271a92cf3a0202d89fe5730e313
|
4
|
+
data.tar.gz: 99b07f13fe0bd4f28c65098d71d86b02c6598b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0a569b57dd22a86823019cfc8a541ac159ebede36d1960fe41493b4fca69984a34c11d92948e3da2731fb5a308b2d4380459f222671aece70fe416ec8f4d634
|
7
|
+
data.tar.gz: f616b2542f95919d905a10ddaa76b3f09f20fd5210755dfe57dd4a56f56f29bad3614594e8f3189db2405047bf2763051c0b91ef8b52a3ba082dee3c5e3792e9
|
data/lib/uri_shortener.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'net/http'
|
2
3
|
class UriShortener
|
3
4
|
attr :long_uri
|
@@ -5,7 +6,7 @@ class UriShortener
|
|
5
6
|
attr_accessor :type
|
6
7
|
|
7
8
|
def initialize long_uri, type="t.cn"
|
8
|
-
@long_uri = long_uri.gsub "http://",""
|
9
|
+
@long_uri = URI.encode(long_uri.gsub "http://","")
|
9
10
|
@type = type # t.cn || rdcnzz || url.cn
|
10
11
|
@short_uri = ""
|
11
12
|
end
|
@@ -22,7 +23,7 @@ class UriShortener
|
|
22
23
|
def verify
|
23
24
|
begin
|
24
25
|
res = Net::HTTP.get_response URI(@short_uri)
|
25
|
-
URI("http://"+@long_uri) == URI(res["location"])
|
26
|
+
URI("http://"+@long_uri) == URI(URI.encode res["location"])
|
26
27
|
rescue
|
27
28
|
false
|
28
29
|
end
|
@@ -30,17 +31,17 @@ class UriShortener
|
|
30
31
|
|
31
32
|
private
|
32
33
|
def t_cn long_uri
|
33
|
-
response = Net::HTTP.post_form(URI("http://tinyurl.duapp.com/url.php"), {:url=>
|
34
|
+
response = Net::HTTP.post_form(URI("http://tinyurl.duapp.com/url.php"), {:url=>(long_uri.gsub "http://", ""), :type=>"t.cn"})
|
34
35
|
response.body
|
35
36
|
end
|
36
37
|
|
37
38
|
def url_cn long_uri
|
38
|
-
response = Net::HTTP.get(URI("http://121.199.13.65/web/json.php?type=url.cn&xzurl=#{
|
39
|
+
response = Net::HTTP.get(URI("http://121.199.13.65/web/json.php?type=url.cn&xzurl=#{long_uri}"))
|
39
40
|
(/http\:\/\/\w+\.\w+\/\w+/.match response).to_s
|
40
41
|
end
|
41
42
|
|
42
43
|
def rdcnzz long_uri
|
43
|
-
response = Net::HTTP.get(URI("http://rdcnzz.com/v1/data/link_conv/rd_dispatcher.php?orig_link=#{
|
44
|
+
response = Net::HTTP.get(URI("http://rdcnzz.com/v1/data/link_conv/rd_dispatcher.php?orig_link=#{long_uri}"))
|
44
45
|
end
|
45
46
|
|
46
47
|
|