├── example.env
├── .gitignore
├── readme.md
├── src
└── main
│ └── java
│ └── com
│ └── platzi
│ └── gatos_app
│ ├── model
│ ├── ImageX.java
│ ├── Cats.java
│ └── FavoriteCat.java
│ ├── Main.java
│ └── service
│ └── CatService.java
└── pom.xml
/example.env:
--------------------------------------------------------------------------------
1 | API_KEY=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | target/
3 | src/main/java/com/santiago/red_social/.DS_Store
4 | src/.DS_Store
5 | .settings/
6 | .project
7 | .classpath
8 | .DS_Store
9 | .env
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # gatos_app
2 |
3 | ## description
4 |
5 | Gatos_app is an application that uses thecatapi to show Cats photos, mark as favorites and delete favorites, the main objetive is to see how we can interact with an API server from Java.
6 |
7 | this repo is part of this [Platzi Course](https://platzi.com/cursos/java-persistencia/).
--------------------------------------------------------------------------------
/src/main/java/com/platzi/gatos_app/model/ImageX.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.platzi.gatos_app.model;
7 |
8 | /**
9 | *
10 | * @author santiaguf
11 | */
12 | public class ImageX {
13 | String id;
14 | String url;
15 |
16 | public String getId() {
17 | return id;
18 | }
19 |
20 | public void setId(String id) {
21 | this.id = id;
22 | }
23 |
24 | public String getUrl() {
25 | return url;
26 | }
27 |
28 | public void setUrl(String url) {
29 | this.url = url;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/platzi/gatos_app/model/Cats.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.platzi.gatos_app.model;
7 |
8 | import io.github.cdimascio.dotenv.Dotenv;
9 |
10 | /**
11 | *
12 | * @author santiaguf
13 | */
14 | public class Cats {
15 | Dotenv dotenv = Dotenv.load();
16 |
17 | String id;
18 | String url;
19 | String apikey = dotenv.get("API_KEY");
20 | String image;
21 |
22 | public String getId() {
23 | return id;
24 | }
25 |
26 | public void setId(String id) {
27 | this.id = id;
28 | }
29 |
30 | public String getUrl() {
31 | return url;
32 | }
33 |
34 | public void setUrl(String url) {
35 | this.url = url;
36 | }
37 |
38 | public String getApikey() {
39 | return apikey;
40 | }
41 |
42 | public void setApikey(String apikey) {
43 | this.apikey = apikey;
44 | }
45 |
46 | public String getImage() {
47 | return image;
48 | }
49 |
50 | public void setImage(String image) {
51 | this.image = image;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/platzi/gatos_app/model/FavoriteCat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.platzi.gatos_app.model;
7 |
8 | import io.github.cdimascio.dotenv.Dotenv;
9 |
10 | /**
11 | *
12 | * @author santiaguf
13 | */
14 | public class FavoriteCat {
15 | Dotenv dotenv = Dotenv.load();
16 |
17 | String id;
18 | String imageId;
19 | String apikey= dotenv.get("API_KEY");
20 | public ImageX image;
21 |
22 | public String getId() {
23 | return id;
24 | }
25 |
26 | public void setId(String id) {
27 | this.id = id;
28 | }
29 |
30 | public String getImageId() {
31 | return imageId;
32 | }
33 |
34 | public void setImageId(String imageId) {
35 | this.imageId = imageId;
36 | }
37 |
38 | public String getApikey() {
39 | return apikey;
40 | }
41 |
42 | public void setApikey(String apikey) {
43 | this.apikey = apikey;
44 | }
45 |
46 | public ImageX getImage() {
47 | return image;
48 | }
49 |
50 | public void setImage(ImageX image) {
51 | this.image = image;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.platzi
5 | gatos_app
6 | 1.0-SNAPSHOT
7 | jar
8 |
9 |
10 | com.squareup.okhttp
11 | okhttp
12 | 2.7.5
13 |
14 |
15 | com.google.code.gson
16 | gson
17 | 2.8.9
18 |
19 |
20 | io.github.cdimascio
21 | java-dotenv
22 | 5.2.2
23 |
24 |
25 |
26 | UTF-8
27 | 12
28 | 12
29 |
30 |
--------------------------------------------------------------------------------
/src/main/java/com/platzi/gatos_app/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.platzi.gatos_app;
7 |
8 | import java.io.IOException;
9 | import javax.swing.JOptionPane;
10 |
11 | import com.platzi.gatos_app.model.Cats;
12 | import com.platzi.gatos_app.service.CatService;
13 |
14 | /**
15 | *
16 | * @author santiaguf
17 | */
18 | public class Main {
19 |
20 | public static void main(String[] args) throws IOException{
21 | int menuOption = -1;
22 | String[] buttoms = {" 1. ver gatos", "2. ver favoritos", "3. salir"};
23 |
24 | do{
25 | String option = (String) JOptionPane.showInputDialog(null, "Gatitos java", "Menu principal", JOptionPane.INFORMATION_MESSAGE, null, buttoms,buttoms[0]);
26 |
27 | for(int i=0;i 800){
103 |
104 | Image background = catImageIcon.getImage();
105 | Image modified = background.getScaledInstance(800, 600, java.awt.Image.SCALE_SMOOTH);
106 | catImageIcon = new ImageIcon(modified);
107 | }
108 |
109 | String[] buttoms = { "ver otra imagen", "favorito", "volver" };
110 | String catId = cat.getId();
111 | String option = (String) JOptionPane.showInputDialog(null, randomCatsMenu, catId, JOptionPane.INFORMATION_MESSAGE, catImageIcon, buttoms,buttoms[0]);
112 |
113 | int selection = -1;
114 |
115 | for(int i=0;i 0){
162 | int min = 1;
163 | int max = catsArray.length;
164 | int aleatorio = (int) (Math.random() * ((max-min)+1)) + min;
165 | int indice = aleatorio-1;
166 | FavoriteCat favoriteCat = catsArray[indice];
167 |
168 |
169 | Image image = null;
170 | try{
171 | URL url = new URL(favoriteCat.image.getUrl());
172 | image = ImageIO.read(url);
173 |
174 | ImageIcon catImageIcon = new ImageIcon(image);
175 |
176 | if(catImageIcon.getIconWidth() > 800){
177 |
178 | Image background = catImageIcon.getImage();
179 | Image modified = background.getScaledInstance(800, 600, java.awt.Image.SCALE_SMOOTH);
180 | catImageIcon = new ImageIcon(modified);
181 | }
182 |
183 | String[] buttoms = { "ver otra imagen", "eliminar favorito", "volver" };
184 | String catId = favoriteCat.getId();
185 | String option = (String) JOptionPane.showInputDialog(null, FavoriteMenu, catId, JOptionPane.INFORMATION_MESSAGE, catImageIcon, buttoms,buttoms[0]);
186 |
187 | int selection = -1;
188 |
189 | for(int i=0;i