uri_shortener 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/uri_shortener.rb +38 -28
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bec835e14cb3f445fceeaf2645e5792642cf720
4
- data.tar.gz: c51cf918dcde7f6c85b673ed67ec49ed8ce1f67e
3
+ metadata.gz: 96f672757995879e46765694bd6134698fdc1d50
4
+ data.tar.gz: 88f7851064871f2a2c848ac99c51234d03d6e49d
5
5
  SHA512:
6
- metadata.gz: 988a47e944084e48853981ae9473c49113d5863cbf9cb3ec20d4dbbaad5ef3d195bf5826bf71f261f6441e439fa5df4cb2074a1c4b4030d7f321f5259a97e9fc
7
- data.tar.gz: b83d9770b52f891e1aa56926a93c209cc8a2920983de95ba147c2fabe91ccbc88d0e93b0aa76dfb0e4cb514e4921198aabd82bd45da3be25adee001a90f1c71b
6
+ metadata.gz: 490ea2d112595b2357ea729b210e2958e94072291714255595bad631ea338729beafb554b39c649d55d83e5f4b0c37e5754445d651ca2c014b735cef011985f7
7
+ data.tar.gz: 3bcef9683245e0bbd7efeb61e33fa08628cfba911354f7e915f8af0e530e38dfd57776bb339d881dc7dc50390b98aec9f98c764a1b3da686b5a2795153ad97e2
data/lib/uri_shortener.rb CHANGED
@@ -1,37 +1,47 @@
1
1
  require 'net/http'
2
- module Trackmaster
3
- class UriShortener
4
- attr :long_uri
5
- attr_accessor :type
2
+ class UriShortener
3
+ attr :long_uri
4
+ attr :short_uri
5
+ attr_accessor :type
6
6
 
7
- def initialize long_uri, type="t.cn"
8
- @long_uri = long_uri
9
- @type = type # t.cn || rdcnzz || url.cn
10
- end
11
-
12
- def shorten
13
- result = case @type
14
- when "t.cn" then t_cn @long_uri
15
- when "url.cn" then url_cn @long_uri
16
- when "rdcnzz" then rdcnzz @long_uri
17
- else puts "Not correct type"
18
- end
19
- end
7
+ def initialize long_uri, type="t.cn"
8
+ @long_uri = long_uri.gsub "http://",""
9
+ @type = type # t.cn || rdcnzz || url.cn
10
+ @short_uri = ""
11
+ end
12
+
13
+ def shorten
14
+ @short_uri = case @type
15
+ when "t.cn" then t_cn @long_uri
16
+ when "url.cn" then url_cn @long_uri
17
+ when "rdcnzz" then rdcnzz @long_uri
18
+ else puts "Not correct type"
19
+ end
20
+ end
20
21
 
21
- private
22
- def t_cn long_uri
23
- response = Net::HTTP.post_form(URI("http://tinyurl.duapp.com/url.php"), {:url=>URI.encode_www_form_component(long_uri.gsub "http://", ""), :type=>"t.cn"})
24
- response.body
22
+ def verify
23
+ begin
24
+ res = Net::HTTP.get_response URI(@short_uri)
25
+ URI("http://"+@long_uri) == URI(res["location"])
26
+ rescue
27
+ false
25
28
  end
29
+ end
26
30
 
27
- def url_cn long_uri
28
- response = Net::HTTP.get(URI("http://121.199.13.65/web/json.php?type=url.cn&xzurl=#{URI.encode_www_form_component long_uri}"))
29
- (/http\:\/\/\w+\.\w+\/\w+/.match response).to_s
30
- end
31
+ private
32
+ def t_cn long_uri
33
+ response = Net::HTTP.post_form(URI("http://tinyurl.duapp.com/url.php"), {:url=>URI.encode_www_form_component(long_uri.gsub "http://", ""), :type=>"t.cn"})
34
+ response.body
35
+ end
31
36
 
32
- def rdcnzz long_uri
33
- response = Net::HTTP.get(URI("http://rdcnzz.com/v1/data/link_conv/rd_dispatcher.php?orig_link=#{URI.encode_www_form_component long_uri}"))
34
- end
37
+ def url_cn long_uri
38
+ response = Net::HTTP.get(URI("http://121.199.13.65/web/json.php?type=url.cn&xzurl=#{URI.encode_www_form_component long_uri}"))
39
+ (/http\:\/\/\w+\.\w+\/\w+/.match response).to_s
40
+ end
35
41
 
42
+ def rdcnzz long_uri
43
+ response = Net::HTTP.get(URI("http://rdcnzz.com/v1/data/link_conv/rd_dispatcher.php?orig_link=#{URI.encode_www_form_component long_uri}"))
36
44
  end
45
+
46
+
37
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_shortener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asakawa Ryu