forked from a-frony/go-pinterest
/
me_pins_controller.go
48 lines (41 loc) · 1.28 KB
/
me_pins_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
package controllers
import (
"github.com/BrandonRomano/wrecker"
"github.com/carrot/go-pinterest/models"
)
// MePinsController is the controller that is responsible for all
// /v1/me/pins/ endpoints in the Pinterest API.
type MePinsController struct {
wreckerClient *wrecker.Wrecker
}
// newMePinsController instantiates a new MePinsController
func newMePinsController(wc *wrecker.Wrecker) *MePinsController {
return &MePinsController{
wreckerClient: wc,
}
}
// MePinsFetchOptionals is a struct that represents the optional parameters
// that can be passed to the Fetch endpoint
type MePinsFetchOptionals struct {
Cursor string
}
// Fetch loads all of the logged in user's Pins
// Endpoint: [GET] /v1/me/pins/
func (mpc *MePinsController) Fetch(optionals *MePinsFetchOptionals) (*[]models.Pin, *models.Page, error) {
// Build + execute request
resp := new(models.Response)
resp.Data = &[]models.Pin{}
request := mpc.wreckerClient.Get("/me/pins/").
URLParam("fields", models.PIN_FIELDS).
Into(resp)
if optionals.Cursor != "" {
request.URLParam("cursor", optionals.Cursor)
}
httpResp, err := request.Execute()
// Check Error
if err = models.WrapPinterestError(httpResp, resp, err); err != nil {
return nil, nil, err
}
// OK
return resp.Data.(*[]models.Pin), &resp.Page, nil
}