use of com.google.api.client.util.DateTime in project DisCal-Discord-Bot by NovaFox161.
the class EventEndpoint method getEventsForSelectedDate.
public static String getEventsForSelectedDate(Request request, Response response) {
JSONObject requestBody = new JSONObject(request.body());
Long startEpoch = Long.valueOf(requestBody.getString("StartEpoch"));
Long endEpoch = startEpoch + 86400000L;
GuildSettings settings;
if (DiscordAccountHandler.getHandler().hasAccount(request.session().id())) {
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
settings = g.getSettings();
} else {
long guildId = requestBody.getLong("guild_id");
settings = DatabaseManager.getManager().getSettings(guildId);
}
// okay, lets actually get the month's events.
try {
Calendar service;
if (settings.useExternalCalendar()) {
service = CalendarAuth.getCalendarService(settings);
} else {
service = CalendarAuth.getCalendarService();
}
CalendarData calendarData = DatabaseManager.getManager().getMainCalendar(settings.getGuildID());
Events events = service.events().list(calendarData.getCalendarAddress()).setTimeMin(new DateTime(startEpoch)).setTimeMax(new DateTime(endEpoch)).setOrderBy("startTime").setSingleEvents(true).setShowDeleted(false).execute();
List<Event> items = events.getItems();
String tz = "Error/Unknown";
try {
tz = service.calendars().get(calendarData.getCalendarAddress()).execute().getTimeZone();
} catch (Exception ignore) {
}
List<JSONObject> eventsJson = new ArrayList<>();
for (Event e : items) {
JSONObject jo = new JSONObject();
jo.put("id", e.getId());
jo.put("epochStart", e.getStart().getDateTime().getValue());
jo.put("epochEnd", e.getEnd().getDateTime().getValue());
jo.put("timezone", tz);
jo.put("summary", e.getSummary());
jo.put("description", e.getDescription());
if (e.getLocked() != null) {
jo.put("location", e.getLocation());
} else {
jo.put("location", "N/a");
}
jo.put("color", EventColor.fromNameOrHexOrID(e.getColorId()).name());
jo.put("isParent", !(e.getId().contains("_")));
if (e.getRecurrence() != null && e.getRecurrence().size() > 0) {
jo.put("recur", true);
Recurrence r = new Recurrence().fromRRule(e.getRecurrence().get(0));
JSONObject rjo = new JSONObject();
rjo.put("frequency", r.getFrequency().name());
rjo.put("count", r.getCount());
rjo.put("interval", r.getInterval());
jo.put("recurrence", rjo);
} else {
jo.put("recur", false);
JSONObject rjo = new JSONObject();
rjo.put("frequency", EventFrequency.DAILY.name());
rjo.put("count", -1);
rjo.put("interval", 1);
jo.put("recurrence", rjo);
}
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), e.getId());
jo.put("image", ed.getImageLink());
eventsJson.add(jo);
}
JSONObject body = new JSONObject();
body.put("events", eventsJson);
body.put("count", eventsJson.size());
response.body(body.toString());
} catch (Exception e) {
response.body("Internal server error!");
Logger.getLogger().exception(null, "[WEB] Failed to retrieve events for specific date!", e, EventEndpoint.class, true);
return response.body();
}
return response.body();
}
use of com.google.api.client.util.DateTime in project drbookings by DrBookings.
the class EventFactory method newEvent.
public Event newEvent(final String summary, final LocalDate date, final String description) {
final Event event = new Event();
event.setSummary(summary);
event.setDescription("Dr.Bookings:\n" + description);
final Date startDate = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
// An
final Date endDate = new Date(startDate.getTime() + 86400000);
// all-day
// event
// is 1
// day
// (or
// 86400000
// ms)
// long
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
final String startDateStr = dateFormat.format(startDate);
final String endDateStr = dateFormat.format(endDate);
// Out of the 6 methods for creating a DateTime object with no time
// element, only the String version works
final DateTime startDateTime = new DateTime(startDateStr);
final DateTime endDateTime = new DateTime(endDateStr);
// Must use the setDate() method for an all-day event (setDateTime() is
// used for timed events)
final EventDateTime startEventDateTime = new EventDateTime().setDate(startDateTime);
final EventDateTime endEventDateTime = new EventDateTime().setDate(endDateTime);
event.setStart(startEventDateTime);
event.setEnd(endEventDateTime);
return event;
}
use of com.google.api.client.util.DateTime in project jbpm-work-items by kiegroup.
the class AddTaskWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
String taskName = (String) workItem.getParameter("TaskName");
String taskKind = (String) workItem.getParameter("TaskKind");
if (taskName == null) {
logger.error("Missing task name input.");
throw new IllegalArgumentException("Missing task name input.");
}
try {
Tasks service = auth.getTasksService(appName, clientSecret);
TaskList taskList = new TaskList();
taskList.setTitle(taskName);
taskList.setId(taskName);
taskList.setKind(taskKind);
taskList.setUpdated(new DateTime(new Date()));
service.tasklists().insert(taskList).execute();
workItemManager.completeWorkItem(workItem.getId(), null);
} catch (Exception e) {
handleException(e);
}
}
use of com.google.api.client.util.DateTime in project api-samples by youtube.
the class CreateBroadcast method main.
/**
* Create and insert a liveBroadcast resource.
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "createbroadcast");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-createbroadcast-sample").build();
// Prompt the user to enter a title for the broadcast.
String title = getBroadcastTitle();
System.out.println("You chose " + title + " for broadcast title.");
// Create a snippet with the title and scheduled start and end
// times for the broadcast. Currently, those times are hard-coded.
LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
broadcastSnippet.setTitle(title);
broadcastSnippet.setScheduledStartTime(new DateTime("2024-01-30T00:00:00.000Z"));
broadcastSnippet.setScheduledEndTime(new DateTime("2024-01-31T00:00:00.000Z"));
// Set the broadcast's privacy status to "private". See:
// https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.privacyStatus
LiveBroadcastStatus status = new LiveBroadcastStatus();
status.setPrivacyStatus("private");
LiveBroadcast broadcast = new LiveBroadcast();
broadcast.setKind("youtube#liveBroadcast");
broadcast.setSnippet(broadcastSnippet);
broadcast.setStatus(status);
// Construct and execute the API request to insert the broadcast.
YouTube.LiveBroadcasts.Insert liveBroadcastInsert = youtube.liveBroadcasts().insert("snippet,status", broadcast);
LiveBroadcast returnedBroadcast = liveBroadcastInsert.execute();
// Print information from the API response.
System.out.println("\n================== Returned Broadcast ==================\n");
System.out.println(" - Id: " + returnedBroadcast.getId());
System.out.println(" - Title: " + returnedBroadcast.getSnippet().getTitle());
System.out.println(" - Description: " + returnedBroadcast.getSnippet().getDescription());
System.out.println(" - Published At: " + returnedBroadcast.getSnippet().getPublishedAt());
System.out.println(" - Scheduled Start Time: " + returnedBroadcast.getSnippet().getScheduledStartTime());
System.out.println(" - Scheduled End Time: " + returnedBroadcast.getSnippet().getScheduledEndTime());
// Prompt the user to enter a title for the video stream.
title = getStreamTitle();
System.out.println("You chose " + title + " for stream title.");
// Create a snippet with the video stream's title.
LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
streamSnippet.setTitle(title);
// Define the content distribution network settings for the
// video stream. The settings specify the stream's format and
// ingestion type. See:
// https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn
CdnSettings cdnSettings = new CdnSettings();
cdnSettings.setFormat("1080p");
cdnSettings.setIngestionType("rtmp");
LiveStream stream = new LiveStream();
stream.setKind("youtube#liveStream");
stream.setSnippet(streamSnippet);
stream.setCdn(cdnSettings);
// Construct and execute the API request to insert the stream.
YouTube.LiveStreams.Insert liveStreamInsert = youtube.liveStreams().insert("snippet,cdn", stream);
LiveStream returnedStream = liveStreamInsert.execute();
// Print information from the API response.
System.out.println("\n================== Returned Stream ==================\n");
System.out.println(" - Id: " + returnedStream.getId());
System.out.println(" - Title: " + returnedStream.getSnippet().getTitle());
System.out.println(" - Description: " + returnedStream.getSnippet().getDescription());
System.out.println(" - Published At: " + returnedStream.getSnippet().getPublishedAt());
// Construct and execute a request to bind the new broadcast
// and stream.
YouTube.LiveBroadcasts.Bind liveBroadcastBind = youtube.liveBroadcasts().bind(returnedBroadcast.getId(), "id,contentDetails");
liveBroadcastBind.setStreamId(returnedStream.getId());
returnedBroadcast = liveBroadcastBind.execute();
// Print information from the API response.
System.out.println("\n================== Returned Bound Broadcast ==================\n");
System.out.println(" - Broadcast Id: " + returnedBroadcast.getId());
System.out.println(" - Bound Stream Id: " + returnedBroadcast.getContentDetails().getBoundStreamId());
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of com.google.api.client.util.DateTime in project druid by druid-io.
the class GoogleTestUtils method newStorageObject.
public static StorageObject newStorageObject(String bucket, String key, long lastModifiedTimestamp) {
StorageObject object = new StorageObject();
object.setBucket(bucket);
object.setName(key);
object.setUpdated(new DateTime(lastModifiedTimestamp));
object.setEtag("etag");
object.setSize(BigInteger.valueOf(CONTENT.length));
return object;
}
Aggregations