Bladeren bron

Move Golang API client here

Frédéric Guillot 7 jaren geleden
bovenliggende
commit
f43a055d63

+ 1 - 7
Gopkg.lock

@@ -41,12 +41,6 @@
   ]
   revision = "90697d60dd844d5ef6ff15135d0203f65d2f53b8"
 
-[[projects]]
-  branch = "master"
-  name = "github.com/miniflux/miniflux-go"
-  packages = ["."]
-  revision = "7b8d54a221db7b3e049f63e302ebbcc7d6a8d6be"
-
 [[projects]]
   name = "github.com/tdewolff/minify"
   packages = [
@@ -152,6 +146,6 @@
 [solve-meta]
   analyzer-name = "dep"
   analyzer-version = 1
-  inputs-digest = "62141ee1c8cb97033a8a89a45761f074ff9632cb57fe9e4440493ddfce0b083c"
+  inputs-digest = "bcdb45e8fd281e2a0b71ac72bfeba98a126cdbc8809da17e7e63394237105e32"
   solver-name = "gps-cdcl"
   solver-version = 1

+ 1 - 5
Gopkg.toml

@@ -21,7 +21,7 @@
 #  version = "2.4.0"
 
 [metadata.heroku]
-  root-package = "github.com/miniflux/miniflux"
+  root-package = "miniflux.app"
   go-version = "go1.10"
   ensure = "false"
 
@@ -37,10 +37,6 @@
   branch = "master"
   name = "github.com/lib/pq"
 
-[[constraint]]
-  branch = "master"
-  name = "github.com/miniflux/miniflux-go"
-
 [[constraint]]
   name = "github.com/tdewolff/minify"
   version = "2.3.5"

+ 50 - 0
client/README.md

@@ -0,0 +1,50 @@
+Miniflux API Client
+===================
+
+Client library for Miniflux REST API.
+
+Installation
+------------
+
+```bash
+go get -u miniflux.app/client
+```
+
+Example
+-------
+
+```go
+package main
+
+import (
+	"fmt"
+    "io/ioutil"
+
+	miniflux "miniflux.app/client"
+)
+
+func main() {
+    client := miniflux.New("https://api.example.org", "admin", "secret")
+
+    // Fetch all feeds.
+    feeds, err := client.Feeds()
+    if err != nil {
+        fmt.Println(err)
+        return
+    }
+    fmt.Println(feeds)
+
+    // Backup your feeds to an OPML file.
+    opml, err := client.Export()
+    if err != nil {
+        fmt.Println(err)
+        return
+    }
+
+    err = ioutil.WriteFile("opml.xml", opml, 0644)
+    if err != nil {
+        fmt.Println(err)
+        return
+    }
+}
+```

+ 5 - 5
vendor/github.com/miniflux/miniflux-go/client.go → client/client.go

@@ -1,8 +1,8 @@
-// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Copyright 2018 Frédéric Guillot. All rights reserved.
 // Use of this source code is governed by the MIT license
 // that can be found in the LICENSE file.
 
-package miniflux
+package client // import "miniflux.app/client"
 
 import (
 	"encoding/json"
@@ -13,7 +13,7 @@ import (
 	"strconv"
 )
 
-// Client represents a Miniflux client.
+// Client holds API procedure calls.
 type Client struct {
 	request *request
 }
@@ -448,8 +448,8 @@ func (c *Client) ToggleBookmark(entryID int64) error {
 	return nil
 }
 
-// NewClient returns a new Client.
-func NewClient(endpoint, username, password string) *Client {
+// New returns a new Miniflux client.
+func New(endpoint, username, password string) *Client {
 	return &Client{request: &request{endpoint: endpoint, username: username, password: password}}
 }
 

+ 2 - 2
vendor/github.com/miniflux/miniflux-go/miniflux.go → client/core.go

@@ -1,8 +1,8 @@
-// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Copyright 2018 Frédéric Guillot. All rights reserved.
 // Use of this source code is governed by the MIT license
 // that can be found in the LICENSE file.
 
-package miniflux
+package client // import "miniflux.app/client"
 
 import (
 	"fmt"

+ 35 - 0
client/doc.go

@@ -0,0 +1,35 @@
+// Copyright 2018 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the MIT license
+// that can be found in the LICENSE file.
+
+/*
+
+Package client implements a client library for the Miniflux REST API.
+
+Examples
+
+This code snippet fetch the list of users:
+
+	import (
+		miniflux "miniflux.app/client"
+	)
+
+	client := miniflux.New("https://api.example.org", "admin", "secret")
+	users, err := client.Users()
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	fmt.Println(users, err)
+
+This one discover subscriptions on a website:
+
+	subscriptions, err := client.Discover("https://example.org/")
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	fmt.Println(subscriptions)
+
+*/
+package client // import "miniflux.app/client"

+ 2 - 2
vendor/github.com/miniflux/miniflux-go/request.go → client/request.go

@@ -1,8 +1,8 @@
-// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Copyright 2018 Frédéric Guillot. All rights reserved.
 // Use of this source code is governed by the MIT license
 // that can be found in the LICENSE file.
 
-package miniflux
+package client // import "miniflux.app/client"
 
 import (
 	"bytes"

+ 36 - 36
integration_test.go

@@ -15,7 +15,7 @@ import (
 	"testing"
 	"time"
 
-	"github.com/miniflux/miniflux-go"
+	miniflux "miniflux.app/client"
 )
 
 const (
@@ -29,7 +29,7 @@ const (
 )
 
 func TestWithBadEndpoint(t *testing.T) {
-	client := miniflux.NewClient("bad url", testAdminUsername, testAdminPassword)
+	client := miniflux.New("bad url", testAdminUsername, testAdminPassword)
 	_, err := client.Users()
 	if err == nil {
 		t.Fatal(`Using a bad url should raise an error`)
@@ -37,7 +37,7 @@ func TestWithBadEndpoint(t *testing.T) {
 }
 
 func TestWithWrongCredentials(t *testing.T) {
-	client := miniflux.NewClient(testBaseURL, "invalid", "invalid")
+	client := miniflux.New(testBaseURL, "invalid", "invalid")
 	_, err := client.Users()
 	if err == nil {
 		t.Fatal(`Using bad credentials should raise an error`)
@@ -49,7 +49,7 @@ func TestWithWrongCredentials(t *testing.T) {
 }
 
 func TestGetCurrentLoggedUser(t *testing.T) {
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.Me()
 	if err != nil {
 		t.Fatal(err)
@@ -65,7 +65,7 @@ func TestGetCurrentLoggedUser(t *testing.T) {
 }
 
 func TestGetUsers(t *testing.T) {
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	users, err := client.Users()
 	if err != nil {
 		t.Fatal(err)
@@ -106,7 +106,7 @@ func TestGetUsers(t *testing.T) {
 
 func TestCreateStandardUser(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -147,7 +147,7 @@ func TestCreateStandardUser(t *testing.T) {
 
 func TestRemoveUser(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -160,7 +160,7 @@ func TestRemoveUser(t *testing.T) {
 
 func TestGetUserByID(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -211,7 +211,7 @@ func TestGetUserByID(t *testing.T) {
 
 func TestGetUserByUsername(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -262,7 +262,7 @@ func TestGetUserByUsername(t *testing.T) {
 
 func TestUpdateUserTheme(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -281,7 +281,7 @@ func TestUpdateUserTheme(t *testing.T) {
 
 func TestUpdateUserThemeWithInvalidValue(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -296,7 +296,7 @@ func TestUpdateUserThemeWithInvalidValue(t *testing.T) {
 
 func TestCannotCreateDuplicateUser(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	_, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
@@ -310,13 +310,13 @@ func TestCannotCreateDuplicateUser(t *testing.T) {
 
 func TestCannotListUsersAsNonAdmin(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	_, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	_, err = client.Users()
 	if err == nil {
 		t.Fatal(`Standard users should not be able to list any users`)
@@ -329,13 +329,13 @@ func TestCannotListUsersAsNonAdmin(t *testing.T) {
 
 func TestCannotGetUserAsNonAdmin(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	_, err = client.UserByID(user.ID)
 	if err == nil {
 		t.Fatal(`Standard users should not be able to get any users`)
@@ -348,13 +348,13 @@ func TestCannotGetUserAsNonAdmin(t *testing.T) {
 
 func TestCannotUpdateUserAsNonAdmin(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	_, err = client.UpdateUser(user.ID, &miniflux.UserModification{})
 	if err == nil {
 		t.Fatal(`Standard users should not be able to update any users`)
@@ -367,13 +367,13 @@ func TestCannotUpdateUserAsNonAdmin(t *testing.T) {
 
 func TestCannotCreateUserAsNonAdmin(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	_, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	_, err = client.CreateUser(username, testStandardPassword, false)
 	if err == nil {
 		t.Fatal(`Standard users should not be able to create users`)
@@ -386,13 +386,13 @@ func TestCannotCreateUserAsNonAdmin(t *testing.T) {
 
 func TestCannotDeleteUserAsNonAdmin(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	err = client.DeleteUser(user.ID)
 	if err == nil {
 		t.Fatal(`Standard users should not be able to remove any users`)
@@ -405,14 +405,14 @@ func TestCannotDeleteUserAsNonAdmin(t *testing.T) {
 
 func TestCreateCategory(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
 	categoryName := "My category"
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	category, err := client.CreateCategory(categoryName)
 	if err != nil {
 		t.Fatal(err)
@@ -432,7 +432,7 @@ func TestCreateCategory(t *testing.T) {
 }
 
 func TestCreateCategoryWithEmptyTitle(t *testing.T) {
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	_, err := client.CreateCategory("")
 	if err == nil {
 		t.Fatal(`The category title should be mandatory`)
@@ -456,14 +456,14 @@ func TestCannotCreateDuplicatedCategory(t *testing.T) {
 
 func TestUpdateCategory(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
 	categoryName := "My category"
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	category, err := client.CreateCategory(categoryName)
 	if err != nil {
 		t.Fatal(err)
@@ -490,14 +490,14 @@ func TestUpdateCategory(t *testing.T) {
 
 func TestListCategories(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	user, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
 	categoryName := "My category"
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	_, err = client.CreateCategory(categoryName)
 	if err != nil {
 		t.Fatal(err)
@@ -553,7 +553,7 @@ func TestDeleteCategory(t *testing.T) {
 
 func TestCannotDeleteCategoryOfAnotherUser(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	categories, err := client.Categories()
 	if err != nil {
 		t.Fatal(err)
@@ -564,7 +564,7 @@ func TestCannotDeleteCategoryOfAnotherUser(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	err = client.DeleteCategory(categories[0].ID)
 	if err == nil {
 		t.Fatal(`Removing a category that belongs to another user should be forbidden`)
@@ -572,7 +572,7 @@ func TestCannotDeleteCategoryOfAnotherUser(t *testing.T) {
 }
 
 func TestDiscoverSubscriptions(t *testing.T) {
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	subscriptions, err := client.Discover(testWebsiteURL)
 	if err != nil {
 		t.Fatal(err)
@@ -956,13 +956,13 @@ func TestGetFeedIcon(t *testing.T) {
 
 func TestGetFeedIconNotFound(t *testing.T) {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	_, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	client = miniflux.New(testBaseURL, username, testStandardPassword)
 	if _, err := client.FeedIcon(42); err == nil {
 		t.Fatalf(`The feed icon should be null`)
 	}
@@ -1233,13 +1233,13 @@ func getRandomUsername() string {
 
 func createClient(t *testing.T) *miniflux.Client {
 	username := getRandomUsername()
-	client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
+	client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
 	_, err := client.CreateUser(username, testStandardPassword, false)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	return miniflux.NewClient(testBaseURL, username, testStandardPassword)
+	return miniflux.New(testBaseURL, username, testStandardPassword)
 }
 
 func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflux.Category) {

+ 0 - 9
vendor/github.com/miniflux/miniflux-go/.travis.yml

@@ -1,9 +0,0 @@
-notifications:
-  email: false
-language: go
-go:
-  - 1.9
-before_install:
-  - go get -u github.com/golang/lint/golint
-script:
-  - golint *.go

+ 0 - 21
vendor/github.com/miniflux/miniflux-go/LICENSE

@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2017 Frédéric Guillot
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.

+ 0 - 65
vendor/github.com/miniflux/miniflux-go/README.md

@@ -1,65 +0,0 @@
-Go Library for Miniflux
-=======================
-[![Build Status](https://travis-ci.org/miniflux/miniflux-go.svg?branch=master)](https://travis-ci.org/miniflux/miniflux-go)
-[![GoDoc](https://godoc.org/github.com/miniflux/miniflux-go?status.svg)](https://godoc.org/github.com/miniflux/miniflux-go)
-
-Client library for Miniflux REST API.
-
-Requirements
-------------
-
-- Miniflux >= 2.0.0
-- Go >= 1.9
-
-Installation
-------------
-
-```bash
-go get -u github.com/miniflux/miniflux-go
-```
-
-Example
--------
-
-```go
-package main
-
-import (
-	"fmt"
-	"io/ioutil"
-	"github.com/miniflux/miniflux-go"
-)
-
-func main() {
-    client := miniflux.NewClient("https://api.example.org", "admin", "secret")
-
-    // Fetch all feeds.
-    feeds, err := client.Feeds()
-    if err != nil {
-        fmt.Println(err)
-        return
-    }
-    fmt.Println(feeds)
-
-    // Backup your feeds to an OPML file.
-    opml, err := client.Export()
-    if err != nil {
-        fmt.Println(err)
-        return
-    }
-
-    err = ioutil.WriteFile("opml.xml", opml, 0644)
-    if err != nil {
-        fmt.Println(err)
-        return
-    }
-
-    fmt.Println("backup done!")
-}
-```
-
-Credits
--------
-
-- Author: Frédéric Guillot
-- Distributed under MIT License

+ 0 - 31
vendor/github.com/miniflux/miniflux-go/doc.go

@@ -1,31 +0,0 @@
-// Copyright 2017 Frédéric Guillot. All rights reserved.
-// Use of this source code is governed by the MIT license
-// that can be found in the LICENSE file.
-
-/*
-
-Package miniflux implements a client library for the Miniflux REST API.
-
-Examples
-
-This code snippet fetch the list of users.
-
-	client := miniflux.NewClient("https://api.example.org", "admin", "secret")
-	users, err := client.Users()
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-	fmt.Println(users, err)
-
-This one discover subscriptions on a website.
-
-	subscriptions, err := client.Discover("https://example.org/")
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-	fmt.Println(subscriptions)
-
-*/
-package miniflux