From d67ab70f5252e6e61fc99316d836921ae47b2200 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 26 Feb 2013 21:54:00 +0100 Subject: [PATCH] Add filter that performs an HTTP query for a previously extract URL. --- .../rhynodge/filters/HttpQueryFilter.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/HttpQueryFilter.java 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(); + } + +} -- 2.7.4