From: David ‘Bombe’ Roden Date: Tue, 26 Feb 2013 20:54:00 +0000 (+0100) Subject: Add filter that performs an HTTP query for a previously extract URL. X-Git-Tag: v2~309 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d67ab70f5252e6e61fc99316d836921ae47b2200;p=rhynodge.git Add filter that performs an HTTP query for a previously extract URL. --- diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/HttpQueryFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/HttpQueryFilter.java new file mode 100644 index 0000000..2600288 --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/filters/HttpQueryFilter.java @@ -0,0 +1,48 @@ +/* + * rhynodge - HttpQueryFilter.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.rhynodge.filters; + +import static com.google.common.base.Preconditions.*; + +import net.pterodactylus.rhynodge.Filter; +import net.pterodactylus.rhynodge.State; +import net.pterodactylus.rhynodge.queries.HttpQuery; +import net.pterodactylus.rhynodge.states.HttpState; +import net.pterodactylus.rhynodge.states.StringState; + +/** + * {@link Filter} implementation that uses the {@link StringState#value() value} + * of a {@link StringState} as a URL for {@link HttpQuery}, turning it into an + * {@link HttpState}. + * + * @author David ‘Bombe’ Roden + */ +public class HttpQueryFilter implements Filter { + + @Override + public State filter(State state) { + checkArgument(state instanceof StringState, "state must be a String state"); + + StringState stringState = (StringState) state; + String url = stringState.value(); + + HttpQuery query = new HttpQuery(url); + return query.state(); + } + +}