/
AuthorizedApplicationImpl.java
138 lines (118 loc) · 3.45 KB
/
AuthorizedApplicationImpl.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
/*
* Copyright 2015-2017 Austin Keener & Michael Ritter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.jda.client.entities.impl;
import net.dv8tion.jda.client.entities.AuthorizedApplication;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.requests.Request;
import net.dv8tion.jda.core.requests.Response;
import net.dv8tion.jda.core.requests.RestAction;
import net.dv8tion.jda.core.requests.Route;
import net.dv8tion.jda.core.requests.Route.CompiledRoute;
import java.util.Collections;
import java.util.List;
public class AuthorizedApplicationImpl implements AuthorizedApplication
{
private final JDA api;
private final long id;
private final long authId;
private final String description;
private final String iconId;
private final String name;
private final List<String> scopes;
public AuthorizedApplicationImpl(final JDA api, final long authId, final String description, final String iconId,
final long id, final String name, final List<String> scopes)
{
this.api = api;
this.authId = authId;
this.description = description;
this.iconId = iconId;
this.id = id;
this.name = name;
this.scopes = Collections.unmodifiableList(scopes);
}
@Override
public RestAction<Void> delete()
{
CompiledRoute route = Route.Applications.DELETE_AUTHORIZED_APPLICATION.compile(getAuthId());
return new RestAction<Void>(this.api, route, null)
{
@Override
protected void handleResponse(final Response response, final Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
@Override
public boolean equals(final Object obj)
{
return obj instanceof AuthorizedApplicationImpl && this.id == ((AuthorizedApplicationImpl) obj).id;
}
@Override
public String getAuthId()
{
return String.valueOf(this.authId);
}
@Override
public String getDescription()
{
return this.description;
}
@Override
public String getIconId()
{
return this.iconId;
}
@Override
public String getIconUrl()
{
return this.iconId == null ? null
: "https://cdn.discordapp.com/app-icons/" + this.id + '/' + this.iconId + ".png";
}
@Override
public long getIdLong()
{
return this.id;
}
@Override
public JDA getJDA()
{
return this.api;
}
@Override
public String getName()
{
return this.name;
}
@Override
public List<String> getScopes()
{
return this.scopes;
}
@Override
public int hashCode()
{
return Long.hashCode(id);
}
@Override
public String toString()
{
return "AuthorizedApplication(" + this.id + ")";
}
}