All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twilio.sdk.resource.instance.CallerIdValidation Maven / Gradle / Ivy

There is a newer version: 7.0.0-rc-10
Show newest version
package com.twilio.sdk.resource.instance;

import com.twilio.sdk.TwilioRestResponse;

import java.util.HashMap;
import java.util.Map;

public class CallerIdValidation {
	
	/** The properties. */
	private Map properties;
	
	/** The json keys. */
	private boolean jsonKeys = true;
	
	/**
	 * Instantiates a new caller id validation.
	 *
	 * @param response the response
	 */
	public CallerIdValidation(TwilioRestResponse response) {
		this.properties = new HashMap(response.toMap());
		this.jsonKeys = response.isJson();
	}
	
	/**
	 * Gets the validation code.
	 *
	 * @return the validation code
	 */
	public String getValidationCode() {
		//TODO better parsing here
		if (this.jsonKeys) {
			return getProperty("validation_code");
		}
		
		return getProperty("ValidationCode");
	}
	
	/**
	 * Gets the phone number.
	 *
	 * @return the phone number
	 */
	public String getPhoneNumber() {
		//TODO better parsing here
		if (this.jsonKeys) {
			return getProperty("phone_number");
		}
		
		return getProperty("PhoneNumber");
	}
	
	/**
	 * Gets the property.
	 *
	 * @param name the name
	 * @return the property
	 */
	public String getProperty(String name) {
		Object prop = properties.get(name);
		prop = properties.get(name);

		if (prop == null) {
			throw new IllegalArgumentException("Property " + name
					+ " does not exist");
		}

		if (prop instanceof String) {
			return (String) prop;
		}

		throw new IllegalArgumentException("Property " + name
				+ " is an object.  Use getOjbect() instead.");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy