Skip to content

Commit

Permalink
Allow url_from_event in the WebsiteAgent to be an Array
Browse files Browse the repository at this point in the history
  • Loading branch information
cantino committed Sep 5, 2015
1 parent 3844c25 commit 48d5990
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/agents/website_agent.rb
Expand Up @@ -251,11 +251,11 @@ def check
check_urls(interpolated['url'])
end

def check_urls(in_url)
def check_urls(in_url, payload = {})
return unless in_url.present?

Array(in_url).each do |url|
check_url(url)
check_url(url, payload)
end
end

Expand Down Expand Up @@ -322,11 +322,11 @@ def receive(incoming_events)
interpolate_with(event) do
url_to_scrape =
if url_template = options['url_from_event'].presence
interpolate_string(url_template)
interpolate_options(url_template)
else
event.payload['url']
end
check_url(url_to_scrape,
check_urls(url_to_scrape,
interpolated['mode'].to_s == "merge" ? event.payload : {})
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/models/agents/website_agent_spec.rb
Expand Up @@ -673,6 +673,19 @@
expect(stub).to have_been_requested
end

it "should allow url_from_event to be an array of urls" do
stub1 = stub_request(:any, 'http://example.org/?url=http%3A%2F%2Fxkcd.com')
stub2 = stub_request(:any, 'http://google.org/?url=http%3A%2F%2Fxkcd.com')

@checker.options = @valid_options.merge(
'url_from_event' => ['http://example.org/?url={{url | uri_escape}}', 'http://google.org/?url={{url | uri_escape}}']
)
@checker.receive([@event])

expect(stub1).to have_been_requested
expect(stub2).to have_been_requested
end

it "should interpolate values from incoming event payload" do
expect {
@valid_options['extract'] = {
Expand Down

0 comments on commit 48d5990

Please sign in to comment.