-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckin.go
76 lines (63 loc) · 2.18 KB
/
checkin.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package trakt
import (
"encoding/json"
"strings"
"time"
)
// StartCheckinParams parameters in order to start a checkin
// operation. The only required values are Type, Element and an
// OAuth token.
type StartCheckinParams struct {
Params
// Type the type of media element. Can either be TypeMovie or TypeEpisode.
Type Type `json:"-"`
// Element the actual element data. We can provide as much or as little as
// we want about the item. The recommended values are either the trakt ID or slug.
Element *GenericElementParams `json:"-"`
// Message used for sharing. If not sent, it will use the watching string in the user settings.
Message string `json:"message,omitempty"`
// Foursquare venue ID. Optional.
VenueID string `json:"venue_id,omitempty"`
// Foursquare venue name. Optional.
VenueName string `json:"venue_name,omitempty"`
// Version number of the app. Optional.
AppVersion string `json:"app_version,omitempty"`
// Build date of the app. Optional.
AppDate string `json:"app_date,omitempty"`
// The sharing object is optional and will apply the user's settings if not sent.
// If sharing is sent, each key will override the user's setting for that social network.
// Send true to post or false to not post on the indicated social network. You can see which
// social networks a user has connected with the /users/settings method.
Sharing *SharingParams `json:"sharing,omitempty"`
}
// MarshalJSON implements Marshaller interface.
func (s *StartCheckinParams) MarshalJSON() ([]byte, error) {
m := marshalToMap(s)
m[strings.ToLower(string(s.Type))] = s.Element
return json.Marshal(m)
}
// Checkin represents a manual checkin entry.
type Checkin struct {
basePlaybackItem
// WatchedAt when the user started watching this item.
WatchedAt time.Time `json:"watched_at"`
}
// UnmarshalJSON implements Unmarshaller interface.
// allows us to determine the type of entry it is
// from the data retrieved.
func (c *Checkin) UnmarshalJSON(bytes []byte) error {
type A Checkin
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return err
}
switch {
case a.Episode != nil:
a.Type = TypeEpisode
case a.Movie != nil:
a.Type = TypeMovie
}
*c = Checkin(*a)
return nil
}