package pinterest;

import com.google.gson.Gson;
import exceptions.PinterestException;
import fields.PinFields;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.utils.URIBuilder;
import responses.Pin;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class Pinterest {
    private static final String PROTOCOL = "https";
    private static final String HOST = "api.pinterest.com";
    private static final String PIN_PATH = "/v1/pins/{PIN_ID}/";

    private final String accessToken;

    public Pinterest(String accessToken) {
        this.accessToken = accessToken;
    }

    public Pin getPin(final String id) {
        try {
            return new Gson().fromJson(IOUtils.toString(buildPinUri(id, PinFields.defaultFields())), Pin.class);
        } catch (URISyntaxException | IOException e) {
            throw new PinterestException(e.getMessage(), e);
        }
    }

    public Pin getPin(final String id, final PinFields pinFields) {
        try {
            return new Gson().fromJson(IOUtils.toString(buildPinUri(id, pinFields.build())), Pin.class);
        } catch (URISyntaxException | IOException e) {
            throw new PinterestException(e.getMessage(), e);
        }
    }

    private URI buildPinUri(final String id, final String fields) throws URISyntaxException {
        return new URIBuilder()
                .setScheme(PROTOCOL)
                .setHost(HOST)
                .setPath(PIN_PATH.replace("{PIN_ID}", id))
                .setParameter("access_token", accessToken)
                .setParameter("fields", fields)
                .build();
    }
}

@@ -212,16 +212,39 @@
 ses.Pin;
+%0Aimport responses.Pins;
 %0A%0Aimport
@@ -524,16 +524,94 @@
 N_ID%7D/%22;
+%0A    private static final String BOARD_PATH = %22/v1/boards/%7BBOARD_NAME%7D/pins/%22;
 %0A%0A    pr
@@ -740,35 +740,40 @@
 %0A    public Pin 
-g
+r
 et
+rieve
 Pin(final String
@@ -1054,19 +1054,24 @@
 lic Pin 
-g
+r
 et
+rieve
 Pin(fina
@@ -1373,253 +1373,1345 @@
    p
-rivate URI buildPinUri(final String id, final String fields) throws URISyntaxException %7B%0A        return new URIBuilder()%0A                .setScheme(PROTOCOL)%0A                .setHost(HOST)%0A                .setPath(PIN_PATH.replace(%22%7BPIN_ID%7D%22, id
+ublic Pins retrievePinsFromBoard(final String boardName) %7B%0A        try %7B%0A            return new Gson().fromJson(IOUtils.toString(buildBoardUri(boardName, PinFields.defaultFields())), Pins.class);%0A        %7D catch (URISyntaxException %7C IOException e) %7B%0A            throw new PinterestException(e.getMessage(), e);%0A        %7D%0A    %7D%0A%0A    public Pins retrievePinsFromBoard(final String boardName, final PinFields pinFields) %7B%0A        try %7B%0A            return new Gson().fromJson(IOUtils.toString(buildBoardUri(boardName, pinFields.build())), Pins.class);%0A        %7D catch (URISyntaxException %7C IOException e) %7B%0A            throw new PinterestException(e.getMessage(), e);%0A        %7D%0A    %7D%0A%0A    private URI buildPinUri(final String id, final String fields) throws URISyntaxException %7B%0A        return new URIBuilder()%0A                .setScheme(PROTOCOL)%0A                .setHost(HOST)%0A                .setPath(PIN_PATH.replace(%22%7BPIN_ID%7D%22, id))%0A                .setParameter(%22access_token%22, accessToken)%0A                .setParameter(%22fields%22, fields)%0A                .build();%0A    %7D%0A%0A    private URI buildBoardUri(final String name, final String fields) throws URISyntaxException %7B%0A        return new URIBuilder()%0A                .setScheme(PROTOCOL)%0A                .setHost(HOST)%0A                .setPath(BOARD_PATH.replace(%22%7BBOARD_NAME%7D%22, name
 ))%0A 

Add methods for Boards