-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added GithubUtils and controller method to retrieve recent events for…
… a repository
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/skiwi/githubhooksechatservice/jackson/MessageTypeIdResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.skiwi.githubhooksechatservice.jackson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
|
||
public class MessageTypeIdResolver implements TypeIdResolver { | ||
|
||
private JavaType mBaseType; | ||
|
||
@Override | ||
public void init(JavaType baseType) { | ||
mBaseType = baseType; | ||
} | ||
|
||
@Override | ||
public Id getMechanism() { | ||
return Id.CUSTOM; | ||
} | ||
|
||
@Override | ||
public String idFromValue(Object obj) { | ||
return idFromValueAndType(obj, obj.getClass()); | ||
} | ||
|
||
@Override | ||
public String idFromBaseType() { | ||
throw new AssertionError("this should never happen"); | ||
} | ||
|
||
@Override | ||
public String idFromValueAndType(Object obj, Class<?> clazz) { | ||
return clazz.getSimpleName();// AnySetterJSONObject mess = (AnySetterJSONObject) obj; | ||
// return mess.getCommand(); | ||
} | ||
|
||
@Override | ||
public JavaType typeFromId(String type) { | ||
Class<?> clazz; | ||
try { | ||
clazz = Class.forName("com.skiwi.githubhooksechatservice.events.github." + type); | ||
} catch (ClassNotFoundException e) { | ||
throw new UnsupportedOperationException("No such defined type: " + type); | ||
} | ||
return TypeFactory.defaultInstance().constructSpecializedType(mBaseType, clazz); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/skiwi/githubhooksechatservice/mvc/beans/GithubUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.skiwi.githubhooksechatservice.mvc.beans; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.skiwi.githubhooksechatservice.events.AnySetterJSONObject; | ||
|
||
public class GithubUtils { | ||
|
||
|
||
|
||
public AnySetterJSONObject[] data(String name, String repository) { | ||
ObjectMapper mapper = new ObjectMapper(); // just need one | ||
try { | ||
URL url = new URL("https://api.github.com/repos/" + name + "/" + repository + "/events"); | ||
AnySetterJSONObject[] data = mapper.readValue(url, AnySetterJSONObject[].class); | ||
return data; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters