forked from campaignmonitor/createsend-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplates.java
More file actions
executable file
·127 lines (116 loc) · 5 KB
/
Templates.java
File metadata and controls
executable file
·127 lines (116 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Copyright (c) 2011 Toby Brain
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.createsend;
import com.createsend.models.templates.TemplateDetails;
import com.createsend.models.templates.TemplateForCreate;
import com.createsend.util.JerseyClient;
import com.createsend.util.JerseyClientImpl;
import com.createsend.util.exceptions.CreateSendException;
/**
* Provides methods for accessing all <a href="http://www.campaignmonitor.com/api/templates/" target="_blank">
* Template</a> resources in the Campaign Monitor API *
*/
public class Templates {
private String templateID;
private JerseyClient client;
/**
* Constructor.
* Use this for creating new templates.
*/
public Templates() {
this(null);
}
/**
* Constructor.
* @param templateID The ID of the template to apply calls to.
*/
public Templates(String templateID) {
this(templateID, new JerseyClientImpl());
}
/**
* Constructor.
* @param templateID The ID of the template to apply any calls to.
* @param client The {@link com.createsend.util.JerseyClient} to use for API requests
*/
public Templates(String templateID, JerseyClient client) {
setTemplateID(templateID);
this.client = client;
}
/**
* Gets the current template ID.
* @return The current template ID.
*/
public String getTemplateID() {
return templateID;
}
/**
* Sets the ID of the template to apply API calls to.
* @param templateID The ID of the template to apply API calls to.
*/
public void setTemplateID(String templateID) {
this.templateID = templateID;
}
/**
* Creates a new template for the specified client.
* After a successful call, this method sets the current template ID to that of the
* newly created template.
* @param clientID The ID of the client to create the template for.
* @param template The template details.
* @return The ID of the newly created template
* @throws CreateSendException Thrown when the API responds with HTTP Status >= 400
* @see <a href="http://www.campaignmonitor.com/api/templates/#creating_a_template" target="_blank">
* Creating a template</a>
*/
public String create(String clientID, TemplateForCreate template) throws CreateSendException {
templateID = client.post(String.class, template, "templates", clientID + ".json");
return templateID;
}
/**
* Gets the details of the current template
* @return The details of the current template
* @throws CreateSendException Thrown when the API responds with HTTP Status >= 400
* @see <a href="http://www.campaignmonitor.com/api/templates/#getting_a_template" target="_blank">
* Getting a template</a>
*/
public TemplateDetails get() throws CreateSendException {
return client.get(TemplateDetails.class, "templates", templateID + ".json");
}
/**
* Updates a template with the specified details
* @param template The template details to use
* @throws CreateSendException Thrown when the API responds with HTTP Status >= 400
* @see <a href="http://www.campaignmonitor.com/api/templates/#updating_a_template" target="_blank">
* Updating a template</a>
*/
public void update(TemplateForCreate template) throws CreateSendException {
client.put(template, "templates", templateID + ".json");
}
/**
* Deletes the template with the current ID
* @throws CreateSendException Thrown when the API responds with HTTP Status >= 400
* @see <a href="http://www.campaignmonitor.com/api/templates/#deleting_a_template" target="_blank">
* Deleting a template</a>
*/
public void delete() throws CreateSendException {
client.delete("templates", templateID + ".json");
}
}