uri_shortener 0.0.1

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 +7 -0
  2. data/lib/uri_shortener.rb +37 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7bec835e14cb3f445fceeaf2645e5792642cf720
4
+ data.tar.gz: c51cf918dcde7f6c85b673ed67ec49ed8ce1f67e
5
+ SHA512:
6
+ metadata.gz: 988a47e944084e48853981ae9473c49113d5863cbf9cb3ec20d4dbbaad5ef3d195bf5826bf71f261f6441e439fa5df4cb2074a1c4b4030d7f321f5259a97e9fc
7
+ data.tar.gz: b83d9770b52f891e1aa56926a93c209cc8a2920983de95ba147c2fabe91ccbc88d0e93b0aa76dfb0e4cb514e4921198aabd82bd45da3be25adee001a90f1c71b
@@ -0,0 +1,37 @@
1
+ require 'net/http'
2
+ module Trackmaster
3
+ class UriShortener
4
+ attr :long_uri
5
+ attr_accessor :type
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
20
+
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
25
+ end
26
+
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
+
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
35
+
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uri_shortener
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Asakawa Ryu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Providing types: t.cn, url.cn, url7.me'
14
+ email: i@nyangawa.me
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/uri_shortener.rb
20
+ homepage: http://rubygems.org/gems/uri_shortener
21
+ licenses:
22
+ - GPLv3
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A scalable URI shortener
44
+ test_files: []