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