Skip to content

Commit

Permalink
Moving SearchResponse to prosper package
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Oct 5, 2016
1 parent b10125b commit f2628f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
18 changes: 13 additions & 5 deletions prosper/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,39 @@ type (
Filter SearchFilter
}

// SearchResponse represents the full response from the Search API, documented
// at: https://developers.prosper.com/docs/investor/searchlistings-api/
SearchResponse struct {
Results []types.Listing
ResultCount int
TotalCount int
}

// ListingSearcher is an interface that supports the Search API for active
// Prosper listings.
ListingSearcher interface {
Search(SearchParams) (types.SearchResponse, error)
Search(SearchParams) (SearchResponse, error)
}
)

// Search queries Prosper for current listings that match specified search
// parameters. Search implements the REST API described at:
// https://developers.prosper.com/docs/investor/searchlistings-api/
func (c Client) Search(p SearchParams) (response types.SearchResponse, err error) {
func (c Client) Search(p SearchParams) (response SearchResponse, err error) {
rawResponse, err := c.rawClient.Search(searchParamsToThinType(p))
if err != nil {
return types.SearchResponse{}, err
return SearchResponse{}, err
}
var results []types.Listing
for _, lRaw := range rawResponse.Results {
l, err := c.listingParser.Parse(lRaw)
if err != nil {
log.Printf("failed to parse listing. err: %v, listing: %+v", err, lRaw)
return types.SearchResponse{}, err
return SearchResponse{}, err
}
results = append(results, l)
}
return types.SearchResponse{
return SearchResponse{
Results: results,
ResultCount: rawResponse.ResultCount,
TotalCount: rawResponse.TotalCount,
Expand Down
8 changes: 4 additions & 4 deletions prosper/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestSearch(t *testing.T) {
rawClientErr error
parsedListings []types.Listing
parseErrors []error
want types.SearchResponse
want SearchResponse
wantErr error
msg string
}{
Expand All @@ -112,7 +112,7 @@ func TestSearch(t *testing.T) {
},
parsedListings: []types.Listing{listingA},
parseErrors: []error{nil},
want: types.SearchResponse{
want: SearchResponse{
Results: []types.Listing{listingA},
ResultCount: 1,
TotalCount: 1,
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestSearch(t *testing.T) {
},
parsedListings: []types.Listing{listingA},
parseErrors: []error{nil},
want: types.SearchResponse{
want: SearchResponse{
Results: []types.Listing{listingA},
ResultCount: 1,
TotalCount: 1,
Expand All @@ -168,7 +168,7 @@ func TestSearch(t *testing.T) {
},
parsedListings: []types.Listing{listingA, listingB},
parseErrors: []error{nil, nil},
want: types.SearchResponse{
want: SearchResponse{
Results: []types.Listing{listingA, listingB},
ResultCount: 2,
TotalCount: 2,
Expand Down
9 changes: 0 additions & 9 deletions types/search.go

This file was deleted.

0 comments on commit f2628f9

Please sign in to comment.