com.jdroid.github.service.EventService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdroid-java-github Show documentation
Show all versions of jdroid-java-github Show documentation
Java Connector for GitHub API
/*******************************************************************************
* Copyright (c) 2011 GitHub Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Jason Tsay (GitHub Inc.) - initial API and implementation
*******************************************************************************/
package com.jdroid.github.service;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_EVENTS;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_NETWORKS;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_ORGS;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_PUBLIC;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_RECEIVED_EVENTS;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_REPOS;
import static com.jdroid.github.client.IGitHubConstants.SEGMENT_USERS;
import static com.jdroid.github.client.PagedRequest.PAGE_FIRST;
import static com.jdroid.github.client.PagedRequest.PAGE_SIZE;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import com.jdroid.github.IRepositoryIdProvider;
import com.jdroid.github.client.GitHubClient;
import com.jdroid.github.client.PageIterator;
import com.jdroid.github.client.PagedRequest;
import com.jdroid.github.event.Event;
/**
* Service class for interacting with Events
*
* @see GitHub Event API
* documentation
* @see GitHub Event types
* API documentation
*/
public class EventService extends GitHubService {
/**
* Create event service
*/
public EventService() {
super();
}
/**
* Create event service
*
* @param client
*/
public EventService(GitHubClient client) {
super(client);
}
/**
* Create page iterator for all public events
*
* @return events page iterator
*/
public PageIterator pagePublicEvents() {
return pagePublicEvents(PAGE_SIZE);
}
/**
* Create page iterator for all public events
*
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pagePublicEvents(final int size) {
return pagePublicEvents(PAGE_FIRST, size);
}
/**
* Create page iterator for all public events
*
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pagePublicEvents(final int start, final int size) {
PagedRequest request = createPagedRequest(start, size);
request.setUri(SEGMENT_EVENTS);
request.setType(new TypeToken>() {
}.getType());
return createPageIterator(request);
}
/**
* Create page iterator for a given repo's events
*
* @param repository
* @return events page iterator
*/
public PageIterator pageEvents(IRepositoryIdProvider repository) {
return pageEvents(repository, PAGE_SIZE);
}
/**
* Create page iterator for a given repo's events
*
* @param repository
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageEvents(IRepositoryIdProvider repository,
final int size) {
return pageEvents(repository, PAGE_FIRST, size);
}
/**
* Create page iterator for a given repo's events
*
* @param repository
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageEvents(IRepositoryIdProvider repository,
final int start, final int size) {
PagedRequest request = createRepoEventRequest(repository, start,
size);
return createPageIterator(request);
}
/**
* Create page iterator for a given repo network's events
*
* @param repository
* @return events page iterator
*/
public PageIterator pageNetworkEvents(
IRepositoryIdProvider repository) {
return pageNetworkEvents(repository, PAGE_SIZE);
}
/**
* Create page iterator for a given repo network's events
*
* @param repository
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageNetworkEvents(
IRepositoryIdProvider repository, final int size) {
return pageNetworkEvents(repository, PAGE_FIRST, size);
}
/**
* Create page iterator for a given repo network's events
*
* @param repository
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageNetworkEvents(
IRepositoryIdProvider repository, final int start, final int size) {
PagedRequest request = createNetworkRepoEventRequest(repository,
start, size);
return createPageIterator(request);
}
/**
* Create page iterator for a given org's events
*
* @param org
* @return events page iterator
*/
public PageIterator pageOrgEvents(String org) {
return pageOrgEvents(org, PAGE_SIZE);
}
/**
* Create page iterator for a given org's events
*
* @param org
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageOrgEvents(String org, final int size) {
return pageOrgEvents(org, PAGE_FIRST, size);
}
/**
* Create page iterator for a given org's events
*
* @param org
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageOrgEvents(String org, final int start,
final int size) {
PagedRequest request = createOrgEventRequest(org, start, size);
return createPageIterator(request);
}
/**
* Create page iterator for a given user's received events Returns private
* events if authenticated as the user
*
* @param user
* @return events page iterator
*/
public PageIterator pageUserReceivedEvents(String user) {
return pageUserReceivedEvents(user, false);
}
/**
* Create page iterator for a given user's received events
*
* @param user
* @param isPublic
* only include public events?
* @return events page iterator
*/
public PageIterator pageUserReceivedEvents(String user,
boolean isPublic) {
return pageUserReceivedEvents(user, isPublic, PAGE_SIZE);
}
/**
* Create page iterator for a given user's received events
*
* @param user
* @param isPublic
* only include public events?
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageUserReceivedEvents(String user,
boolean isPublic, final int size) {
return pageUserReceivedEvents(user, isPublic, PAGE_FIRST, size);
}
/**
* Create page iterator for a given user's received events
*
* @param user
* @param isPublic
* only include public events?
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageUserReceivedEvents(String user,
boolean isPublic, final int start, final int size) {
PagedRequest request = createUserReceivedEventRequest(user,
isPublic, start, size);
return createPageIterator(request);
}
/**
* Create page iterator for a given user's events Returns private events if
* authenticated as the user
*
* @param user
* @return events page iterator
*/
public PageIterator pageUserEvents(String user) {
return pageUserEvents(user, false);
}
/**
* Create page iterator for a given user's events
*
* @param user
* @param isPublic
* only include public events?
* @return events page iterator
*/
public PageIterator pageUserEvents(String user, boolean isPublic) {
return pageUserEvents(user, isPublic, PAGE_SIZE);
}
/**
* Create page iterator for a given user's events
*
* @param user
* @param isPublic
* only include public events?
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageUserEvents(String user, boolean isPublic,
final int size) {
return pageUserEvents(user, isPublic, PAGE_FIRST, size);
}
/**
* Create page iterator for a given user's events
*
* @param user
* @param isPublic
* only include public events?
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageUserEvents(String user, boolean isPublic,
final int start, final int size) {
PagedRequest request = createUserEventRequest(user, isPublic,
start, size);
return createPageIterator(request);
}
/**
* Create page iterator for a given user's orgs events
*
* @param user
* @param org
* @return events page iterator
*/
public PageIterator pageUserOrgEvents(String user, String org) {
return pageUserOrgEvents(user, org, PAGE_SIZE);
}
/**
* Create page iterator for a given user's orgs events
*
* @param user
* @param org
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageUserOrgEvents(String user, String org,
final int size) {
return pageUserOrgEvents(user, org, PAGE_FIRST, size);
}
/**
* Create page iterator for a given user's orgs events
*
* @param user
* @param org
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
public PageIterator pageUserOrgEvents(String user, String org,
final int start, final int size) {
PagedRequest request = createUserOrgEventRequest(user, org,
start, size);
return createPageIterator(request);
}
/**
* Create repo event page request
*
* @param repository
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
protected PagedRequest createRepoEventRequest(
IRepositoryIdProvider repository, int start, int size) {
final String repoId = getId(repository);
StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
uri.append(SEGMENT_EVENTS);
PagedRequest request = createPagedRequest(start, size);
request.setUri(uri).setType(new TypeToken>() {
}.getType());
return request;
}
/**
* Create network repo event page request
*
* @param repository
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
protected PagedRequest createNetworkRepoEventRequest(
IRepositoryIdProvider repository, int start, int size) {
final String repoId = getId(repository);
StringBuilder uri = new StringBuilder(SEGMENT_NETWORKS);
uri.append('/').append(repoId);
uri.append(SEGMENT_EVENTS);
PagedRequest request = createPagedRequest(start, size);
request.setUri(uri).setType(new TypeToken>() {
}.getType());
return request;
}
/**
* Create org event page request
*
* @param org
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
protected PagedRequest createOrgEventRequest(String org, int start,
int size) {
StringBuilder uri = new StringBuilder(SEGMENT_ORGS);
uri.append('/').append(org);
uri.append(SEGMENT_EVENTS);
PagedRequest request = createPagedRequest(start, size);
request.setUri(uri).setType(new TypeToken>() {
}.getType());
return request;
}
/**
* Create user received event page request
*
* @param user
* @param isPublic
* only include public events?
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
protected PagedRequest createUserReceivedEventRequest(String user,
boolean isPublic, int start, int size) {
StringBuilder uri = new StringBuilder(SEGMENT_USERS);
uri.append('/').append(user);
uri.append(SEGMENT_RECEIVED_EVENTS);
if (isPublic)
uri.append(SEGMENT_PUBLIC);
PagedRequest request = createPagedRequest(start, size);
request.setUri(uri).setType(new TypeToken>() {
}.getType());
return request;
}
/**
* Create user event page request
*
* @param user
* @param isPublic
* only include public events?
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
protected PagedRequest createUserEventRequest(String user,
boolean isPublic, int start, int size) {
StringBuilder uri = new StringBuilder(SEGMENT_USERS);
uri.append('/').append(user);
uri.append(SEGMENT_EVENTS);
if (isPublic)
uri.append(SEGMENT_PUBLIC);
PagedRequest request = createPagedRequest(start, size);
request.setUri(uri).setType(new TypeToken>() {
}.getType());
return request;
}
/**
* Create user's organization event page request
*
* @param user
* @param org
* @param start
* starting page number
* @param size
* size of page
* @return events page iterator
*/
protected PagedRequest createUserOrgEventRequest(String user,
String org, int start, int size) {
StringBuilder uri = new StringBuilder(SEGMENT_USERS);
uri.append('/').append(user);
uri.append(SEGMENT_EVENTS).append(SEGMENT_ORGS);
uri.append('/').append(org);
PagedRequest request = createPagedRequest(start, size);
request.setUri(uri).setType(new TypeToken>() {
}.getType());
return request;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy