package com.poprosturonin.sites.ninegag;

import com.poprosturonin.data.Page;
import com.poprosturonin.exceptions.PageIsEmptyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * The coding love
 */
@RestController
@RequestMapping(value = "/9gagnsfw")
public class NinegagNSFWController {
    final static String ROOT_URL = "http://9gag.com/nsfw";
    final static String ID_URL_PART = "?id=";

    @Autowired
    private NinegagNSFWPageScrapper ninegagNSFWPageScrapper;

    @RequestMapping(value = "")
    @ResponseBody
    public Page readerPage() {
        return ninegagNSFWPageScrapper.scrapPage(ROOT_URL);
    }

    @RequestMapping(value = "/page/{id}")
    @ResponseBody
    public Page readerPage(@PathVariable String id) {
        if (id.length() <= 4) //There is no 9gag id that has 4 letters
            throw new PageIsEmptyException();

        return ninegagNSFWPageScrapper.scrapPage(ROOT_URL + ID_URL_PART + id);
    }
}

@@ -598,16 +598,17 @@
  = %22http
+s
 ://9gag.
@@ -611,20 +611,50 @@
 gag.com/
-nsfw
+v1/group-posts/group/nsfw/type/hot
 %22;%0A    f
@@ -688,18 +688,26 @@
 ART = %22?
-id
+c=10&after
 =%22;%0A%0A   

Add not see fork woman back, close #5