com.twilio.jwt.client.OutgoingClientScope Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twilio Show documentation
Show all versions of twilio Show documentation
Twilio Java Helper Library
package com.twilio.jwt.client;
import com.google.common.base.Joiner;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Scope token for Outgoing Clients.
*/
public class OutgoingClientScope implements Scope {
private static final String SCOPE = Joiner.on(':').join("scope", "client", "outgoing");
private final String applicationSid;
private final String clientName;
private final Map params;
private OutgoingClientScope(Builder b) {
this.applicationSid = b.applicationSid;
this.clientName = b.clientName;
this.params = b.params;
}
@Override
public String getPayload() throws UnsupportedEncodingException {
List queryArgs = new ArrayList<>();
queryArgs.add(Joiner.on('=').join(
URLEncoder.encode("appSid", "UTF-8"),
URLEncoder.encode(this.applicationSid, "UTF-8")
));
if (this.clientName != null) {
queryArgs.add(Joiner.on('=').join(
URLEncoder.encode("clientName", "UTF-8"),
URLEncoder.encode(this.clientName, "UTF-8")
));
}
if (!this.params.isEmpty()) {
queryArgs.add(Joiner.on('=').join(
URLEncoder.encode("appParams", "UTF-8"),
URLEncoder.encode(this.getAppParams(), "UTF-8")
));
}
String queryString = Joiner.on('&').join(queryArgs);
return Joiner.on('?').join(SCOPE, queryString);
}
private String getAppParams() throws UnsupportedEncodingException {
List queryParams = new ArrayList<>();
for (Map.Entry param : params.entrySet()) {
queryParams.add(Joiner.on('=').join(
URLEncoder.encode(param.getKey(), "UTF-8"),
URLEncoder.encode(param.getValue(), "UTF-8")
));
}
return Joiner.on('&').join(queryParams);
}
public static class Builder {
private String applicationSid;
private String clientName;
private Map params = new HashMap<>();
public Builder(String applicationSid) {
this.applicationSid = applicationSid;
}
public Builder clientName(String clientName) {
this.clientName = clientName;
return this;
}
public Builder params(Map params) {
this.params.putAll(params);
return this;
}
public OutgoingClientScope build() {
return new OutgoingClientScope(this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy