aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-12-26 12:10:48 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-12-26 12:10:48 -0800
commitc3c27e3637e63af5fe2d9bb45712838740063906 (patch)
treed40bc55d67bd18de3bd8fb146940f676c7c651e2 /vendor
parentd5b8f2fb8839189bdf6893da0f86f3bb26001d3d (diff)
Add API handler to fetch user by username
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/miniflux/miniflux-go/client.go21
-rw-r--r--vendor/github.com/miniflux/miniflux-go/request.go12
2 files changed, 23 insertions, 10 deletions
diff --git a/vendor/github.com/miniflux/miniflux-go/client.go b/vendor/github.com/miniflux/miniflux-go/client.go
index 7350a70..8440a31 100644
--- a/vendor/github.com/miniflux/miniflux-go/client.go
+++ b/vendor/github.com/miniflux/miniflux-go/client.go
@@ -33,8 +33,8 @@ func (c *Client) Users() (Users, error) {
return users, nil
}
-// User returns a single user.
-func (c *Client) User(userID int64) (*User, error) {
+// UserByID returns a single user.
+func (c *Client) UserByID(userID int64) (*User, error) {
body, err := c.request.Get(fmt.Sprintf("/v1/users/%d", userID))
if err != nil {
return nil, err
@@ -50,6 +50,23 @@ func (c *Client) User(userID int64) (*User, error) {
return &user, nil
}
+// UserByUsername returns a single user.
+func (c *Client) UserByUsername(username string) (*User, error) {
+ body, err := c.request.Get(fmt.Sprintf("/v1/users/%s", username))
+ if err != nil {
+ return nil, err
+ }
+ defer body.Close()
+
+ var user User
+ decoder := json.NewDecoder(body)
+ if err := decoder.Decode(&user); err != nil {
+ return nil, fmt.Errorf("miniflux: response error (%v)", err)
+ }
+
+ return &user, nil
+}
+
// CreateUser creates a new user in the system.
func (c *Client) CreateUser(username, password string, isAdmin bool) (*User, error) {
body, err := c.request.Post("/v1/users", &User{Username: username, Password: password, IsAdmin: isAdmin})
diff --git a/vendor/github.com/miniflux/miniflux-go/request.go b/vendor/github.com/miniflux/miniflux-go/request.go
index 17baf4e..a24a425 100644
--- a/vendor/github.com/miniflux/miniflux-go/request.go
+++ b/vendor/github.com/miniflux/miniflux-go/request.go
@@ -55,6 +55,10 @@ func (r *request) Delete(path string) (io.ReadCloser, error) {
}
func (r *request) execute(method, path string, data interface{}) (io.ReadCloser, error) {
+ if r.endpoint[len(r.endpoint)-1:] == "/" {
+ r.endpoint = r.endpoint[:len(r.endpoint)-1]
+ }
+
u, err := url.Parse(r.endpoint + path)
if err != nil {
return nil, err
@@ -126,11 +130,3 @@ func (r *request) toJSON(v interface{}) []byte {
return b
}
-
-func newRequest(endpoint, username, password string) *request {
- return &request{
- endpoint: endpoint,
- username: username,
- password: password,
- }
-}