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 private Type type; 039 040 /** 041 * Construct a request with the only required parameter, the country code. 042 * 043 * @param country A String containing a two-character country code. 044 */ 045 public SearchNumbersFilter(String country) { 046 this.country = country; 047 } 048 049 public String getCountry() { 050 return country; 051 } 052 053 public String getPattern() { 054 return pattern; 055 } 056 057 public void setPattern(String pattern) { 058 this.pattern = pattern; 059 } 060 061 public String[] getFeatures() { 062 return features; 063 } 064 065 public void setFeatures(String[] features) { 066 this.features = features; 067 } 068 069 public Integer getIndex() { 070 return index; 071 } 072 073 public void setIndex(Integer index) { 074 this.index = index; 075 } 076 077 public Integer getSize() { 078 return size; 079 } 080 081 public void setType(Type type) { 082 this.type = type; 083 } 084 085 public Type getType() { 086 return type; 087 } 088 089 /** 090 * Set the maximum number of matching results to be returned. 091 * 092 * @param size An Integer between 10 and 100 (inclusive) or null, to indicate that the default value should be 093 * used. 094 */ 095 public void setSize(Integer size) { 096 this.size = size; 097 } 098 099 public SearchPattern getSearchPattern() { 100 return searchPattern; 101 } 102 103 /** 104 * @param searchPattern 105 */ 106 public void setSearchPattern(SearchPattern searchPattern) { 107 this.searchPattern = searchPattern; 108 } 109 110 public void addParams(RequestBuilder request) { 111 request.addParameter("country", country); 112 if (features != null && features.length > 0) { 113 request.addParameter("features", StringUtils.join(features, ",")); 114 } 115 if (index != null) { 116 request.addParameter("index", index.toString()); 117 } 118 if (size != null) { 119 request.addParameter("size", size.toString()); 120 } 121 if (pattern != null) { 122 request.addParameter("pattern", pattern); 123 } 124 if (searchPattern != null) { 125 request.addParameter("search_pattern", Integer.toString(searchPattern.getValue())); 126 } 127 if (type != null) { 128 request.addParameter("type", type.getType()); 129 } 130 } 131}