uri_shortener 0.0.4 → 0.0.6
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.
- checksums.yaml +4 -4
 - data/lib/uri_shortener.rb +12 -4
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ac637bf7657b4e347ad15d0528a32d65ae045608
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7f6125dd925b81bcf9a9d942a0222426d3a5b8c6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 17986c09b81520639a25272177668041827bc41c513a7d3de558e6c0fc0608dbca1759fb414b8ac8bcefe157d6b39b275878fd9f42799872be234425b84e8864
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 740fead45ca92163c8feb3ff98c66bd88de3330137fd5d1dbd5ba8bd3646597f9fca9a2effcb91d0554af71dc516b41c37f2f1c0e2bcee9f0d2f1301a9a6cbbe
         
     | 
    
        data/lib/uri_shortener.rb
    CHANGED
    
    | 
         @@ -1,13 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- coding: utf-8 -*-
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'net/http'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'json'
         
     | 
| 
       3 
4 
     | 
    
         
             
            class UriShortener
         
     | 
| 
       4 
5 
     | 
    
         
             
              attr :long_uri
         
     | 
| 
       5 
6 
     | 
    
         
             
              attr :short_uri
         
     | 
| 
       6 
7 
     | 
    
         
             
              attr_accessor :type
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
              def initialize long_uri, type="t.cn"
         
     | 
| 
       9 
     | 
    
         
            -
                @long_uri = URI.encode(long_uri.gsub  
     | 
| 
       10 
     | 
    
         
            -
                @type = type # t.cn || rdcnzz || url.cn
         
     | 
| 
      
 10 
     | 
    
         
            +
                @long_uri = URI.encode(long_uri.gsub /http:\/\/|https:\/\//,"")
         
     | 
| 
      
 11 
     | 
    
         
            +
                @type = type # t.cn || rdcnzz || url.cn || 126.am
         
     | 
| 
       11 
12 
     | 
    
         
             
                @short_uri = ""
         
     | 
| 
       12 
13 
     | 
    
         
             
              end
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
         @@ -16,6 +17,7 @@ class UriShortener 
     | 
|
| 
       16 
17 
     | 
    
         
             
                             when "t.cn" then t_cn @long_uri
         
     | 
| 
       17 
18 
     | 
    
         
             
                             when "url.cn" then url_cn @long_uri
         
     | 
| 
       18 
19 
     | 
    
         
             
                             when "rdcnzz" then rdcnzz @long_uri
         
     | 
| 
      
 20 
     | 
    
         
            +
                             when "126.am" then am @long_uri
         
     | 
| 
       19 
21 
     | 
    
         
             
                             else puts "Not correct type"
         
     | 
| 
       20 
22 
     | 
    
         
             
                             end
         
     | 
| 
       21 
23 
     | 
    
         
             
              end
         
     | 
| 
         @@ -31,7 +33,7 @@ class UriShortener 
     | 
|
| 
       31 
33 
     | 
    
         | 
| 
       32 
34 
     | 
    
         
             
              private
         
     | 
| 
       33 
35 
     | 
    
         
             
              def t_cn long_uri
         
     | 
| 
       34 
     | 
    
         
            -
                response = Net::HTTP.post_form(URI("http://tinyurl.duapp.com/url.php"), {:url=>( 
     | 
| 
      
 36 
     | 
    
         
            +
                response = Net::HTTP.post_form(URI("http://tinyurl.duapp.com/url.php"), {:url=>(URI.encode_www_form_component URI.decode(long_uri)), :type=>"t.cn"})
         
     | 
| 
       35 
37 
     | 
    
         
             
                response.body
         
     | 
| 
       36 
38 
     | 
    
         
             
              end
         
     | 
| 
       37 
39 
     | 
    
         | 
| 
         @@ -43,6 +45,12 @@ class UriShortener 
     | 
|
| 
       43 
45 
     | 
    
         
             
              def rdcnzz long_uri
         
     | 
| 
       44 
46 
     | 
    
         
             
                response = Net::HTTP.get(URI("http://rdcnzz.com/v1/data/link_conv/rd_dispatcher.php?orig_link=#{long_uri}"))
         
     | 
| 
       45 
47 
     | 
    
         
             
              end
         
     | 
| 
       46 
     | 
    
         
            -
              
         
     | 
| 
       47 
48 
     | 
    
         | 
| 
      
 49 
     | 
    
         
            +
              def am long_uri
         
     | 
| 
      
 50 
     | 
    
         
            +
                response = Net::HTTP.post_form(URI("http://126.am/api!shorten.action"), {:key=>"d1f04c518037412988e26e449469106f", :longUrl=>(URI.decode "http://"+long_uri)})
         
     | 
| 
      
 51 
     | 
    
         
            +
                result = JSON.parse response.body
         
     | 
| 
      
 52 
     | 
    
         
            +
                "http://"+result["url"]
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
              
         
     | 
| 
       48 
55 
     | 
    
         
             
            end
         
     | 
| 
      
 56 
     | 
    
         
            +
            # 126.am api key: d1f04c518037412988e26e449469106f
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,16 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: uri_shortener
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Asakawa Ryu
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2013-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-07-30 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
     | 
    
         
            -
            description: 'Providing types: t.cn, url.cn, url7.me'
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: 'Providing types: t.cn, url.cn, url7.me, 126.am'
         
     | 
| 
       14 
14 
     | 
    
         
             
            email: i@nyangawa.me
         
     | 
| 
       15 
15 
     | 
    
         
             
            executables: []
         
     | 
| 
       16 
16 
     | 
    
         
             
            extensions: []
         
     |