Skip to content

bvilela/google-calendar-util-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Google Calendar Util Lib

🎯 Quality Status

build publish Quality Gate Status

📊 Repository Statistics

Lines of Code GitHub repo size GitHub language count GitHub open issues GitHub open pull requests

🔎 Summary

Java Lib with useful services for Google Calendar API.

💻 Technologies

🚀 GitHub Actions

  • Analyze SonarCloud
  • Build with Maven (branch master)
  • Publish on GitHub Packages (tag/release)

🛠️ Lib Features

Read and create events on Google Calendar.

✔️ Check PMD rules locally

To check PMD rules in your machine, run follow command in app dir:

mvn pmd:check

⚙️ Add dependency in your project

To include this dependency in you project, you need:

  1. Add dependency in your pom.xml:
<dependency>
	<groupId>br.com.bvilela.lib</groupId>
	<artifactId>google-calendar-util-lib</artifactId>
	<version>1.0.0</version>
</dependency>
  1. Add the GitHub repository in your pom.xml:
<repositories>
	<repository>
		<id>github</id>
		<name>GitHub</name>
		<url>https://maven.pkg.github.com/bvilela/google-calendar-util-lib</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</repository>
</repositories>
  1. Add the authentication to the Package Registry in your global settings.xml: USER_HOME\.m2\settings.xml
<servers>
    <server>
        <id>github</id>
        <username>YOUR_USERNAME</username>
        <password>YOUR_AUTH_TOKEN</password>
    </server>
</servers>

Replace the YOUR_USERNAME with your GitHub login name.

Replace the YOUR_AUTH_TOKEN with a generated GitHub Personal Access Token (PAT):

GitHub > Settings > Developer Settings > Personal access tokens > Generate new token.

The token needs at least the read:packages scope.

❗ Otherwise you will get a Not authorized exception.

🔑 Create ClientId and ClientSecret on Google Cloud Platform

For generate ClientId and ClientSecret, see these documentations:

  • Remember to add your gmail in Test Users in your Project in Google Cloud Console
  • Add following scopes in your app:
    • https://www.googleapis.com/auth/calendar
    • https://www.googleapis.com/auth/calendar.events

💡 How to Use this Lib in your project

In your Application Class add:

@SpringBootApplication
@ComponentScan({"<your-path>", "br.com.bvilela.lib"})
public class Application {

}

This make your Spring Application recognise the Spring Services of lib.

To create a event use:

import br.com.bvilela.lib.enuns.ColorEnum;
import br.com.bvilela.lib.model.CalendarEvent;
import br.com.bvilela.lib.service.GoogleCalendarCreateService;

@Autowired
private GoogleCalendarCreateService calendarService;

CalendarEvent dto = CalendarEvent.builder()
		.setSummary("My Event Title")
		.setLocation("My Event Location")
		.setDescription("My Event Description")
		.setDateTimeStart(LocalDateTime.of(2022, 6, 20, 20, 0))
		.setDateTimeEnd(LocalDateTime.of(2022, 6, 20, 21, 0))
		.setColor(ColorEnum.SALVIA) // Default: ColorEnum.PADRAO
		.setTimeZone("America/Sao_Paulo") // Default: "America/Sao_Paulo"
		.build();

calendarService.createEvent(dto);
// or
calendarService.createEvents(List.of(dto1, dto2...));

📝 Enabled Default Log

To enable default logging of events sent to Google Calendar, follow these steps:

  1. In your application.properties add:
bvilela.lib.google.calendar.log.enabled=true

Example Default Log Output

Sending Event to Google Calendar...
CalendarEvent[Summary=myEventTitle, Dates=(2022-07-19T21:30 - 2022-07-19T22:00), Color=SALVIA]

🔒 Change Location google-credentials.json file

If you don't want or can't add the google-credentials.json file in the src directory, add this property in your application.properties and set the directory to save the file.

bvilela.lib.google.calendar.credentials.path=D:\\my-directory

⬆ Voltar ao topo