1 /*
2 * Copyright (c) 2023. Roland T. Lichti, Kaiserpfalz EDV-Service.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 package de.kaiserpfalzedv.commons.core.libravatar;
19
20 import org.springframework.boot.context.properties.EnableConfigurationProperties;
21
22 import de.kaiserpfalzedv.commons.api.libravatar.AvatarOptions;
23 import jakarta.enterprise.context.ApplicationScoped;
24 import jakarta.inject.Inject;
25 import lombok.RequiredArgsConstructor;
26
27 /**
28 * <p>AvatarGenerator -- The service to generate libravatars with.</p>
29 *
30 * @author rlichti {@literal <rlichti@kaiserpfalz-edv.de>}
31 * @since 1.0.0 2023-01-19
32 */
33 @ApplicationScoped
34 @EnableConfigurationProperties(AvatarOptions.class)
35 @RequiredArgsConstructor(onConstructor = @__(@Inject))
36 public class AvatarGenerator {
37 private final AvatarOptions options;
38
39 public String generateUri(final String email) {
40 return new AvatarImpl(email).buildUrl(this.options);
41 }
42
43 public byte[] download(final String email) {
44 return new AvatarImpl(email).download(this.options);
45 }
46 }