compare_linker 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ff36e8002d51aa16c9c31b9d187f564eac1d53
4
- data.tar.gz: 8adab281e5f6a8fcb53c41041a566b45a98235e7
3
+ metadata.gz: fe8706a6e774056382e01562c03e0d80a1b54e27
4
+ data.tar.gz: bbd74f1b4f4f97296235577d5d0c2440a0e592ce
5
5
  SHA512:
6
- metadata.gz: bb90094ecc911eecad452ed5967cd700fd9c1646da356ba2d36d1dbb5832a55196e7af9e4935772ec0dcc98e763c919321b19f815b7606253937ebfaf26d339a
7
- data.tar.gz: 75da3f152b86ce87b961df282d882c84c26c2c5da57f28c194cddd325025b79977c936c7283dfad148aea476adebd0a7869c84b5dbd8ff570f9acd9ffacb0cd6
6
+ metadata.gz: 207de118d2c3361db0e11b8863bc21164b6e0030d6a54a9a33c3630618cfc100a9cb49fbb5defa429f3455619122980f91ba33405e48b3f79f9945a5492b61ed
7
+ data.tar.gz: fdad1e8b92cd042b7f5cde2181e5ee08c49513a650ae5b7bdc7f218f623859434c41e81c1fcf04a86a421ed6151520cfa405a7aef0a009023937b3a1ed4e1c06
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compare_linker (1.1.5)
4
+ compare_linker (1.1.6)
5
5
  httpclient
6
6
  octokit
7
7
 
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "httpclient"
3
+ require "net/http"
3
4
 
4
5
  class CompareLinker
5
6
  class GithubLinkFinder
@@ -22,6 +23,7 @@ class CompareLinker
22
23
  if github_url.nil?
23
24
  @homepage_uri = gem_info["homepage_uri"]
24
25
  else
26
+ github_url = redirect_url(github_url)
25
27
  _, @repo_owner, @repo_name = github_url.match(%r!github\.com/([^/]+)/([^/]+)!).to_a
26
28
  end
27
29
 
@@ -32,5 +34,29 @@ class CompareLinker
32
34
  def repo_full_name
33
35
  "#{@repo_owner}/#{repo_name}"
34
36
  end
37
+
38
+ private
39
+
40
+ def redirect_url(url, limit = 5)
41
+ raise ArgumentError, 'HTTP redirect too deep' if limit <= 0
42
+
43
+ uri = URI.parse(url)
44
+ response = Net::HTTP.get_response(uri)
45
+
46
+ case response
47
+ when Net::HTTPSuccess
48
+ url
49
+ when Net::HTTPRedirection
50
+ redirect_url(to_absolute(response['location'], uri), limit - 1)
51
+ else
52
+ raise 'item not found'
53
+ end
54
+ end
55
+
56
+ def to_absolute(location, uri)
57
+ return location if location =~ /\Ahttp/
58
+ # RFC2394 violation?
59
+ "#{uri.scheme}://#{uri.host}#{location}"
60
+ end
35
61
  end
36
62
  end
@@ -1,3 +1,3 @@
1
1
  class CompareLinker
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
@@ -9,6 +9,7 @@ describe CompareLinker::GithubLinkFinder do
9
9
  describe "#find" do
10
10
  before do
11
11
  allow(HTTPClient).to receive(:get_content).and_return load_fixture("rails.json")
12
+ allow(subject).to receive(:redirect_url).and_return "http://github.com/rails/rails"
12
13
  end
13
14
 
14
15
  it "extracts repo_owner and repo_name" do
@@ -20,6 +21,7 @@ describe CompareLinker::GithubLinkFinder do
20
21
  context "if github url includes trailing slash" do
21
22
  before do
22
23
  allow(HTTPClient).to receive(:get_content).and_return load_fixture("web_translate_it.json")
24
+ allow(subject).to receive(:redirect_url).and_return "http://github.com/atelierconvivialite/webtranslateit/"
23
25
  end
24
26
 
25
27
  it "extracts repo_owner and repo_name without trailing slash" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compare_linker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kensuke Nagae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit