Skip to content

Commit

Permalink
Update Auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Aug 8, 2016
1 parent 362b9f4 commit 685b04b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
22 changes: 11 additions & 11 deletions auth.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package sdk

import (
"github.com/clawio/authentication/service"
"github.com/clawio/codes"
"github.com/clawio/clawiod/codes"
"github.com/clawio/clawiod/services/authentication"
)

type (
// AuthService is the interface that deals with the calls to an authentication service.
// AuthService is the interface that deals with the calls to an authentication authentication.
AuthService interface {
Authenticate(username, password string) (string, *codes.Response, error)
Token(username, password string) (string, *codes.Response, error)
}

authService struct {
Expand All @@ -17,19 +17,19 @@ type (
}
)

// Authenticate authenticates a user using a username and a password.
func (s *authService) Authenticate(username, password string) (string, *codes.Response, error) {
authNRequest := &service.AuthenticateRequest{
// Token gets an access token after authenticating the user with username and password.
func (s *authService) Token(username, password string) (string, *codes.Response, error) {
tokenRequest := &authentication.TokenRequest{
Username: username,
Password: password}
req, err := s.client.newRequest("POST", "token", authNRequest)
req, err := s.client.newRequest("POST", "token", tokenRequest)
if err != nil {
return "", nil, err
}
authNResponse := &service.AuthenticateResponse{}
resp, err := s.client.do(req, authNResponse, true)
tokenResponse := &authentication.TokenResponse{}
resp, err := s.client.do(req, tokenResponse, true)
if err != nil {
return "", resp, err
}
return authNResponse.AccessToken, resp, nil
return tokenResponse.AccessToken, resp, nil
}
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"net/url"

"github.com/clawio/codes"
"github.com/clawio/clawiod/codes"
)

// A client manages communication with the ClawIO API.
Expand Down
2 changes: 1 addition & 1 deletion data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"
"path"

"github.com/clawio/codes"
"github.com/clawio/clawiod/codes"
)

// DataService is the interface that specifies the methods to call a data service.
Expand Down
15 changes: 13 additions & 2 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package sdk
import (
"path"

"github.com/clawio/codes"
"github.com/clawio/entities"
"github.com/clawio/clawiod/codes"
"github.com/clawio/clawiod/entities"
)

// MetaDataService is the interface that specifies the methods to call a metaData service.
type MetaDataService interface {
Init() (*codes.Response, error)
CreateTree(pathSpec string) (*codes.Response, error)
ExamineObject(pathSpec string) (*entities.ObjectInfo, *codes.Response, error)
ListTree(pathSpec string) ([]*entities.ObjectInfo, *codes.Response, error)
DeleteObject(pathSpec string) (*codes.Response, error)
Expand Down Expand Up @@ -60,6 +61,7 @@ func (s *metaDataService) ListTree(pathSpec string) ([]*entities.ObjectInfo, *co
}
return oinfos, resp, nil
}

func (s *metaDataService) DeleteObject(pathSpec string) (*codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("DELETE", "delete"+pathSpec, nil)
Expand All @@ -69,6 +71,15 @@ func (s *metaDataService) DeleteObject(pathSpec string) (*codes.Response, error)
return s.client.do(req, nil, true)
}

func (s *metaDataService) CreateTree(pathSpec string) (*codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("POST", "createtree"+pathSpec, nil)
if err != nil {
return nil, err
}
return s.client.do(req, nil, true)
}

func (s *metaDataService) MoveObject(sourcePathSpec, targetPathSpec string) (*codes.Response, error) {
sourcePathSpec = path.Join("/", sourcePathSpec)
targetPathSpec = path.Join("/", targetPathSpec)
Expand Down

0 comments on commit 685b04b

Please sign in to comment.