/
me_boards_suggested_controller.go
53 lines (46 loc) · 1.5 KB
/
me_boards_suggested_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package controllers
import (
"github.com/BrandonRomano/wrecker"
"github.com/carrot/go-pinterest/models"
"strconv"
)
// MeBoardsSuggestedController is the controller that is responsible for all
// /v1/me/boards/suggested/ endpoints in the Pinterest API.
type MeBoardsSuggestedController struct {
wreckerClient *wrecker.Wrecker
}
// newMeBoardsSuggestedController instantiates a new MeBoardsSuggestedController
func newMeBoardsSuggestedController(wc *wrecker.Wrecker) *MeBoardsSuggestedController {
return &MeBoardsSuggestedController{
wreckerClient: wc,
}
}
// MeBoardsSuggestedFetchOptionals is a struct that represents the optional
// parameters for the Fetch method
type MeBoardsSuggestedFetchOptionals struct {
Count int32
Pin string
}
// Fetch loads board suggestions for the logged in user
// Endpoint: [GET] /v1/me/boards/suggested/
func (mbsc *MeBoardsSuggestedController) Fetch(optionals *MeBoardsSuggestedFetchOptionals) (*[]models.Board, error) {
// Build + execute request
resp := new(models.Response)
resp.Data = &[]models.Board{}
request := mbsc.wreckerClient.Get("/me/boards/suggested/").
URLParam("fields", models.BOARD_FIELDS).
Into(resp)
if optionals.Count != 0 {
request.URLParam("count", strconv.Itoa(int(optionals.Count)))
}
if optionals.Pin != "" {
request.URLParam("pin", optionals.Pin)
}
httpResp, err := request.Execute()
// Check Error
if err = models.WrapPinterestError(httpResp, resp, err); err != nil {
return nil, err
}
// OK
return resp.Data.(*[]models.Board), nil
}