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.voice.ncco; 023 024import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 025import com.fasterxml.jackson.annotation.JsonInclude; 026 027import java.util.Arrays; 028import java.util.Collection; 029import java.util.Map; 030 031/** 032 * An NCCO notify action which allows for custom events to be sent to a configured webhook. 033 */ 034@JsonInclude(value = JsonInclude.Include.NON_NULL) 035@JsonIgnoreProperties(ignoreUnknown = true) 036public class NotifyAction implements Action { 037 private static final String ACTION = "notify"; 038 039 private Map<String, ?> payload; 040 private Collection<String> eventUrl; 041 private EventMethod eventMethod; 042 043 private NotifyAction(Builder builder) { 044 this.payload = builder.payload; 045 this.eventUrl = builder.eventUrl; 046 this.eventMethod = builder.eventMethod; 047 } 048 049 @Override 050 public String getAction() { 051 return ACTION; 052 } 053 054 public Map getPayload() { 055 return payload; 056 } 057 058 public Collection<String> getEventUrl() { 059 return eventUrl; 060 } 061 062 public EventMethod getEventMethod() { 063 return eventMethod; 064 } 065 066 public static Builder builder(Map<String, ?> payload, Collection<String> eventUrl) { 067 return new Builder(payload, eventUrl); 068 } 069 070 public static Builder builder(Map<String, ?> payload, String... eventUrl) { 071 return new Builder(payload, eventUrl); 072 } 073 074 public static class Builder { 075 private Map<String, ?> payload; 076 private Collection<String> eventUrl; 077 private EventMethod eventMethod = null; 078 079 /** 080 * @param payload A Map of String keys and ? values that will be converted to JSON and sent to your event URL. 081 * @param eventUrl The URL to send events to. 082 */ 083 public Builder(Map<String, ?> payload, Collection<String> eventUrl) { 084 this.payload = payload; 085 this.eventUrl = eventUrl; 086 } 087 088 /** 089 * @param payload A Map of String keys and ? values that will be converted to JSON and sent to your event URL. 090 * @param eventUrl The URL to send events to. 091 */ 092 public Builder(Map<String, ?> payload, String... eventUrl) { 093 this(payload, Arrays.asList(eventUrl)); 094 } 095 096 /** 097 * @param payload A Map of String keys and ? values that will be converted to JSON and sent to your event URL. 098 * 099 * @return The {@link Builder} to keep building. 100 */ 101 public Builder payload(Map<String, ?> payload) { 102 this.payload = payload; 103 return this; 104 } 105 106 /** 107 * @param eventUrl The URL to send events to. 108 * 109 * @return The {@link Builder} to keep building. 110 */ 111 public Builder eventUrl(Collection<String> eventUrl) { 112 this.eventUrl = eventUrl; 113 return this; 114 } 115 116 /** 117 * @param eventUrl The URL to send events to. 118 * 119 * @return The {@link Builder} to keep building. 120 */ 121 public Builder eventUrl(String... eventUrl) { 122 return eventUrl(Arrays.asList(eventUrl)); 123 } 124 125 /** 126 * @param eventMethod The HTTP method to use when sending the payload to your event url. 127 * 128 * @return The {@link Builder} to keep building. 129 */ 130 public Builder eventMethod(EventMethod eventMethod) { 131 this.eventMethod = eventMethod; 132 return this; 133 } 134 135 /** 136 * @return A new {@link NotifyAction} object from the stored builder options. 137 */ 138 public NotifyAction build() { 139 return new NotifyAction(this); 140 } 141 } 142}