diff --git a/api.go b/api.go index 0e63616..e5e7a27 100644 --- a/api.go +++ b/api.go @@ -6,7 +6,6 @@ import ( "time" "github.com/rubiojr/omnivore-go/queries" - "github.com/rubiojr/omnivore-go/types" "github.com/shurcooL/graphql" ) @@ -31,6 +30,17 @@ type Opts struct { Token string } +type Label struct { + Name string + Color string + Description string + CreatedAt time.Time + ID graphql.ID + Source string + Internal bool + Position int +} + type Subscription struct { AutoAddToLibrary bool Count int @@ -73,7 +83,7 @@ type SearchItem struct { Words int FeedContent string Folder string - Labels []types.Label + Labels []Label } type SearchOpts struct { @@ -97,6 +107,10 @@ func NewClient(opts Opts) *Omnivore { } func NewClientFor(url string, opts Opts) *Omnivore { + if opts.Token == "" { + panic("token is missing") + } + httpClient := &http.Client{ Transport: &headerTransport{ Token: opts.Token, @@ -146,9 +160,9 @@ func (c *Omnivore) Search(opts SearchOpts) ([]SearchItem, error) { FeedContent: edge.Node.FeedContent, Folder: edge.Node.Folder, } - labels := []types.Label{} + labels := []Label{} for _, label := range edge.Node.Labels { - labels = append(labels, types.Label{ + labels = append(labels, Label{ Name: label.Name, Color: label.Color, Description: label.Description, @@ -250,8 +264,8 @@ func (a *ApiKey) HasExpiry() bool { return a.ExpiresAt != "+275760-09-13T00:00:00.000Z" } -func (c *Omnivore) Labels() ([]*types.Label, error) { - a := []*types.Label{} +func (c *Omnivore) Labels() ([]*Label, error) { + a := []*Label{} err := c.graphql.Query(context.Background(), &queries.Labels, nil) if err != nil { @@ -260,7 +274,7 @@ func (c *Omnivore) Labels() ([]*types.Label, error) { result := queries.Labels.Labels.LabelsSuccess for _, label := range result.Labels { - a = append(a, &types.Label{ + a = append(a, &Label{ ID: label.ID, Name: label.Name, Color: label.Color, diff --git a/types/label.go b/types/label.go deleted file mode 100644 index 5b1b802..0000000 --- a/types/label.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -import ( - "time" - - "github.com/shurcooL/graphql" -) - -type Label struct { - Name string - Color string - Description string - CreatedAt time.Time - ID graphql.ID - Source string - Internal bool - Position int -}