-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3305f3d
commit d1e72f0
Showing
10 changed files
with
38 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package spotify | ||
|
||
import ( | ||
"errors" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
type HREF string | ||
|
||
// Get returns the most recent version of the object in it's entirety | ||
// Get returns the most recent version of the object in its entirety | ||
func (h *HREF) Get(api *API, obj interface{}) error { | ||
url, err := h.URL() | ||
if err != nil { | ||
return err | ||
} | ||
urlParts := strings.Split(url.Path, "/") | ||
// looking for a URL that looks something like | ||
// /v1/playlists | ||
if len(urlParts) < 2 { | ||
return errors.New("invalid endpoint structure") | ||
} | ||
apiVersion := urlParts[0] | ||
path := strings.Join(urlParts[1:], "/") | ||
return api.get(apiVersion, path, url.Query(), obj) | ||
|
||
// Example path: v1/me/player | ||
idx := strings.Index(url.Path, "/") | ||
version := url.Path[:idx] | ||
endpoint := url.Path[idx:] | ||
|
||
return api.get(version, endpoint, url.Query(), obj) | ||
} | ||
|
||
// URL parses HREF into a *net/url.URL | ||
// URL parses HREF into a URL object | ||
func (h *HREF) URL() (*url.URL, error) { | ||
return url.Parse(string(*h)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters