001/* 002 * Copyright 2020 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.numbers; 017 018import org.apache.commons.lang3.StringUtils; 019import org.apache.http.client.methods.RequestBuilder; 020 021/** 022 * This class encapsulates a request to search for available Vonage Virtual Numbers. 023 */ 024public class SearchNumbersFilter { 025 private final String country; 026 027 private String pattern; 028 private SearchPattern searchPattern; 029 private String[] features; 030 private Integer index; 031 private Integer size; 032 private Type type; 033 034 /** 035 * Construct a request with the only required parameter, the country code. 036 * 037 * @param country A String containing a two-character country code. 038 */ 039 public SearchNumbersFilter(String country) { 040 this.country = country; 041 } 042 043 public String getCountry() { 044 return country; 045 } 046 047 public String getPattern() { 048 return pattern; 049 } 050 051 public void setPattern(String pattern) { 052 this.pattern = pattern; 053 } 054 055 public String[] getFeatures() { 056 return features; 057 } 058 059 public void setFeatures(String[] features) { 060 this.features = features; 061 } 062 063 public Integer getIndex() { 064 return index; 065 } 066 067 public void setIndex(Integer index) { 068 this.index = index; 069 } 070 071 public Integer getSize() { 072 return size; 073 } 074 075 public void setType(Type type) { 076 this.type = type; 077 } 078 079 public Type getType() { 080 return type; 081 } 082 083 /** 084 * Set the maximum number of matching results to be returned. 085 * 086 * @param size An Integer between 10 and 100 (inclusive) or null, to indicate that the default value should be 087 * used. 088 */ 089 public void setSize(Integer size) { 090 this.size = size; 091 } 092 093 public SearchPattern getSearchPattern() { 094 return searchPattern; 095 } 096 097 /** 098 * @param searchPattern 099 */ 100 public void setSearchPattern(SearchPattern searchPattern) { 101 this.searchPattern = searchPattern; 102 } 103 104 public void addParams(RequestBuilder request) { 105 request.addParameter("country", country); 106 if (features != null && features.length > 0) { 107 request.addParameter("features", StringUtils.join(features, ",")); 108 } 109 if (index != null) { 110 request.addParameter("index", index.toString()); 111 } 112 if (size != null) { 113 request.addParameter("size", size.toString()); 114 } 115 if (pattern != null) { 116 request.addParameter("pattern", pattern); 117 } 118 if (searchPattern != null) { 119 request.addParameter("search_pattern", Integer.toString(searchPattern.getValue())); 120 } 121 if (type != null) { 122 request.addParameter("type", type.getType()); 123 } 124 } 125}