commit
357d483e3f
|
@ -58,12 +58,7 @@ public class RedditController {
|
||||||
|
|
||||||
Map<String, String> param = new HashMap<String, String>();
|
Map<String, String> param = new HashMap<String, String>();
|
||||||
param.put("api_type", "json");
|
param.put("api_type", "json");
|
||||||
param.put("kind", "self");
|
param.put("kind", "link");
|
||||||
param.put("sr", "api");
|
|
||||||
// param.put("iden", "XCzyTdJveIcYXNhLJ4a2X9WVDswtx83u");
|
|
||||||
// param.put("captcha", "BJMGMU");
|
|
||||||
// param.put("title", "http2 is coming soon");
|
|
||||||
// param.put("text", "http2 is coming soon what do you think about that");
|
|
||||||
param.putAll(formParams);
|
param.putAll(formParams);
|
||||||
|
|
||||||
System.out.println(param.keySet());
|
System.out.println(param.keySet());
|
||||||
|
@ -83,6 +78,10 @@ public class RedditController {
|
||||||
|
|
||||||
@RequestMapping("/post")
|
@RequestMapping("/post")
|
||||||
public String showSubmissionForm(Model model) throws JsonProcessingException, IOException {
|
public String showSubmissionForm(Model model) throws JsonProcessingException, IOException {
|
||||||
|
try {
|
||||||
|
List<String> subreddits = getSubreddit();
|
||||||
|
model.addAttribute("subreddits", subreddits);
|
||||||
|
|
||||||
String needsCaptchaResult = needsCaptcha();
|
String needsCaptchaResult = needsCaptcha();
|
||||||
if (needsCaptchaResult.equalsIgnoreCase("true")) {
|
if (needsCaptchaResult.equalsIgnoreCase("true")) {
|
||||||
String newCaptchaResult = getNewCaptcha();
|
String newCaptchaResult = getNewCaptcha();
|
||||||
|
@ -90,13 +89,22 @@ public class RedditController {
|
||||||
String iden = split[split.length - 2];
|
String iden = split[split.length - 2];
|
||||||
model.addAttribute("iden", iden.trim());
|
model.addAttribute("iden", iden.trim());
|
||||||
}
|
}
|
||||||
|
} catch (UserApprovalRequiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (UserRedirectRequiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Error occurred", e);
|
||||||
|
model.addAttribute("error", e.getLocalizedMessage());
|
||||||
|
return "reddit";
|
||||||
|
}
|
||||||
return "submissionForm";
|
return "submissionForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
public List<String> getSubreddit(Model model) throws JsonProcessingException, IOException {
|
private List<String> getSubreddit() throws JsonProcessingException, IOException {
|
||||||
String result = redditRestTemplate.getForObject("https://oauth.reddit.com/subreddits/popular", String.class);
|
String result = redditRestTemplate.getForObject("https://oauth.reddit.com/subreddits/popular?limit=50", String.class);
|
||||||
JsonNode node = new ObjectMapper().readTree(result);
|
JsonNode node = new ObjectMapper().readTree(result);
|
||||||
node = node.get("data").get("children");
|
node = node.get("data").get("children");
|
||||||
List<String> subreddits = new ArrayList<String>();
|
List<String> subreddits = new ArrayList<String>();
|
||||||
|
@ -106,12 +114,12 @@ public class RedditController {
|
||||||
return subreddits;
|
return subreddits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String needsCaptcha() {
|
private String needsCaptcha() {
|
||||||
String result = redditRestTemplate.getForObject("https://oauth.reddit.com/api/needs_captcha.json", String.class);
|
String result = redditRestTemplate.getForObject("https://oauth.reddit.com/api/needs_captcha.json", String.class);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNewCaptcha() {
|
private String getNewCaptcha() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
HttpEntity req = new HttpEntity(headers);
|
HttpEntity req = new HttpEntity(headers);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<c:when test="${info != null}">
|
<c:when test="${info != null}">
|
||||||
<h1>Your Reddit Info</h1>
|
<h1>Your Reddit Info</h1>
|
||||||
<b>Your reddit username is </b>${info}
|
<b>Your reddit username is </b>${info}
|
||||||
<br>
|
<br><br><br>
|
||||||
<a href="post">Submit to Reddit</a>
|
<a href="post">Submit to Reddit</a>
|
||||||
</c:when>
|
</c:when>
|
||||||
<c:otherwise>
|
<c:otherwise>
|
||||||
|
|
|
@ -17,10 +17,22 @@
|
||||||
</div>
|
</div>
|
||||||
<br><br>
|
<br><br>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-3">Content</label>
|
<label class="col-sm-3">Url</label>
|
||||||
<span class="col-sm-9"><textarea placeholder="content" class="form-control"></textarea></span>
|
<span class="col-sm-9"><input name="url" placeholder="url" class="form-control" /></span>
|
||||||
</div>
|
</div>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-3">Subreddit</label>
|
||||||
|
<span class="col-sm-9">
|
||||||
|
<select name="sr">
|
||||||
|
<c:forEach items="${subreddits}" var="item">
|
||||||
|
<option value="${item}">${item}</option>
|
||||||
|
</c:forEach>
|
||||||
|
</select>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<br><br>
|
||||||
|
|
||||||
<c:if test="${iden != null}">
|
<c:if test="${iden != null}">
|
||||||
<input type="hidden" name="iden" value="${iden}"/>
|
<input type="hidden" name="iden" value="${iden}"/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue