-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from zembrodt/develop
Merge develop into main
- Loading branch information
Showing
8 changed files
with
155 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,76 @@ | ||
# ShowTunes API | ||
|
||
Go server used by the ShowTunes app to make API requests where a client secret is needed. | ||
|
||
## Requests | ||
* */v1/auth/tokens* (**POST**): Retrieve a Spotify auth token | ||
* Expects *code* and *redirect_uri* | ||
* Returns a new auth token | ||
* */v1/auth/tokens* (**PUT**): Refresh a Spotify auth token | ||
* Expects refresh token as *code* | ||
* Returns an updated auth token | ||
* */v1/color* (**GET**): Retrieve the dominant color of a given album's cover art | ||
* Expects *url* - must be to an image hosted by Spotify (*i.scdn.co*) | ||
* Returns the dominant color in hex | ||
Go server API as an example of a 3rd party API for the ShowTunes app. | ||
|
||
See: https://github.com/zembrodt/showtunes | ||
|
||
The ShowTunes app can be configured to use a 3rd party API for its authorization requests. It can also be configured to | ||
use a 3rd party API (the same or a different server) to request analysis information on album covers. | ||
|
||
## Endpoints | ||
|
||
###`/v1/auth/token` POST | ||
Retrieve/Refresh a Spotify auth token | ||
|
||
#### Request | ||
| Parameter | Value | | ||
| --------------- | --------------------------------------------------------------------------------- | | ||
| `grant_type` | Must be `authorization_token` or `refresh_token` | | ||
| `code` | The authorization code | | ||
| `redirect_uri` | Must match the `redirect_uri` used when requesting the authorization code | | ||
| `refresh_token` | The token used in place of the authorization code when the auth token has expired | | ||
|
||
#### Response | ||
| Parameter | Type | Value | | ||
| --------------- | -------- | ---------------------------------------------------- | | ||
| `access_token` | `string` | The Spotify API access token | | ||
| `token_type` | `string` | How the access token can be used. Always `Bearer` | | ||
| `refresh_token` | `string` | The token used to request a new token after `expiry` | | ||
| `expiry` | `string` | Date formatted string for when this token expires | | ||
|
||
--- | ||
|
||
###`/v1/color` GET | ||
Retrieve the dominant color of a given album's cover art | ||
|
||
#### Request | ||
| Parameter | Value | | ||
| --------- | --------------------------------------------------------------------------------- | | ||
| `url` | The url for the image to be used (Must be a domain configured in `VALID_DOMAINS`) | | ||
|
||
#### Response | ||
| Parameter | Type | Value | | ||
| --------- | -------- | ---------------------------------- | | ||
| `color` | `string` | The dominant color as a hex string | | ||
|
||
--- | ||
|
||
###`/ping` GET | ||
Retrieve information on the running API server | ||
|
||
#### Response | ||
| Parameter | Type | Value | | ||
| --------- | -------- | ----------------------------------| | ||
| `name` | `string` | The name of the application | | ||
| `version` | `string` | The application's current version | | ||
| `api_root` | `string` | The API endpoint root | | ||
|
||
## Configurations | ||
*Note*: these can be configured as environment variables or in `config/config.yaml`. | ||
|
||
Environment variables must be prefixed with `SHOWTUNES_` | ||
|
||
| Config | Default Value | Description | | ||
| ---------------- | ------------- | ------------------------------------------------------------------ | | ||
| `SERVER_ADDRESS` | `localhost` | The address of this API server | | ||
| `SERVER_PORT` | `8000` | The port of this API server | | ||
| `ORIGIN` | `*` | URL for client accessing this API (`Access-Control-Allow-Origin`) | | ||
| `MAX_AGE` | `86400` | Value for `Access-Control-Max-Age` header | | ||
| `CLIENT_ID` | None | The Client ID to retrieve the authorization token with | | ||
| `CLIENT_SECRET` | None | The Client Secret to retrieve the authorization token with | | ||
| `VALID_DOMAINS` | `i.scdn.co` | Comma-separated list of URLs that host the required Spotify images | | ||
|
||
## Building and Running the Server | ||
Scripts have been provided to build an executable for the server that can be deployed. | ||
* `resources/scripts/build.bat` | ||
* `resources/scripts/build.sh` |
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
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,10 +1,32 @@ | ||
module github.com/zembrodt/showtunes-api | ||
|
||
go 1.16 | ||
go 1.20 | ||
|
||
require ( | ||
github.com/cenkalti/dominantcolor v0.0.0-20211126221809-b695f665ba35 | ||
github.com/gorilla/mux v1.8.0 | ||
github.com/spf13/viper v1.7.1 | ||
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93 | ||
) | ||
|
||
require ( | ||
github.com/fsnotify/fsnotify v1.4.7 // indirect | ||
github.com/golang/protobuf v1.4.2 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/magiconair/properties v1.8.1 // indirect | ||
github.com/mitchellh/mapstructure v1.1.2 // indirect | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect | ||
github.com/pelletier/go-toml v1.2.0 // indirect | ||
github.com/spf13/afero v1.1.2 // indirect | ||
github.com/spf13/cast v1.3.0 // indirect | ||
github.com/spf13/jwalterweatherman v1.0.0 // indirect | ||
github.com/spf13/pflag v1.0.3 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect | ||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect | ||
golang.org/x/text v0.3.3 // indirect | ||
google.golang.org/appengine v1.6.6 // indirect | ||
google.golang.org/protobuf v1.25.0 // indirect | ||
gopkg.in/ini.v1 v1.51.0 // indirect | ||
gopkg.in/yaml.v2 v2.2.4 // indirect | ||
) |
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ package showtunes | |
|
||
const ( | ||
Name = "ShowTunes API" | ||
Version = "1.0.0" | ||
Version = "1.1.0" | ||
APIRoot = "/v1" | ||
) |
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,19 +1,21 @@ | ||
package global | ||
|
||
const ( | ||
EnvPrefix = "SHOWTUNES" | ||
|
||
// Configuration file | ||
ConfigFileName = "config" | ||
ConfigFileExtension = "yaml" | ||
ConfigFilePath = "config" | ||
|
||
// Configuration names | ||
ServerAddress = "ServerAddress" | ||
ServerPort = "PORT" | ||
PublicAddress = "PublicAddress" | ||
OriginKey = "Origin" | ||
MaxAgeKey = "MaxAge" | ||
ServerAddressKey = "SERVER_ADDRESS" | ||
ServerPortKey = "SERVER_PORT" | ||
OriginKey = "ORIGIN" | ||
MaxAgeKey = "MAX_AGE" | ||
|
||
// Spotify Configurations | ||
ClientIdKey = "ClientId" | ||
ClientSecretKey = "ClientSecret" | ||
ClientIdKey = "CLIENT_ID" | ||
ClientSecretKey = "CLIENT_SECRET" | ||
ValidDomainsKey = "VALID_DOMAINS" | ||
) |