2424@ Controller
2525public class RedditController {
2626
27- private final Logger LOGGER = LoggerFactory .getLogger (getClass ());
27+ private final Logger logger = LoggerFactory .getLogger (getClass ());
2828
2929 @ Autowired
3030 private OAuth2RestTemplate redditRestTemplate ;
@@ -33,73 +33,71 @@ public class RedditController {
3333
3434 @ RequestMapping ("/info" )
3535 public final String getInfo (Model model ) {
36- JsonNode node = redditRestTemplate .getForObject ("https://oauth.reddit.com/api/v1/me" , JsonNode .class );
37- String name = node .get ("name" ).asText ();
36+ final JsonNode node = redditRestTemplate .getForObject ("https://oauth.reddit.com/api/v1/me" , JsonNode .class );
37+ final String name = node .get ("name" ).asText ();
3838 model .addAttribute ("info" , name );
3939 return "reddit" ;
4040 }
4141
4242 @ RequestMapping ("/submit" )
4343 public final String submit (Model model , @ RequestParam Map <String , String > formParams ) {
44- MultiValueMap <String , String > param = new LinkedMultiValueMap <String , String >();
44+ final MultiValueMap <String , String > param = new LinkedMultiValueMap <String , String >();
4545 param .add ("api_type" , "json" );
4646 param .add ("kind" , "link" );
4747 param .add ("resubmit" , "true" );
4848 param .add ("sendreplies" , "false" );
4949 param .add ("then" , "comments" );
50-
51- for (Map .Entry <String , String > entry : formParams .entrySet ()) {
50+ for (final Map .Entry <String , String > entry : formParams .entrySet ()) {
5251 param .add (entry .getKey (), entry .getValue ());
5352 }
5453
55- LOGGER .info ("User submitting Link with these parameters: " + formParams .entrySet ());
54+ logger .info ("User submitting Link with these parameters: " + formParams .entrySet ());
5655 JsonNode node = redditRestTemplate .postForObject ("https://oauth.reddit.com/api/submit" , param , JsonNode .class );
57- LOGGER .info ("Full Reddit Response: " + node .toString ());
56+ logger .info ("Full Reddit Response: " + node .toString ());
5857 String responseMsg = parseResponse (node );
5958 model .addAttribute ("msg" , responseMsg );
6059 return "submissionResponse" ;
6160 }
6261
6362 @ RequestMapping ("/post" )
64- public final String showSubmissionForm (Model model ) {
65- String needsCaptchaResult = needsCaptcha ();
63+ public final String showSubmissionForm (final Model model ) {
64+ final String needsCaptchaResult = needsCaptcha ();
6665 if (needsCaptchaResult .equalsIgnoreCase ("true" )) {
67- String iden = getNewCaptcha ();
66+ final String iden = getNewCaptcha ();
6867 model .addAttribute ("iden" , iden );
6968 }
7069 return "submissionForm" ;
7170 }
7271
7372 // === private
7473
75- List <String > getSubreddit () throws JsonProcessingException , IOException {
76- String result = redditRestTemplate .getForObject ("https://oauth.reddit.com/subreddits/popular?limit=50" , String .class );
77- JsonNode node = new ObjectMapper ().readTree (result );
78- node = node .get ("data" ).get ("children" );
79- List <String > subreddits = new ArrayList <String >();
74+ final List <String > getSubreddit () throws JsonProcessingException , IOException {
75+ final String result = redditRestTemplate .getForObject ("https://oauth.reddit.com/subreddits/popular?limit=50" , String .class );
76+ final JsonNode node = new ObjectMapper ().readTree (result ).get ("data" ).get ("children" );
77+ final List <String > subreddits = new ArrayList <String >();
8078 for (JsonNode child : node ) {
8179 subreddits .add (child .get ("data" ).get ("display_name" ).asText ());
8280 }
8381 return subreddits ;
8482 }
8583
86- private String needsCaptcha () {
84+ private final String needsCaptcha () {
8785 String result = redditRestTemplate .getForObject ("https://oauth.reddit.com/api/needs_captcha.json" , String .class );
8886 return result ;
8987 }
9088
91- private String getNewCaptcha () {
92- Map <String , String > param = new HashMap <String , String >();
89+ private final String getNewCaptcha () {
90+ final Map <String , String > param = new HashMap <String , String >();
9391 param .put ("api_type" , "json" );
9492
95- String result = redditRestTemplate .postForObject ("https://oauth.reddit.com/api/new_captcha" , param , String .class , param );
96- String [] split = result .split ("\" " );
93+ final String result = redditRestTemplate .postForObject ("https://oauth.reddit.com/api/new_captcha" , param , String .class , param );
94+ final String [] split = result .split ("\" " );
9795 return split [split .length - 2 ];
9896 }
9997
100- private String parseResponse (JsonNode node ) {
98+ private final String parseResponse (final JsonNode node ) {
10199 String result = "" ;
102- JsonNode errorNode = node .get ("json" ).get ("errors" ).get (0 );
100+ final JsonNode errorNode = node .get ("json" ).get ("errors" ).get (0 );
103101 if (errorNode != null ) {
104102 for (JsonNode child : errorNode ) {
105103 result = result + child .toString ().replaceAll ("\" |null" , "" ) + "<br>" ;
0 commit comments