-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathConnectAppReader.java
More file actions
150 lines (132 loc) · 4.38 KB
/
ConnectAppReader.java
File metadata and controls
150 lines (132 loc) · 4.38 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Api
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package com.twilio.rest.api.v2010.account;
import com.twilio.base.Page;
import com.twilio.base.Reader;
import com.twilio.base.ResourceSet;
import com.twilio.constant.EnumConstants.ParameterType;
import com.twilio.converter.Serializer;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;
import com.twilio.exception.RestException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Request;
import com.twilio.http.Response;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.Domains;
import com.twilio.type.*;
public class ConnectAppReader extends Reader<ConnectApp> {
private String pathAccountSid;
private Long pageSize;
public ConnectAppReader() {}
public ConnectAppReader(final String pathAccountSid) {
this.pathAccountSid = pathAccountSid;
}
public ConnectAppReader setPageSize(final Long pageSize) {
this.pageSize = pageSize;
return this;
}
@Override
public ResourceSet<ConnectApp> read(final TwilioRestClient client) {
return new ResourceSet<>(this, client, firstPage(client));
}
public Page<ConnectApp> firstPage(final TwilioRestClient client) {
String path = "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json";
this.pathAccountSid =
this.pathAccountSid == null
? client.getAccountSid()
: this.pathAccountSid;
path =
path.replace(
"{" + "AccountSid" + "}",
this.pathAccountSid.toString()
);
Request request = new Request(
HttpMethod.GET,
Domains.API.toString(),
path
);
addQueryParams(request);
return pageForRequest(client, request);
}
private Page<ConnectApp> pageForRequest(
final TwilioRestClient client,
final Request request
) {
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException(
"ConnectApp read failed: Unable to connect to server"
);
} else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) {
RestException restException = RestException.fromJson(
response.getStream(),
client.getObjectMapper()
);
if (restException == null) {
throw new ApiException(
"Server Error, no content",
response.getStatusCode()
);
}
throw new ApiException(restException);
}
return Page.fromJson(
"connect_apps",
response.getContent(),
ConnectApp.class,
client.getObjectMapper()
);
}
@Override
public Page<ConnectApp> previousPage(
final Page<ConnectApp> page,
final TwilioRestClient client
) {
Request request = new Request(
HttpMethod.GET,
page.getPreviousPageUrl(Domains.API.toString())
);
return pageForRequest(client, request);
}
@Override
public Page<ConnectApp> nextPage(
final Page<ConnectApp> page,
final TwilioRestClient client
) {
Request request = new Request(
HttpMethod.GET,
page.getNextPageUrl(Domains.API.toString())
);
return pageForRequest(client, request);
}
@Override
public Page<ConnectApp> getPage(
final String targetUrl,
final TwilioRestClient client
) {
Request request = new Request(HttpMethod.GET, targetUrl);
return pageForRequest(client, request);
}
private void addQueryParams(final Request request) {
if (pageSize != null) {
Serializer.toString(
request,
"PageSize",
pageSize,
ParameterType.QUERY
);
}
}
}