001package silicondust;
002/*-
003 * ##########################################################################
004 * TV H/W, EPGs, and Recording
005 * $Id: HDHRPrimeClient.java 6118 2020-06-04 19:31:45Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/silicondust/trunk/src/main/java/silicondust/HDHRPrimeClient.java $
007 * %%
008 * Copyright (C) 2013 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.http.ProtocolClient;
024import java.util.List;
025import org.apache.http.HttpEntity;
026import org.apache.http.impl.client.HttpClientBuilder;
027import lombok.ToString;
028
029import static java.util.Objects.requireNonNull;
030
031/**
032 * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
033 * (CableCard) HTTP client.
034 *
035 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
036 * @version $Revision: 6118 $
037 */
038@ToString
039public class HDHRPrimeClient extends ProtocolClient<HDHRPrimeProtocol> {
040    private final String host;
041
042    /**
043     * Sole public constructor.
044     *
045     * @param   host            The host IP or name.
046     */
047    public HDHRPrimeClient(String host) {
048        this(HttpClientBuilder.create(), host);
049    }
050
051    /**
052     * Protected constructor.
053     *
054     * @param   builder         A configured {@link HttpClientBuilder}.
055     * @param   host            The HDHR Prime host name or IP
056     *                          ({@link String}).
057     */
058    protected HDHRPrimeClient(HttpClientBuilder builder, String host) {
059        super(builder, null, HDHRPrimeProtocol.class);
060        super.mapper = ObjectMapperConfiguration.MAPPER;
061
062        this.host = requireNonNull(host, "host");
063    }
064
065    /**
066     * See {@link HDHRPrimeProtocol#getLineup(String,String)}.
067     *
068     * @param   type            The requested entity type.
069     *
070     * @return  The {@link HttpEntity} containing the line-up.
071     *
072     * @throws  Exception       If an exception is encountered invoking the
073     *                          {@link HDHRPrimeProtocol#getLineup(String,String)}.
074     */
075    public HttpEntity getLineup(String type) throws Exception {
076        return proxy().getLineup(host, type).getEntity();
077    }
078
079    /**
080     * See {@link HDHRPrimeProtocol#getLineup(String,String)}.
081     *
082     * @return  The {@link List} of {@link LineupEntry}s containing the
083     *          line-up.
084     *
085     * @throws  Exception       If an exception is encountered invoking the
086     *                          {@link HDHRPrimeProtocol#getLineup(String,String)}.
087     */
088    public List<LineupEntry> getLineup() throws Exception {
089        return proxy().getLineup(host);
090    }
091
092    /**
093     * See {@link HDHRPrimeProtocol#stream(String,Integer,Integer,Integer)}.
094     *
095     * @param   tuner           The tuner to use.
096     * @param   channel         The channel to tune.
097     * @param   duration        The time to stream in seconds.
098     *
099     * @return  The {@link HttpEntity} containing the stream.
100     *
101     * @throws  Exception       If an exception is encountered invoking the
102     *                          {@link HDHRPrimeProtocol#getLineup}.
103     */
104    public HttpEntity stream(Integer tuner, Integer channel,
105                             Integer duration) throws Exception {
106        return proxy().stream(host, tuner, channel, duration).getEntity();
107    }
108}