uri_shortener 0.0.3 → 0.0.4

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 +6 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96f672757995879e46765694bd6134698fdc1d50
4
- data.tar.gz: 88f7851064871f2a2c848ac99c51234d03d6e49d
3
+ metadata.gz: bc958e10a0269271a92cf3a0202d89fe5730e313
4
+ data.tar.gz: 99b07f13fe0bd4f28c65098d71d86b02c6598b17
5
5
  SHA512:
6
- metadata.gz: 490ea2d112595b2357ea729b210e2958e94072291714255595bad631ea338729beafb554b39c649d55d83e5f4b0c37e5754445d651ca2c014b735cef011985f7
7
- data.tar.gz: 3bcef9683245e0bbd7efeb61e33fa08628cfba911354f7e915f8af0e530e38dfd57776bb339d881dc7dc50390b98aec9f98c764a1b3da686b5a2795153ad97e2
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=>URI.encode_www_form_component(long_uri.gsub "http://", ""), :type=>"t.cn"})
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=#{URI.encode_www_form_component long_uri}"))
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=#{URI.encode_www_form_component long_uri}"))
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
 
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asakawa Ryu