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.common; 017 018import com.fasterxml.jackson.annotation.*; 019 020import java.util.HashMap; 021import java.util.Map; 022 023@JsonIgnoreProperties(ignoreUnknown = true) 024@JsonInclude(JsonInclude.Include.NON_NULL) 025/** 026 * Data class which can be deserialized into a webhook for the Vonage API. 027 */ 028public class Webhook { 029 private String address; 030 @JsonProperty("http_method") 031 private HttpMethod method; 032 033 private Webhook() { 034 // Required for Deserialization 035 } 036 037 public Webhook(String address, HttpMethod method) { 038 this.address = address; 039 this.method = method; 040 } 041 042 public String getAddress() { 043 return address; 044 } 045 046 public HttpMethod getMethod() { 047 return method; 048 } 049 050 public enum Type { 051 ANSWER("answer_url"), 052 EVENT("event_url"), 053 INBOUND("inbound_url"), 054 STATUS("status_url"), 055 UNKNOWN("unknown"); 056 057 private String name; 058 059 private static final Map<String, Type> TYPE_INDEX = new HashMap<>(); 060 061 static { 062 for (Type type : Type.values()) { 063 TYPE_INDEX.put(type.name, type); 064 } 065 } 066 067 Type(String name) { 068 this.name = name; 069 } 070 071 @JsonValue 072 public String getName() { 073 return name; 074 } 075 076 @JsonCreator 077 public static Type fromName(String name) { 078 Type foundType = TYPE_INDEX.get(name.toLowerCase()); 079 return (foundType != null) ? foundType : UNKNOWN; 080 } 081 } 082}