-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.go
93 lines (81 loc) · 2 KB
/
input.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package go_pocket_sdk
import (
"strings"
)
// AddInput contains the data needed to create an item in the Pocket list
type AddInput struct {
AccessToken string
URL string
Title string
Tags []string
TweetID string
}
// ModifyInput contains the data needed to modify items in the Pocket list
type ModifyInput struct {
AccessToken string
Actions []Action
}
// RetrievingInput contains the data needed to retrieve items from the Pocket list
type RetrievingInput struct {
AccessToken string
State string
Favorite string
Tag string
ContentType string
Sort string
DetailType string
Search string
Domain string
Since int64
Count int
Offset int
}
func (i AddInput) generateRequest(consumerKey string) (requestAdd, error) {
if i.AccessToken == "" {
return requestAdd{}, ErrEmptyAccessToken
}
if i.URL == "" {
return requestAdd{}, ErrEmptyItemURL
}
return requestAdd{
ConsumerKey: consumerKey,
AccessToken: i.AccessToken,
URL: i.URL,
Title: i.Title,
Tags: strings.Join(i.Tags, ", "),
TweetID: i.TweetID,
}, nil
}
func (i ModifyInput) generateRequest(consumerKey string) (requestModify, error) {
if i.AccessToken == "" {
return requestModify{}, ErrEmptyAccessToken
}
if len(i.Actions) == 0 {
return requestModify{}, ErrNoActions
}
return requestModify{
ConsumerKey: consumerKey,
AccessToken: i.AccessToken,
Actions: i.Actions,
}, nil
}
func (i RetrievingInput) generateRequest(consumerKey string) (requestRetrieving, error) {
if i.AccessToken == "" {
return requestRetrieving{}, ErrEmptyAccessToken
}
return requestRetrieving{
ConsumerKey: consumerKey,
AccessToken: i.AccessToken,
State: i.State,
Favorite: i.Favorite,
Tag: i.Tag,
ContentType: i.ContentType,
Sort: i.Sort,
DetailType: i.DetailType,
Search: i.Search,
Domain: i.Domain,
Since: i.Since,
Count: i.Count,
Offset: i.Offset,
}, nil
}