This repository has been archived by the owner on Nov 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRunner.java
191 lines (173 loc) · 5.93 KB
/
Runner.java
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import java.net.UnknownHostException;
/**
* @date Dec 2, 2014
* @author Dominic Schaff <dominic.schaff@gmail.com>
*/
public class Runner {
public static String USERNAME = "YOUR_USERNAME",
APIID = "YOUR_API_ID",
PASSWORD = "YOUR_PASSWORD",
APIKEY = "YOUR_KEY";
public static void main(String[] args) {
TestHttp();
TestRest();
}
public static void TestHttp() {
System.out.println("STARTING WITH TESTING HTTP:");
// Create New object (Assign auth straight away.):
ClickatellHttp click = new ClickatellHttp(USERNAME, APIID, PASSWORD);
// Using click, test auth:
System.out.println("TESTING GET AUTH");
try {
if (click.testAuth()) {
System.out.println("Authentication was successful");
} else {
System.out
.println("Your authentication details are not correct");
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
}
// Assuming the auth was successful, lets send one message, to one
// recipient:
System.out.println("\nTESTING GET BALANCE");
try {
double response = click.getBalance();
System.out.println(response);
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Assuming the auth was successful, lets send one message, to one
// recipient:
System.out.println("\nTESTING SEND SINGLE MESSAGE");
try {
ClickatellHttp.Message response = click.sendMessage("27821234567",
"Hello, this is a test message!");
System.out.println(response);
if (response.error != null) {
System.out.println(response.error);
} else {
System.out.println("\nTESTING GET STATUS:");
System.out.println(click.getMessageStatus(response.message_id));
System.out.println("\nTESTING STOP:");
System.out.println(click.stopMessage(response.message_id));
System.out.println("\nTESTING GET CHARGE:");
ClickatellHttp.Message replies = click
.getMessageCharge(response.message_id);
System.out.println("Charge: " + replies.charge);
System.out.println("Status: " + replies.status);
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Lets send one message to multiple people:
System.out.println("\nTESTING SEND MULTIPLE NUMBERS ONE MESSAGE");
try {
ClickatellHttp.Message replies[] = click.sendMessage(new String[] {
"27821234567", "27829876543" }, "Test message");
for (ClickatellHttp.Message s : replies) {
System.out.println(s);
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Lets do a coverage test:
System.out.println("\nTESTING COVERAGE");
try {
double reply = click.getCoverage("27820909090");
if (reply < 0) {
System.out.println("Route coverage failed");
} else {
System.out
.println("Route coverage succeded, message could cost:"
+ reply);
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void TestRest() {
System.out.println("\n\nSTARTING WITH TESTING REST:");
// Create New object (Assign auth straight away.):
ClickatellRest click = new ClickatellRest(APIKEY);
// We cannot test for auth, so lets start with balance:
System.out.println("TESTING GET BALANCE");
try {
double response = click.getBalance();
System.out.println(response);
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Assuming the auth was successful, lets send one message, to one
// recipient:
System.out.println("\nTESTING SEND SINGLE MESSAGE");
try {
ClickatellRest.Message response = click.sendMessage("27821234567",
"Hello, this is a test message!");
System.out.println(response);
if (response.error != null) {
System.out.println(response.error);
} else {
System.out.println("\nTESTING STOP:");
System.out.println(click.stopMessage(response.message_id));
System.out.println("\nTESTING GET STATUS:");
ClickatellRest.Message msg = click
.getMessageStatus(response.message_id);
System.out.println("ID:" + msg.message_id);
System.out.println("Status:" + msg.status);
System.out.println("Status Description:" + msg.statusString);
System.out.println("Charge:" + msg.charge);
System.out.println("\nTESTING STOP MESSAGE");
ClickatellRest.Message msgStatus = click
.stopMessage(response.message_id);
System.out.println("ID:" + msgStatus.message_id);
System.out.println("Status:" + msgStatus.status);
System.out.println("Status Description:"
+ msgStatus.statusString);
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Lets send one message to multiple people:
System.out.println("\nTESTING SEND MULTIPLE NUMBERS ONE MESSAGE");
try {
ClickatellRest.Message replies[] = click.sendMessage(new String[] {
"27821234567", "27829876543", "000" }, "Test message");
for (ClickatellRest.Message s : replies) {
System.out.println(s);
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Lets do a coverage test:
System.out.println("\nTESTING COVERAGE");
try {
double reply = click.getCoverage("27820909090");
if (reply < 0) {
System.out.println("Route coverage failed");
} else {
System.out
.println("Route coverage succeded, message could cost:"
+ reply);
}
} catch (UnknownHostException e) {
System.out.println("Host could not be found");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}