Spotify API call
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package tutorial.chapter01;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.itextpdf.barcodes.BarcodeQRCode;
|
||||
import com.itextpdf.kernel.geom.PageSize;
|
||||
@@ -9,22 +10,53 @@ import com.itextpdf.kernel.pdf.PdfNumber;
|
||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
import com.itextpdf.layout.Document;
|
||||
import com.itextpdf.layout.element.Cell;
|
||||
import com.itextpdf.layout.element.IElement;
|
||||
import com.itextpdf.layout.element.Image;
|
||||
import com.itextpdf.layout.element.Paragraph;
|
||||
import com.itextpdf.layout.element.Table;
|
||||
import com.itextpdf.layout.property.TextAlignment;
|
||||
import com.itextpdf.layout.property.UnitValue;
|
||||
import com.itextpdf.layout.property.VerticalAlignment;
|
||||
import com.neovisionaries.i18n.CountryCode;
|
||||
import com.wrapper.spotify.SpotifyApi;
|
||||
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
|
||||
import com.wrapper.spotify.model_objects.credentials.ClientCredentials;
|
||||
import com.wrapper.spotify.model_objects.specification.Album;
|
||||
import com.wrapper.spotify.requests.authorization.client_credentials.ClientCredentialsRequest;
|
||||
import com.wrapper.spotify.requests.data.albums.GetAlbumRequest;
|
||||
|
||||
public class SimpleTable {
|
||||
public static final String DEST = "results/simple_table.pdf";
|
||||
public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180);
|
||||
public static final PdfNumber LANDSCAPE = new PdfNumber(90);
|
||||
public static final PdfNumber PORTRAIT = new PdfNumber(0);
|
||||
public static final PdfNumber SEASCAPE = new PdfNumber(270);
|
||||
|
||||
public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180);
|
||||
public static final PdfNumber LANDSCAPE = new PdfNumber(90);
|
||||
public static final PdfNumber PORTRAIT = new PdfNumber(0);
|
||||
public static final PdfNumber SEASCAPE = new PdfNumber(270);
|
||||
|
||||
private static final String clientId = "d104434912874fbf9ff42e5a91db5179";
|
||||
private static final String clientSecret = "6acdb874210942128ba4991c4f7228b5";
|
||||
|
||||
private static final SpotifyApi spotifyApi = new SpotifyApi.Builder().setClientId(clientId)
|
||||
.setClientSecret(clientSecret).build();
|
||||
private static final ClientCredentialsRequest clientCredentialsRequest = spotifyApi.clientCredentials().build();
|
||||
|
||||
// private static final GetAlbumRequest getAlbumRequest = spotifyApi.getAlbum("3T4tUhGYeRNVUGevb0wThu").market(CountryCode.SE).build();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
final ClientCredentials clientCredentials = clientCredentialsRequest.execute();
|
||||
|
||||
// Set access token for further "spotifyApi" object usage
|
||||
spotifyApi.setAccessToken(clientCredentials.getAccessToken());
|
||||
|
||||
System.out.println("Expires in: " + clientCredentials.getExpiresIn() + " s");
|
||||
|
||||
// final Album album = spotifyApi.getAlbum("3T4tUhGYeRNVUGevb0wThu").market(CountryCode.SE).build().execute();
|
||||
final Album album = spotifyApi.getAlbum("3T4tUhGYeRNVUGevb0wThu").build().execute();
|
||||
|
||||
System.out.println("Name: " + album.getName());
|
||||
} catch (IOException | SpotifyWebApiException e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
File file = new File(DEST);
|
||||
file.getParentFile().mkdirs();
|
||||
new SimpleTable().manipulatePdf(DEST);
|
||||
@@ -33,17 +65,17 @@ public class SimpleTable {
|
||||
protected void manipulatePdf(String dest) throws Exception {
|
||||
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
|
||||
pdfDoc.setDefaultPageSize(PageSize.A4.rotate());
|
||||
|
||||
|
||||
Document doc = new Document(pdfDoc);
|
||||
doc.setMargins(0, 0, 0, 0);
|
||||
|
||||
|
||||
UnitValue[] colWidths = new UnitValue[9];
|
||||
for (int i = 0; i < colWidths.length; i++)
|
||||
colWidths[i] = new UnitValue(UnitValue.PERCENT, 11.10f);
|
||||
|
||||
|
||||
Table table = new Table(colWidths);
|
||||
table.useAllAvailableWidth();
|
||||
|
||||
|
||||
for (int i = 0; i < 17; i++) {
|
||||
table.addCell("hi");
|
||||
}
|
||||
@@ -56,17 +88,17 @@ public class SimpleTable {
|
||||
Paragraph p = new Paragraph();
|
||||
p.setTextAlignment(TextAlignment.CENTER);
|
||||
Image qrcode = new Image(barcodeQRCode.createFormXObject(pdfDoc));
|
||||
qrcode.setWidth(10/25.4f*72);
|
||||
qrcode.setWidth(10 / 25.4f * 72);
|
||||
p.add(qrcode);
|
||||
cell.add(p);
|
||||
table.addCell(cell);
|
||||
|
||||
// table.addCell(new Image(barcodeQRCode.createFormXObject(pdfDoc)));
|
||||
|
||||
|
||||
// table.addCell(new Image(barcodeQRCode.createFormXObject(pdfDoc)));
|
||||
|
||||
table.getCell(1, 1).setVerticalAlignment(VerticalAlignment.MIDDLE);
|
||||
|
||||
doc.add(table);
|
||||
|
||||
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user