Class: Nous::Crawler::RedirectFollower

Inherits:
Nous::Command show all
Defined in:
lib/nous/crawler/redirect_follower.rb

Defined Under Namespace

Classes: RedirectError

Constant Summary collapse

MAX_HOPS =
5

Instance Method Summary collapse

Methods inherited from Nous::Command

call, #failure, #success

Constructor Details

#initialize(client:, seed_host:, url:, hops_remaining: MAX_HOPS) ⇒ RedirectFollower

Returns a new instance of RedirectFollower.



10
11
12
13
14
15
# File 'lib/nous/crawler/redirect_follower.rb', line 10

def initialize(client:, seed_host:, url:, hops_remaining: MAX_HOPS)
  @client = client
  @seed_host = seed_host
  @url = url
  @hops_remaining = hops_remaining
end

Instance Method Details

#call ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/nous/crawler/redirect_follower.rb', line 17

def call
  response = client.get(url, {})

  return success(payload: [response, Url.new(url)]) unless redirect?(response.status)

  response.close
  follow(response.headers["location"])
end