Skip to content

Commit

Permalink
Moving ClientCredentials type to auth package (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Oct 6, 2016
1 parent 54ad198 commit 976000f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
6 changes: 2 additions & 4 deletions prosper/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"errors"
"net/http"
"net/url"

"github.com/mtlynch/gofn-prosper/types"
)

const baseProsperURL = "https://api.prosper.com/v1"
Expand All @@ -22,12 +20,12 @@ type ProsperAuthenticator interface {

type authenticator struct {
baseURL string
creds types.ClientCredentials
creds ClientCredentials
}

// NewAuthenticator creates a new, unauthenticated Prosper API client with the
// given Prosper credentials.
func NewAuthenticator(creds types.ClientCredentials) ProsperAuthenticator {
func NewAuthenticator(creds ClientCredentials) ProsperAuthenticator {
return &authenticator{
baseURL: baseProsperURL,
creds: creds,
Expand Down
10 changes: 4 additions & 6 deletions prosper/auth/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import (
"net/http"
"reflect"
"testing"

"github.com/mtlynch/gofn-prosper/types"
)

func TestAuthenticateSuccessfulResponse(t *testing.T) {
setUp()
defer tearDown()

creds := types.ClientCredentials{
creds := ClientCredentials{
ClientID: "mock client id",
ClientSecret: "mock client secret",
Username: "mock username",
Expand Down Expand Up @@ -64,7 +62,7 @@ func TestAuthenticateStatusOKButResponseIsMalformed(t *testing.T) {
setUp()
defer tearDown()

creds := types.ClientCredentials{
creds := ClientCredentials{
ClientID: "mock client id",
ClientSecret: "mock client secret",
Username: "mock username",
Expand Down Expand Up @@ -101,7 +99,7 @@ func TestAuthenticateHttpError(t *testing.T) {
setUp()
defer tearDown()

creds := types.ClientCredentials{
creds := ClientCredentials{
ClientID: "mock client id",
ClientSecret: "mock client secret",
Username: "mock username",
Expand All @@ -122,7 +120,7 @@ func TestAuthenticateFailedResponse(t *testing.T) {
setUp()
defer tearDown()

creds := types.ClientCredentials{
creds := ClientCredentials{
ClientID: "mock client id",
ClientSecret: "mock client secret",
Username: "mock username",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types
package auth

// ClientCredentials represents the user's secret credentials used to
// authenticate to the Prosper API.
Expand Down
3 changes: 1 addition & 2 deletions prosper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package prosper
import (
"github.com/mtlynch/gofn-prosper/prosper/auth"
"github.com/mtlynch/gofn-prosper/prosper/thin"
"github.com/mtlynch/gofn-prosper/types"
)

// Client is a Prosper client that communicates with the Prosper HTTP endpoints.
Expand All @@ -17,7 +16,7 @@ type Client struct {
}

// NewClient creates a new Client with the given Prosper credentials.
func NewClient(creds types.ClientCredentials) Client {
func NewClient(creds auth.ClientCredentials) Client {
tokenMgr := auth.NewTokenManager(auth.NewAuthenticator(creds))
return Client{
rawClient: thin.NewClient(tokenMgr),
Expand Down

0 comments on commit 976000f

Please sign in to comment.