eac_rails_utils 0.2.0 → 0.2.1

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
- SHA1:
3
- metadata.gz: 48317e9de4d255c8f419eb298030496144d85a93
4
- data.tar.gz: bba8b002895dcca4c34af057f612b34199226ade
2
+ SHA256:
3
+ metadata.gz: 92359094dd9193f30a276178f430b75878c97cbc08f09a57c0a2f0fa281d5314
4
+ data.tar.gz: 8b9abd7eb1dd2d09ff86bdb631ef5f75166b15db1d5ba1681c3bfb8e8972080c
5
5
  SHA512:
6
- metadata.gz: f609cacab57ddc7427a207d419008678b8fe6e7efcf050f415ba461bd0e3c37c78b6ea162b25cbff58dc3074f6ddaeac2dea3b025fba8e295ea2899cc27195bf
7
- data.tar.gz: 3598abd778ff91d1101dabe8a350f7afc240b41d47128a32f5cc28a78a44a6db3f2b3297408b692fefc7ab8becc955f75546a0f254f04f7cdce02180871f0ad9
6
+ metadata.gz: ec17e583b51e3160e23d39c0cb3898b22f227e9db72f7e26383adedab68bd1b735c0fc9fae83188b94afe168a04a543d489c00002d3496e0e81833bf4cb79014
7
+ data.tar.gz: 106a2660951190c7d0fe6f5d6560d36b807ba1b2fd224ea52d5b7ca3ab12a063708df3ad3ccfaf85723617087dcb7aca5520eade074cad3c79173da3b1848124
@@ -43,19 +43,30 @@ module Eac
43
43
 
44
44
  def content_get_fetch(uri, limit = 10)
45
45
  raise 'too many HTTP redirects' if limit == 0
46
+ uri = Addressable::URI.parse(uri)
47
+ content_get_fetch_result(uri, limit, Net::HTTP.get_response(uri))
48
+ end
46
49
 
47
- response = Net::HTTP.get_response(URI(uri))
48
-
50
+ def content_get_fetch_result(uri, limit, response)
49
51
  case response
50
52
  when Net::HTTPSuccess then
51
53
  response.body
52
54
  when Net::HTTPRedirection then
53
- content_get_fetch(response['location'], limit - 1)
55
+ content_get_fetch_redirect(uri, Addressable::URI.parse(response['location']), limit)
54
56
  else
55
57
  response.value
56
58
  end
57
59
  end
58
60
 
61
+ def content_get_fetch_redirect(original_uri, redirect_uri, limit)
62
+ if redirect_uri.scheme.blank?
63
+ redirect_uri.scheme = original_uri.scheme
64
+ redirect_uri.authority = original_uri.authority
65
+ end
66
+ Rails.logger.debug("#{original_uri} redirected to #{redirect_uri}")
67
+ content_get_fetch(redirect_uri, limit - 1)
68
+ end
69
+
59
70
  def content_hash
60
71
  return content_post if @url[:method] == :post
61
72
  raise "Unknown URL format: #{@url}"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module EacRailsUtils
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - E.A.C.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-13 00:00:00.000000000 Z
11
+ date: 2018-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  requirements: []
239
239
  rubyforge_project:
240
- rubygems_version: 2.6.14
240
+ rubygems_version: 2.7.7
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Código reutilizável para as aplicações Rails da E.A.C..