Skip to content

Commit

Permalink
Simplify drive wrapper, s/client/auth/
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen committed Jan 18, 2016
1 parent e60833f commit 4f4152c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 45 deletions.
2 changes: 1 addition & 1 deletion client/auth.go → auth/oauth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package auth

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion client/token.go → auth/token.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package auth

import (
"golang.org/x/oauth2"
Expand Down
2 changes: 1 addition & 1 deletion client/util.go → auth/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package auth

import (
"os"
Expand Down
28 changes: 0 additions & 28 deletions client/client.go

This file was deleted.

16 changes: 6 additions & 10 deletions drive/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ import (
"google.golang.org/api/drive/v3"
)

type Client interface {
Service() *drive.Service
Http() *http.Client
}

type Drive struct {
service *drive.Service
http *http.Client
}

func NewDrive(client Client) *Drive {
return &Drive{
service: client.Service(),
http: client.Http(),
func New(client *http.Client) (*Drive, error) {
service, err := drive.New(client)
if err != nil {
return nil, err
}

return &Drive{service}, nil
}
8 changes: 4 additions & 4 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"
"./cli"
"./client"
"./auth"
"./drive"
)

Expand Down Expand Up @@ -155,17 +155,17 @@ func printCommandHelp(ctx cli.Context) {
func newDrive(args cli.Arguments) *drive.Drive {
configDir := args.String("configDir")
tokenPath := ConfigFilePath(configDir, TokenFilename)
oauth, err := client.NewOauthClient(ClientId, ClientSecret, tokenPath, authCodePrompt)
oauth, err := auth.NewOauthClient(ClientId, ClientSecret, tokenPath, authCodePrompt)
if err != nil {
ExitF("Failed getting oauth client: %s", err.Error())
}

client, err := client.NewClient(oauth)
client, err := drive.New(oauth)
if err != nil {
ExitF("Failed getting drive: %s", err.Error())
}

return drive.NewDrive(client)
return client
}

func authCodePrompt(url string) func() string {
Expand Down

0 comments on commit 4f4152c

Please sign in to comment.