unshorter 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c6ba9c4469d426795bbfc472072ee580f44e661dd74fb9d298d2ed9e480d0e4e
4
+ data.tar.gz: fc193a8459cafa218e7170fdc07cb8463624060fcc6ff3b9c7c924980ac72461
5
+ SHA512:
6
+ metadata.gz: 790cf798a1f43a062abc04fc0cdada8535020da1d2ccd8aacef2f6a88216f6e0e1540be2acaca17a902a3d6995a75f8b89f8180f8ec10f2052566a2c5304c7fc
7
+ data.tar.gz: 8865391eb97f0cca9c53e0161a9f6f69e9053d3fa1a1230e66c9a66b9d8b0340b08ab8a2944b1b65326618487f18df17d3cd13e7cb96284355d72bc9c46741c5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,74 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - "**/*_spec.rb"
7
+
8
+ Metrics/MethodLength:
9
+ Max: 40
10
+
11
+ Metrics/ModuleLength:
12
+ Max: 200
13
+ Exclude:
14
+ - "**/*_spec.rb"
15
+
16
+ Metrics/AbcSize:
17
+ Enabled: false
18
+
19
+ Metrics/CyclomaticComplexity:
20
+ Enabled: false
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Enabled: false
24
+
25
+ Layout/LineLength:
26
+ Max: 120
27
+
28
+ Layout/ParameterAlignment:
29
+ EnforcedStyle: with_fixed_indentation
30
+
31
+ Layout/CaseIndentation:
32
+ EnforcedStyle: case
33
+ SupportedStyles:
34
+ - case
35
+ - end
36
+ IndentOneStep: true
37
+
38
+ Layout/EndAlignment:
39
+ EnforcedStyleAlignWith: variable
40
+
41
+ Style/PercentLiteralDelimiters:
42
+ PreferredDelimiters:
43
+ '%w': "[]"
44
+ '%W': "[]"
45
+
46
+ Style/StringLiterals:
47
+ EnforcedStyle: double_quotes
48
+
49
+ Style/StringLiteralsInInterpolation:
50
+ EnforcedStyle: double_quotes
51
+
52
+ Style/StructInheritance:
53
+ Enabled: false
54
+
55
+ Style/AndOr:
56
+ Enabled: false
57
+
58
+ Style/Not:
59
+ Enabled: false
60
+
61
+ Style/DoubleNegation:
62
+ Enabled: false
63
+
64
+ Style/HashEachMethods:
65
+ Enabled: true
66
+
67
+ Style/HashTransformKeys:
68
+ Enabled: true
69
+
70
+ Style/HashTransformValues:
71
+ Enabled: true
72
+
73
+ Documentation:
74
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in unshorter.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unshorter (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.1.0)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (13.0.1)
17
+ rexml (3.2.4)
18
+ rspec (3.9.0)
19
+ rspec-core (~> 3.9.0)
20
+ rspec-expectations (~> 3.9.0)
21
+ rspec-mocks (~> 3.9.0)
22
+ rspec-core (3.9.1)
23
+ rspec-support (~> 3.9.1)
24
+ rspec-expectations (3.9.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-mocks (3.9.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-support (3.9.2)
31
+ rubocop (0.80.1)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ rexml
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 1.7)
39
+ ruby-progressbar (1.10.1)
40
+ unicode-display_width (1.6.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.17)
47
+ rake (~> 13.0)
48
+ rspec (~> 3.0)
49
+ rubocop (= 0.80.1)
50
+ unshorter!
51
+
52
+ BUNDLED WITH
53
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Unshorter
2
+
3
+ The library for expanding short urls provided by url shortening services like tinyurl.com, bit.ly, etc.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'unshorter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install unshorter
20
+
21
+ ## Usage
22
+ ```ruby
23
+ require 'unshorter'
24
+ unshorter = Unshorter.new
25
+ original_url = unshorter.call('https://cutt.ly/1tP7j2t')
26
+ p "Original url is: #{original_url}"
27
+ ```
28
+
29
+ Unshorter support those services:
30
+
31
+ - https://bit.ly
32
+ - http://0rz.tw
33
+ - https://2.gp
34
+ - http://alturl.com
35
+ - http://chilp.it
36
+ - https://clck.ru
37
+ - https://cutt.us
38
+ - https://is.gd
39
+ - http://merky.de
40
+ - https://soo.gd
41
+ - https://tiny.pl
42
+ - https://tinyurl.com
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/heckfy/unshorter.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "unshorter"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/unshorter.rb ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "net/http"
5
+
6
+ class Unshorter
7
+ attr_reader :max_level
8
+
9
+ def initialize(max_level = 5)
10
+ @max_level = max_level
11
+ end
12
+
13
+ def call(url)
14
+ url = "http://#{url}" if url !~ %r{^(http|https)://}
15
+ original_uri = uri = URI(url)
16
+ max_level.times do
17
+ response = Net::HTTP.get_response(uri)
18
+
19
+ if %w[301 302].include?(response.code)
20
+ uri = URI(response["location"])
21
+ next
22
+ end
23
+
24
+ if original_uri.host.sub(/www\./, "") == uri.host
25
+ break response.body.scan(%r{location=['|"]([a-z:/\.\d]+)['|"]}).flatten.fetch(0, nil)
26
+ end
27
+
28
+ break uri.to_s
29
+ end
30
+ end
31
+ end
data/unshorter.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unshorter"
8
+ spec.version = "1.0.0"
9
+ spec.authors = ["heckfy"]
10
+ spec.email = ["heckfyoz@gmail.com"]
11
+
12
+ spec.summary = "The library for expanding short urls provided by url shortening services"
13
+ spec.description = "The library for expanding short urls provided by url shortening services"
14
+ spec.homepage = "https://github.com/heckfy/unshorter"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "rubocop", "0.80.1"
30
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unshorter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - heckfy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.80.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.80.1
69
+ description: The library for expanding short urls provided by url shortening services
70
+ email:
71
+ - heckfyoz@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/unshorter.rb
88
+ - unshorter.gemspec
89
+ homepage: https://github.com/heckfy/unshorter
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: The library for expanding short urls provided by url shortening services
112
+ test_files: []