-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shpotify rewrite #6
Conversation
5d7b1ad
to
48edd67
Compare
48edd67
to
54913b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are you deploying this? Just going into a server and running the commands yourself? If so, any plans to set up some Ansible configs (not a criticism as to why they're not here yet, just curious)?
Or am I completely wrong and this is just running locally from one of our abandoned macbooks?
Once you've got a computer to run it on, you can install Maestro by running the following commands | ||
in a terminal: | ||
|
||
```sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does sh
do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It marks it as a shell script for syntax highlighting. Shell == bash for most cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually working yet, right? It doesn't look there's anything for actually playing music from Spotify. Or am I missing something?
- Autocomplete help text: | ||
- Check "Show this command in the autocomplete list" | ||
- Description: https://github.com/hnarayanan/shpotify | ||
- Usage hint: [shpotify command] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, excellent documentation
app.rb
Outdated
require "sinatra" | ||
require "json" | ||
|
||
HELP_TEXT = <<~HELP_TEXT.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The <<~HELP_TEXT
part is making it a heredoc. The .freeze
is because it's a constant, and with our Rubocop configs, we want to enforce that it doesn't change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
app.rb
Outdated
puts "# > spotify #{args}" | ||
output = `./spotify.sh #{args}` | ||
puts output | ||
output = HELP_TEXT unless $?.success? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sinatra
stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. The $?
is the return value of the command being run via backticks above (./spotify.sh #{args}
). More on that here and it returns a Process::Status, which responds to .success?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is $?
catching that? Or is that just some deep Ruby stuff? Or am I completely wrong and this is somehow shell scripts? At least that's what that stack overflow response seems to indicate. I've never seen shell scripts in a ruby file like this before.
Does adding a ?
do anything? Can $
stand alone on its own? I ran echo $
and echo ?
from my command line and nothing happened. Well, something happened but just what you'd expect.
Apologies for the question peppering but I always learn a lot from your and this is v fascinating to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a ruby file. $?
automatically gets assigned by the backticks. This might help a bit: https://stackoverflow.com/a/18623297/1202488
?
and $
don't do anything on their own. However, I think there are related variables like $#
, but I don't remember what they do offhand
app.rb
Outdated
end | ||
|
||
post "/maestro" do | ||
output, success = spotify(params["text"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's cool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does output == success
return true after they're defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. This is doing destructuring. So output
will equal spotify(params["text"])[0]
and success
will equal spotify(params["text"])[1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhh, sweet. Is there a reason we haven't done this in any of our Rails apps thus far? Just not knowing that this was even possible is a valid answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I've done it before, but I think it just doesn't show up that often. Not sure why
require "rack/test" | ||
require "json" | ||
require "pry-byebug" | ||
require_relative "../app" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is one of the downfalls of Sinatra, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat. I don't see a huge problem with it, but I might refactor it at some point later. Rails does have a nice way of handling this, and I'm sure we could set it up similarly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha
spec/maestro_spec.rb
Outdated
let(:text) { "help" } | ||
|
||
it "returns the usage text" do | ||
expect(last_response).to be_ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is last_response
coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a rack-test thing: https://github.com/rack-test/rack-test. It's basically the same as response
in a normal request spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that's available in our Rails apps, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. It's a dependency of rspec-rails or something
This is actually working right now. The music playing part happens when we run the shell command via the As for how we're deploying it, right now it's running on a mac mini, and it's all manual. It might be worth writing an ansible script (or maybe just a shell script) to do that, but for now it's manual |
And the reason it's on a mac mini, instead of deployed to heroku or something is that we need to plug speakers into it. The cloud doesn't have a 3.5mm headphone jack, AFAIK |
bahahahah, I'll let you know if I hear the Cloud:registered: is adding that feature |
* Add Spotify class * Improve regex capabilities * Restrict VALID_COMMANDS to public methods
* Implement restart, pause, quit, and toggle Fix case-sensitivity bug when playing by URI
Unless anyone sees any issues with it, I'm going to merge this PR around 2:00 this Friday (6/29) |
Why?
What changed?
app.rb
, which is the actual app code