Skip to content

Commit

Permalink
Merge pull request #64 from citelao/feature-plugin
Browse files Browse the repository at this point in the history
dev: web api scaffolding
  • Loading branch information
citelao committed May 15, 2015
2 parents 5956652 + da9a672 commit 043d196
Show file tree
Hide file tree
Showing 83 changed files with 13,155 additions and 94 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog #

## v0.13 ##
- Added: preliminary scaffolding for web API (playlists, starring, all of it is coming)
- Added: new settings menu.
- Added: you can now *disable* track notifications
- Fixed: track notifications say the right thing in Spotify 1.0

## v0.12 ##
- Added: compatiblity with Alfred Remote

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Spotifious uses Packal to make sure you always have the latest version. It gives

## Download & Install ##

Latest version: [v0.11.2](https://github.com/citelao/Spotify-for-Alfred/archive/master.zip) | Latest dev build: [v0.11.2](https://github.com/citelao/Spotify-for-Alfred/archive/dev.zip)
Latest version: [v0.13](https://github.com/citelao/Spotify-for-Alfred/archive/master.zip) | Latest dev build: [v0.13](https://github.com/citelao/Spotify-for-Alfred/archive/dev.zip)

1. [Download](https://github.com/citelao/Spotify-for-Alfred/archive/master.zip)
this repository.
Expand Down Expand Up @@ -90,6 +90,7 @@ A lot of people helped out on this:
- **vdesabou** and I trade ideas a ton
- **PHPfunk** and his PHP Alfred workflow inspired much of `OhAlfred`
- **David Ferguson** helped with some iffy Alfred glitches
- **jwilsson**'s [Spotify PHP web API](http:https://jwilsson.github.io/spotify-web-api-php/).
- a slightly modified version of [Entypo](http:https://www.entypo.com/) icon font face for icons.
- and many other people mentioned in the code.

Expand All @@ -106,6 +107,7 @@ Oh, and thanks for reading this whole README. I hope you enjoy Spotifious!

See `CHANGELOG.md` for more detailed information.

- v0.13: Preliminary Web API; toggle track notifications
- v0.12: Compatible with Alfred Remote
- v0.11.2: Location opt-out and tutorial
- v0.11.1: Fixed response freezing
Expand Down
Binary file removed Spotifious.alfredworkflow
Binary file not shown.
40 changes: 40 additions & 0 deletions callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
// thanks to http:https://www.alfredforum.com/topic/1788-prevent-flash-of-no-result
mb_internal_encoding("UTF-8");
date_default_timezone_set('America/New_York');

use OhAlfred\OhAlfred;
require 'vendor/autoload.php';

$alfred = new OhAlfred();
$session = new SpotifyWebAPI\Session($alfred->options('spotify_client_id'), $alfred->options('spotify_secret'), 'http:https://localhost:11114/callback.php');

// Request a access token using the code from Spotify
$session->requestToken($_GET['code']);

// Save the tokens
$alfred->options("spotify_access_token", $session->getAccessToken());
$alfred->options("spotify_refresh_token", $session->getRefreshToken());
$alfred->options("spotify_access_token_expires", time() + $session->getExpires());

?>
<html>
<head>
<title>Spotifious Setup</title>

<link rel="stylesheet" href="include/setup/style/normalize.css" />
<link rel="stylesheet" href="include/setup/style/style.css">
</head>

<body>
<div id="wrapper" class="wrapper">
<section>
<h1>Spotifious should be setup :)</h1>
<p>
You should be able to start using Spotifious now!
</p>

<p>(enjoy)</p>
</section>
</div>
</body>
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"OhAlfred\\": "src/citelao/OhAlfred/",
"Spotifious\\": "src/citelao/Spotifious/"
}
},
"require": {
"jwilsson/spotify-web-api-php": "0.6.*"
}
}
62 changes: 62 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added include/images/dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added include/images/disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added include/images/psd/dash.psd
Binary file not shown.
Binary file added include/images/psd/disabled.psd
Binary file not shown.
87 changes: 87 additions & 0 deletions include/setup/client_submit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
// thanks to http:https://www.alfredforum.com/topic/1788-prevent-flash-of-no-result
mb_internal_encoding("UTF-8");
date_default_timezone_set('America/New_York');

use OhAlfred\OhAlfred;
require '../../vendor/autoload.php';

$response = Array();

if(!$_GET["id"] || !$_GET["secret"]) {
// If we opt out, display the opt out page
if ($_GET["opt_out"]) {
?>
<html>
<head>
<title>Spotifious Setup</title>

<link rel="stylesheet" href="style/normalize.css" />
<link rel="stylesheet" href="style/style.css">
</head>

<body>
<div id="wrapper" class="wrapper">
<section>
<h1>Setup complete!</h1>
<p>You've successfully opted out of using a Spotify app.</p>
<p>
You can always opt back in using the settings menu in
Spotifious. Just type <kbd>s</kbd> in Spotifious.
</p>
<p>You can now reopen Spotifious to continue setup.</p>
</section>
</div>
</body>
</html>

<?php
exit();
}

// If we didn't opt out, we're missing information.
$response["status"] = "error";
$response["message"] = "You're missing some data!";
echo json_encode($response);
exit();
}

$alfred = new OhAlfred();

// Test connection
$session = new SpotifyWebAPI\Session($_GET["id"], $_GET["secret"], 'http:https://localhost:11114/callback.php');

$scopes = array(
'playlist-read-private',
'user-read-private'
);

try {
$session->requestCredentialsToken($scopes);
} catch(SpotifyWebAPI\SpotifyWebAPIException $e) {
$response["status"] = "error";

$response["message"] = "Invalid data - ";
if ($e->getMessage() == "Invalid client") {
$response["message"] .= "invalid ID";
} elseif($e->getMessage() == "Invalid client secret") {
$response["message"] .= "incorrect secret";
} else {
$response["message"] .= $e->getMessage();
}

echo json_encode($response);
exit();
}

// Save data
$alfred->options('spotify_client_id', $_GET["id"]);
$alfred->options('spotify_secret', $_GET["secret"]);
$alfred->options('spotify_access_token', '');
$alfred->options('spotify_access_token_expires', '');
$alfred->options('spotify_refresh_token', '');

$response["status"] = "success";
$response["message"] = "Saved your information! Make sure to do step 8 :)";
echo json_encode($response);
exit();
Binary file added include/setup/img/client_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added include/setup/img/create_an_app_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added include/setup/img/create_an_app_name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added include/setup/img/redirect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added include/setup/img/save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 043d196

Please sign in to comment.