001/*
002 * Copyright (c) 2011-2017 Nexmo Inc
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.nexmo.client.numbers;
023
024import org.apache.commons.lang3.StringUtils;
025import org.apache.http.client.methods.RequestBuilder;
026
027/**
028 * This class encapsulates a request to search for available Nexmo Virtual Numbers.
029 */
030public class SearchNumbersFilter {
031    private final String country;
032
033    private String pattern;
034    private SearchPattern searchPattern;
035    private String[] features;
036    private Integer index;
037    private Integer size;
038
039    /**
040     * Construct a request with the only required parameter, the country code.
041     *
042     * @param country A String containing a two-character country code.
043     */
044    public SearchNumbersFilter(String country) {
045        this.country = country;
046    }
047
048    public String getCountry() {
049        return country;
050    }
051
052    public String getPattern() {
053        return pattern;
054    }
055
056    public void setPattern(String pattern) {
057        this.pattern = pattern;
058    }
059
060    public String[] getFeatures() {
061        return features;
062    }
063
064    public void setFeatures(String[] features) {
065        this.features = features;
066    }
067
068    public Integer getIndex() {
069        return index;
070    }
071
072    public void setIndex(Integer index) {
073        this.index = index;
074    }
075
076    public Integer getSize() {
077        return size;
078    }
079
080    /**
081     * Set the maximum number of matching results to be returned.
082     *
083     * @param size An Integer between 10 and 100 (inclusive) or null, to indicate that the default value should be used.
084     */
085    public void setSize(Integer size) {
086        this.size = size;
087    }
088
089    public SearchPattern getSearchPattern() {
090        return searchPattern;
091    }
092
093    /**
094     *
095     * @param searchPattern
096     */
097    public void setSearchPattern(SearchPattern searchPattern) {
098        this.searchPattern = searchPattern;
099    }
100
101    public void addParams(RequestBuilder request) {
102        request.addParameter("country", country);
103        if (features != null && features.length > 0) {
104            request.addParameter("features", StringUtils.join(features, ","));
105        }
106        if (index != null) {
107            request.addParameter("index", index.toString());
108        }
109        if (size != null) {
110            request.addParameter("size", size.toString());
111        }
112        if (pattern != null) {
113            request.addParameter("pattern", pattern);
114        }
115        if (searchPattern != null) {
116            request.addParameter("search_pattern", Integer.toString(searchPattern.getValue()));
117        }
118    }
119}