Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds methods to GHRepository to get the top ten referral paths and referrers via the API #1770

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,38 @@ public void unstar() throws IOException {
root().createRequest().method("DELETE").withUrlPath(String.format("/user/starred/%s", full_name)).send();
}

/**
* Get the top 10 popular contents over the last 14 days.
*
* @return list of top referral paths
* @throws IOException
* the io exception
* @link https://docs.github.com/en/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-paths
*/
public List<GHRepositoryTrafficTopReferralPath> getTopReferralPaths() throws IOException {
return root().createRequest()
.method("GET")
.withUrlPath("/repos/%s/%s/traffic/popular/paths", getOwnerName(), name)
.toIterable(GHRepositoryTrafficTopReferralPath[].class, null)
.toList();
}

/**
* Get the top 10 referrers over the last 14 days.
*
* @return list of top referrers
* @throws IOException
* the io exception
* @link https://docs.github.com/en/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-sources
*/
public List<GHRepositoryTrafficTopReferralSources> getTopReferralSources() throws IOException {
return root().createRequest()
.method("GET")
.withUrlPath("/repos/%s/%s/traffic/popular/referrers", getOwnerName(), name)
.toIterable(GHRepositoryTrafficTopReferralSources[].class, null)
.toList();
}

/**
* A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.kohsuke.github;

/**
* Base class for traffic referral objects.
*/
public class GHRepositoryTrafficReferralBase {
private int count;
private int uniques;

/**
* Instantiates a new Gh repository traffic referral base.
*/
GHRepositoryTrafficReferralBase() {
}

/**
* Instantiates a new Gh repository traffic referral base.
*
* @param count
* the count
* @param uniques
* the uniques
*/
GHRepositoryTrafficReferralBase(int count, int uniques) {
this.count = count;
this.uniques = uniques;
}

/**
* Gets count.
*
* @return the count
*/
public int getCount() {
return this.count;
}

/**
* Gets uniques.
*
* @return the uniques
*/
public int getUniques() {
return this.uniques;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.kohsuke.github;

/**
* Top referral path object.
*/
public class GHRepositoryTrafficTopReferralPath extends GHRepositoryTrafficReferralBase {
private String path;
private String title;

/**
* Instantiates a new Gh repository traffic top referral path.
*/
GHRepositoryTrafficTopReferralPath() {
}

/**
* Instantiates a new Gh repository traffic top referral path.
*
* @param count
* the count
* @param uniques
* the uniques
* @param path
* the path
* @param title
* the title
*/
GHRepositoryTrafficTopReferralPath(int count, int uniques, String path, String title) {
super(count, uniques);
this.path = path;
this.title = title;
}

/**
* Gets path.
*
* @return the path
*/
public String getPath() {
return this.path;
}

/**
* Gets title.
*
* @return the title
*/
public String getTitle() {
return this.title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.kohsuke.github;

/**
* Top referral source object.
*/
public class GHRepositoryTrafficTopReferralSources extends GHRepositoryTrafficReferralBase {
private String referrer;

/**
* Instantiates a new Gh repository traffic top referral sources.
*/
GHRepositoryTrafficTopReferralSources() {
}

/**
* Instantiates a new Gh repository traffic top referral sources.
*
* @param count
* the count
* @param uniques
* the uniques
* @param referrer
* the referrer
*/
GHRepositoryTrafficTopReferralSources(int count, int uniques, String referrer) {
super(count, uniques);
this.referrer = referrer;
}

/**
* Gets referrer.
*
* @return the referrer
*/
public String getReferrer() {
return this.referrer;
}
}