Skip to content

Commit

Permalink
Nest controllers (#19)
Browse files Browse the repository at this point in the history
This is the approach at organizing controllers I have decided on.  This
will match the URL structure that is provided from the Pinterest API and
will feel more fluent than the previous approach I was taking.
  • Loading branch information
BrandonRomano committed Dec 15, 2016
1 parent 7437e04 commit afd79ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 0 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
type Client struct {
Users *controllers.UsersController
Boards *controllers.BoardsController
BoardPins *controllers.BoardPinsController
Pins *controllers.PinsController
wreckerClient *wrecker.Wrecker
}
Expand All @@ -39,7 +38,6 @@ func NewClient() *Client {
}
pinterestClient.Users = controllers.NewUsersController(pinterestClient.wreckerClient)
pinterestClient.Boards = controllers.NewBoardsController(pinterestClient.wreckerClient)
pinterestClient.BoardPins = controllers.NewBoardPinsController(pinterestClient.wreckerClient)
pinterestClient.Pins = controllers.NewPinsController(pinterestClient.wreckerClient)
return pinterestClient
}
Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (suite *ClientTestSuite) TestSuccessfulBoardCUD() {
// TestSuccessfulBoardPinsFetch tests that a boards pins can be
// fetched when everything was set up properly.
func (suite *ClientTestSuite) TestSuccessfulBoardPinsFetch() {
pins, err := suite.client.BoardPins.Fetch("BrandonRRomano/go-pinterest", &controllers.BoardPinsFetchOptionals{})
pins, err := suite.client.Boards.Pins.Fetch("BrandonRRomano/go-pinterest", &controllers.BoardPinsFetchOptionals{})

assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), len(*pins), 3)
Expand All @@ -394,7 +394,7 @@ func (suite *ClientTestSuite) TestSuccessfulBoardPinsFetch() {
// TestNotFoundBoardPinsFetch tests that a 404 is thrown
// when trying to access the pins of a board that does not exist
func (suite *ClientTestSuite) TestNotFoundBoardPinsFetch() {
_, err := suite.client.BoardPins.Fetch(
_, err := suite.client.Boards.Pins.Fetch(
"BrandonRRomano/E20450921CE",
&controllers.BoardPinsFetchOptionals{},
)
Expand All @@ -413,7 +413,7 @@ func (suite *ClientTestSuite) TestNotFoundBoardPinsFetch() {
// TestTimeoutBoardPinsFetch tests that an error is appropriately thrown
// when a network timeout occurs
func (suite *ClientTestSuite) TestTimeoutBoardPinsFetch() {
_, err := suite.timeoutClient.BoardPins.Fetch(
_, err := suite.timeoutClient.Boards.Pins.Fetch(
"BrandonRRomano/go-pinterest",
&controllers.BoardPinsFetchOptionals{},
)
Expand All @@ -423,7 +423,7 @@ func (suite *ClientTestSuite) TestTimeoutBoardPinsFetch() {
// TestUnauthorizedBoardPinsFetch tests that an error is appropriately thrown
// when the user makes an unauthorized request
func (suite *ClientTestSuite) TestUnauthorizedBoardPinsFetch() {
_, err := suite.unauthorizedClient.BoardPins.Fetch(
_, err := suite.unauthorizedClient.Boards.Pins.Fetch(
"BrandonRRomano/go-pinterest",
&controllers.BoardPinsFetchOptionals{},
)
Expand Down
5 changes: 4 additions & 1 deletion controllers/boards_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
// https://developers.pinterest.com/docs/api/boards/
type BoardsController struct {
wreckerClient *wrecker.Wrecker
Pins *BoardPinsController
}

// NewBoardsController instantiates a new BoardsController.
func NewBoardsController(wc *wrecker.Wrecker) *BoardsController {
return &BoardsController{
boardsController := &BoardsController{
wreckerClient: wc,
}
boardsController.Pins = NewBoardPinsController(wc)
return boardsController
}

// Fetch loads a board from the board_spec (username/board-slug)
Expand Down

0 comments on commit afd79ae

Please sign in to comment.