soundly 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +4 -26
- data/bin/soundly +1 -1
- data/lib/soundly/cli.rb +5 -4
- data/lib/soundly/tracks.rb +1 -1
- data/lib/soundly/version.rb +1 -1
- metadata +3 -10
- data/.DS_Store +0 -0
- data/.rspec +0 -2
- data/Rainbow.md +0 -224
- data/lib/.DS_Store +0 -0
- data/notes.md +0 -10
- data/rspotify.md +0 -255
- data/spec.md +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b7a95dd1aec19a430993c0132ca412e0b0b6ff5c0d09cd53fd67dd70e42d5375
|
4
|
+
data.tar.gz: 3e1fce6eb45557df5ba0985033e4bb0f2def779bd7f4f98b3ded5e6f7398c6b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fcdf5d123ee6be530fde44632d090e1005eaf105e4d901ff3ae6d9f555a05dbd332ba3fd9fb22cbd17390a65daa8f4a7bc7f873a862e25a772d3a05c4b6b249
|
7
|
+
data.tar.gz: 550f2c073b575abb845dfe74cd6b29815cf041b84fdd0afd839c33dd54b172ba42fd16b3772fa2951b97c9d48f538f63d1861d97f31031f9ab46b883064d6501
|
data/README.md
CHANGED
@@ -1,33 +1,11 @@
|
|
1
1
|
# Soundly
|
2
|
-
|
3
|
-
Soundly will offer two playlists generated through Spotify's API. The first playlist will be the 50 most played songs in the united states; the second playlist will be a user curated playlist. The user is me and the playlist is comprised of the songs I listen to most at any given moment.
|
2
|
+
Soundly will offer two playlists generated through Spotify's Ruby API. The first playlist will be the 50 most played songs in the united states; the second playlist will be a user curated playlist. The user is me and the playlist is comprised of the songs I listen to most at any given moment.
|
4
3
|
|
5
4
|
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'soundly'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install soundly
|
5
|
+
run `$ gem install soundly`
|
20
6
|
|
21
7
|
## Usage
|
22
|
-
|
23
|
-
Pretty straight forward. This gem is just for funsies.
|
24
|
-
|
25
|
-
## Development
|
26
|
-
|
27
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
-
|
29
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
8
|
+
Pretty straightforward. This gem is just for funsies.
|
30
9
|
|
31
10
|
## Contributing
|
32
|
-
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/<github username>/soundly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
11
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dwyn/soundly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/bin/soundly
CHANGED
data/lib/soundly/cli.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
class Soundly::CLI
|
2
|
+
|
2
3
|
def up?
|
3
|
-
if Net::Ping::External.new("www.google.com").ping?
|
4
|
-
|
5
|
-
end
|
4
|
+
true if Net::Ping::External.new("www.google.com").ping?
|
5
|
+
# binding.pry
|
6
6
|
end
|
7
|
+
|
7
8
|
def pass_go
|
8
9
|
if !up?
|
9
10
|
puts "You need an internet connection to run this program..."
|
@@ -16,7 +17,7 @@ class Soundly::CLI
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
+
def start
|
20
21
|
pass_go
|
21
22
|
end
|
22
23
|
|
data/lib/soundly/tracks.rb
CHANGED
@@ -30,7 +30,7 @@ class Soundly::Tracks
|
|
30
30
|
|
31
31
|
def red_playlist #MY PERSONAL SPOTIFY PLAYLIST
|
32
32
|
authenticate
|
33
|
-
playlist = RSpotify::Playlist.find('
|
33
|
+
playlist = RSpotify::Playlist.find('dwayne.', '2wbLPMQHxG3vhxQzRNEOm9')
|
34
34
|
playlist.tracks.each do |song|
|
35
35
|
@@red_playlist << song
|
36
36
|
end
|
data/lib/soundly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "<dwyn>"
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,27 +129,20 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
-
- ".DS_Store"
|
133
132
|
- ".gitignore"
|
134
|
-
- ".rspec"
|
135
133
|
- ".travis.yml"
|
136
134
|
- CODE_OF_CONDUCT.md
|
137
135
|
- Gemfile
|
138
136
|
- README.md
|
139
|
-
- Rainbow.md
|
140
137
|
- Rakefile
|
141
138
|
- bin/console
|
142
139
|
- bin/setup
|
143
140
|
- bin/soundly
|
144
|
-
- lib/.DS_Store
|
145
141
|
- lib/soundly.rb
|
146
142
|
- lib/soundly/cli.rb
|
147
143
|
- lib/soundly/tracks.rb
|
148
144
|
- lib/soundly/version.rb
|
149
|
-
- notes.md
|
150
|
-
- rspotify.md
|
151
145
|
- soundly.gemspec
|
152
|
-
- spec.md
|
153
146
|
homepage: https://github.com/dwyn/soundly
|
154
147
|
licenses: []
|
155
148
|
metadata: {}
|
@@ -169,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
162
|
version: '0'
|
170
163
|
requirements: []
|
171
164
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.6
|
165
|
+
rubygems_version: 2.7.6
|
173
166
|
signing_key:
|
174
167
|
specification_version: 4
|
175
168
|
summary: This gem will play songs from a revolving playlist through the Spotify API
|
data/.DS_Store
DELETED
Binary file
|
data/.rspec
DELETED
data/Rainbow.md
DELETED
@@ -1,224 +0,0 @@
|
|
1
|
-
# Rainbow
|
2
|
-
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/rainbow.svg)](https://rubygems.org/gems/rainbow)
|
4
|
-
[![Build Status](https://travis-ci.org/sickill/rainbow.svg?branch=master)](https://travis-ci.org/sickill/rainbow)
|
5
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/vq4acb2c38642s5q?svg=true)](https://ci.appveyor.com/project/sickill/rainbow)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/sickill/rainbow.svg)](https://codeclimate.com/github/sickill/rainbow)
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/sickill/rainbow/badge.svg)](https://coveralls.io/r/sickill/rainbow)
|
8
|
-
|
9
|
-
Rainbow is a ruby gem for colorizing printed text on ANSI terminals.
|
10
|
-
|
11
|
-
It provides a string presenter object, which adds several methods to your
|
12
|
-
strings for wrapping them in [ANSI escape
|
13
|
-
codes](http://en.wikipedia.org/wiki/ANSI_escape_code). These codes when printed
|
14
|
-
in a terminal change text attributes like text color, background color,
|
15
|
-
intensity etc.
|
16
|
-
|
17
|
-
## Usage
|
18
|
-
|
19
|
-
To make your string colored wrap it with `Rainbow()` presenter and call
|
20
|
-
`.color(<color name>)` on it.
|
21
|
-
|
22
|
-
### Example
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
require 'rainbow'
|
26
|
-
|
27
|
-
puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yellow) + " and " + Rainbow("even bright underlined!").underline.bright
|
28
|
-
|
29
|
-
# => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m"
|
30
|
-
```
|
31
|
-
|
32
|
-
Or, [watch this video example](https://asciinema.org/a/J928KpHoUQ0sl54ulOSOLE71E?rows=20&speed=2.5)
|
33
|
-
|
34
|
-
### Rainbow presenter API
|
35
|
-
|
36
|
-
Rainbow presenter adds the following methods to presented string:
|
37
|
-
|
38
|
-
* `color(c)` (with `foreground`, and `fg` aliases)
|
39
|
-
* `background(c)` (with `bg` alias)
|
40
|
-
* `bright`
|
41
|
-
* `underline`
|
42
|
-
* `blink`
|
43
|
-
* `inverse`
|
44
|
-
* `hide`
|
45
|
-
* `faint` (not well supported by terminal emulators)
|
46
|
-
* `italic` (not well supported by terminal emulators)
|
47
|
-
|
48
|
-
Text color can also be changed by calling a method named by a color:
|
49
|
-
|
50
|
-
* `black`
|
51
|
-
* `red`
|
52
|
-
* `green`
|
53
|
-
* `yellow`
|
54
|
-
* `blue`
|
55
|
-
* `magenta`
|
56
|
-
* `cyan`
|
57
|
-
* `white`
|
58
|
-
* `aqua`
|
59
|
-
* `silver`
|
60
|
-
* `aliceblue`
|
61
|
-
* `indianred`
|
62
|
-
|
63
|
-
All of the methods return `self` (the presenter object) so you can chain method
|
64
|
-
calls:
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
Rainbow("hola!").blue.bright.underline
|
68
|
-
```
|
69
|
-
|
70
|
-
### Refinement
|
71
|
-
|
72
|
-
If you want to use the Refinements version, you can:
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
require 'rainbow/refinement'
|
76
|
-
using Rainbow
|
77
|
-
puts "Hi!".green
|
78
|
-
```
|
79
|
-
|
80
|
-
Here's an IRB session example:
|
81
|
-
|
82
|
-
```
|
83
|
-
>> 'Hello, World!'.blue.bright.underline
|
84
|
-
NoMethodError: undefined method `blue' for "Hello, World!":String
|
85
|
-
(ripl):1:in `<main>'
|
86
|
-
>> using Rainbow
|
87
|
-
=> main
|
88
|
-
>> 'Hello, World!'.blue.bright.underline
|
89
|
-
=> "\e[34m\e[1m\e[4mHello, World!\e[0m"
|
90
|
-
```
|
91
|
-
|
92
|
-
### Color specification
|
93
|
-
|
94
|
-
Both `color` and `background` accept color specified in any
|
95
|
-
of the following ways:
|
96
|
-
|
97
|
-
* ANSI color number (where 0 is black, 1 is red, 2 is green and so on):
|
98
|
-
`Rainbow("hello").color(1)`
|
99
|
-
|
100
|
-
* [ANSI color](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) name or [X11 color](https://en.wikipedia.org/wiki/X11_color_names) name as a symbol:
|
101
|
-
`Rainbow("hello").color(:yellow)`.
|
102
|
-
This can be simplified to `Rainbow("hello").yellow`
|
103
|
-
|
104
|
-
See [Color list](#user-content-color-list) for all available color names.
|
105
|
-
Note that ANSI colors can be changed in accordance with terminal setting.
|
106
|
-
But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified.
|
107
|
-
|
108
|
-
* RGB triplet as separate values in the range 0-255:
|
109
|
-
`Rainbow("hello").color(115, 23, 98)`
|
110
|
-
|
111
|
-
* RGB triplet as a hex string:
|
112
|
-
`Rainbow("hello").color("FFC482")` or `Rainbow("hello").color("#FFC482")`
|
113
|
-
|
114
|
-
When you specify a color with a RGB triplet rainbow finds the nearest match
|
115
|
-
from 256 colors palette. Note that it requires a 256-colors capable terminal to
|
116
|
-
display correctly.
|
117
|
-
|
118
|
-
#### Example: Choose a random color
|
119
|
-
|
120
|
-
You can pick a random color with Rainbow, it's a one-liner:
|
121
|
-
|
122
|
-
```ruby
|
123
|
-
colors = Range.new(0,7).to_a
|
124
|
-
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
|
125
|
-
# => "\e[36mw\e[0m\e[37mh\e[0m\e[34mo\e[0m\e[34mo\e[0m\e[37mp\e[0m\e[34m \e[0m\e[36md\e[0m\e[33me\e[0m\e[34me\e[0m\e[37m \e[0m\e[32md\e[0m\e[35mo\e[0m\e[33mo\e[0m\e[36mp\e[0m"
|
126
|
-
|
127
|
-
colors = [:aliceblue, :antiquewhite, :aqua, :aquamarine, :azure, :beige, :bisque, :blanchedalmond, :blueviolet]
|
128
|
-
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
|
129
|
-
# => "\e[38;5;135mw\e[0m\e[38;5;230mh\e[0m\e[38;5;231mo\e[0m\e[38;5;135mo\e[0m\e[38;5;231mp\e[0m\e[38;5;231m \e[0m\e[38;5;122md\e[0m\e[38;5;231me\e[0m\e[38;5;231me\e[0m\e[38;5;230m \e[0m\e[38;5;122md\e[0m\e[38;5;51mo\e[0m\e[38;5;51mo\e[0m\e[38;5;51mp\e[0m"
|
130
|
-
```
|
131
|
-
|
132
|
-
### Configuration
|
133
|
-
|
134
|
-
Rainbow can be enabled/disabled globally by setting:
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
Rainbow.enabled = true/false
|
138
|
-
```
|
139
|
-
|
140
|
-
When disabled all the methods return an unmodified string
|
141
|
-
(`Rainbow("hello").red == "hello"`).
|
142
|
-
|
143
|
-
It's enabled by default, unless STDOUT/STDERR is not a TTY or a terminal is
|
144
|
-
dumb.
|
145
|
-
|
146
|
-
### Advanced usage
|
147
|
-
|
148
|
-
`Rainbow()` and `Rainbow.enabled` operate on the global Rainbow wrapper
|
149
|
-
instance. If you would like to selectively enable/disable coloring in separate
|
150
|
-
parts of your application you can get a new Rainbow wrapper instance for each
|
151
|
-
of them and control the state of coloring during the runtime.
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
rainbow_one = Rainbow.new
|
155
|
-
rainbow_two = Rainbow.new
|
156
|
-
|
157
|
-
rainbow_one.enabled = false
|
158
|
-
|
159
|
-
Rainbow("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)
|
160
|
-
rainbow_one.wrap("hello").red # => "hello"
|
161
|
-
rainbow_two.wrap("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)
|
162
|
-
```
|
163
|
-
|
164
|
-
By default each new instance inherits enabled/disabled state from the global
|
165
|
-
`Rainbow.enabled`.
|
166
|
-
|
167
|
-
This feature comes handy for example when you have multiple output formatters
|
168
|
-
in your application and some of them print to a terminal but others write to a
|
169
|
-
file. Normally rainbow would detect that STDIN/STDERR is a TTY and would
|
170
|
-
colorize all the strings, even the ones that go through file writing
|
171
|
-
formatters. You can easily solve that by disabling coloring for the Rainbow
|
172
|
-
instances that are used by formatters with file output.
|
173
|
-
|
174
|
-
## Installation
|
175
|
-
|
176
|
-
Add it to your Gemfile:
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
gem 'rainbow'
|
180
|
-
```
|
181
|
-
|
182
|
-
Or just install it via rubygems:
|
183
|
-
|
184
|
-
```ruby
|
185
|
-
gem install rainbow
|
186
|
-
```
|
187
|
-
|
188
|
-
## Color list
|
189
|
-
|
190
|
-
### ANSI colors
|
191
|
-
|
192
|
-
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
|
193
|
-
|
194
|
-
### X11 colors
|
195
|
-
|
196
|
-
`aliceblue`, `antiquewhite`, `aqua`, `aquamarine`, `azure`, `beige`, `bisque`,
|
197
|
-
`blanchedalmond`, `blueviolet`, `brown`, `burlywood`, `cadetblue`, `chartreuse`,
|
198
|
-
`chocolate`, `coral`, `cornflower`, `cornsilk`, `crimson`, `darkblue`,
|
199
|
-
`darkcyan`, `darkgoldenrod`, `darkgray`, `darkgreen`, `darkkhaki`,
|
200
|
-
`darkmagenta`, `darkolivegreen`, `darkorange`, `darkorchid`, `darkred`,
|
201
|
-
`darksalmon`, `darkseagreen`, `darkslateblue`, `darkslategray`, `darkturquoise`,
|
202
|
-
`darkviolet`, `deeppink`, `deepskyblue`, `dimgray`, `dodgerblue`, `firebrick`,
|
203
|
-
`floralwhite`, `forestgreen`, `fuchsia`, `gainsboro`, `ghostwhite`, `gold`,
|
204
|
-
`goldenrod`, `gray`, `greenyellow`, `honeydew`, `hotpink`, `indianred`,
|
205
|
-
`indigo`, `ivory`, `khaki`, `lavender`, `lavenderblush`, `lawngreen`,
|
206
|
-
`lemonchiffon`, `lightblue`, `lightcoral`, `lightcyan`, `lightgoldenrod`,
|
207
|
-
`lightgray`, `lightgreen`, `lightpink`, `lightsalmon`, `lightseagreen`,
|
208
|
-
`lightskyblue`, `lightslategray`, `lightsteelblue`, `lightyellow`, `lime`,
|
209
|
-
`limegreen`, `linen`, `maroon`, `mediumaquamarine`, `mediumblue`,
|
210
|
-
`mediumorchid`, `mediumpurple`, `mediumseagreen`, `mediumslateblue`,
|
211
|
-
`mediumspringgreen`, `mediumturquoise`, `mediumvioletred`, `midnightblue`,
|
212
|
-
`mintcream`, `mistyrose`, `moccasin`, `navajowhite`, `navyblue`, `oldlace`,
|
213
|
-
`olive`, `olivedrab`, `orange`, `orangered`, `orchid`, `palegoldenrod`,
|
214
|
-
`palegreen`, `paleturquoise`, `palevioletred`, `papayawhip`, `peachpuff`,
|
215
|
-
`peru`, `pink`, `plum`, `powderblue`, `purple`, `rebeccapurple`, `rosybrown`,
|
216
|
-
`royalblue`, `saddlebrown`, `salmon`, `sandybrown`, `seagreen`, `seashell`,
|
217
|
-
`sienna`, `silver`, `skyblue`, `slateblue`, `slategray`, `snow`, `springgreen`,
|
218
|
-
`steelblue`, `tan`, `teal`, `thistle`, `tomato`, `turquoise`, `violet`,
|
219
|
-
`webgray`, `webgreen`, `webmaroon`, `webpurple`, `wheat`, `whitesmoke`,
|
220
|
-
`yellowgreen`
|
221
|
-
|
222
|
-
## Authors
|
223
|
-
|
224
|
-
[Marcin Kulik](http://ku1ik.com/) and [great open-source contributors](https://github.com/sickill/rainbow/graphs/contributors).
|
data/lib/.DS_Store
DELETED
Binary file
|
data/notes.md
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#Psuedo code for Soundly
|
2
|
-
|
3
|
-
1. Greets user
|
4
|
-
2. Give user choice between blue pill and red pill, or to exit the program completely.
|
5
|
-
|
6
|
-
2A. Blue pill will take user to Spotify's top 50 trending songs in USA
|
7
|
-
|
8
|
-
2B. Red pill will take user to my personal trending list on Spotify.
|
9
|
-
|
10
|
-
3. Regardless of pill chosen, the program should end up in a loop that offers a list of songs available - followed by a prompt to ask the user if they would like detailed information on a specific song
|
data/rspotify.md
DELETED
@@ -1,255 +0,0 @@
|
|
1
|
-
# RSpotify
|
2
|
-
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/rspotify.svg)](http://badge.fury.io/rb/rspotify)
|
4
|
-
[![Build Status](https://travis-ci.org/guilhermesad/rspotify.svg?branch=master)](https://travis-ci.org/guilhermesad/rspotify)
|
5
|
-
|
6
|
-
This is a ruby wrapper for the [Spotify Web API](https://developer.spotify.com/web-api).
|
7
|
-
|
8
|
-
## Features
|
9
|
-
|
10
|
-
* [Full documentation](http://www.rubydoc.info/github/guilhermesad/rspotify/master)
|
11
|
-
* Full API Endpoint coverage
|
12
|
-
* OAuth and other authorization flows
|
13
|
-
|
14
|
-
## Installation
|
15
|
-
|
16
|
-
Add this line to your application's Gemfile:
|
17
|
-
|
18
|
-
gem 'rspotify'
|
19
|
-
|
20
|
-
And then execute:
|
21
|
-
|
22
|
-
$ bundle
|
23
|
-
|
24
|
-
Or install it yourself as:
|
25
|
-
|
26
|
-
$ gem install rspotify
|
27
|
-
|
28
|
-
## Usage
|
29
|
-
|
30
|
-
RSpotify was designed with usability as its primary goal, so that you can forget the API and intuitively interact with your playlists, favorite artists, users and so on.
|
31
|
-
|
32
|
-
You can write things like `my_playlist.tracks.sort_by(&:popularity).last.album` without having to think which API calls must be done. RSpotify fills the gaps for you.
|
33
|
-
|
34
|
-
Below are some basic usage examples. Check the [documentation](http://rdoc.info/github/guilhermesad/rspotify/master/frames) for the complete reference.
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
require 'rspotify'
|
38
|
-
|
39
|
-
artists = RSpotify::Artist.search('Arctic Monkeys')
|
40
|
-
|
41
|
-
arctic_monkeys = artists.first
|
42
|
-
arctic_monkeys.popularity #=> 74
|
43
|
-
arctic_monkeys.genres #=> ["Alternative Pop/Rock", "Indie", ...]
|
44
|
-
arctic_monkeys.top_tracks(:US) #=> (Track array)
|
45
|
-
|
46
|
-
albums = arctic_monkeys.albums
|
47
|
-
albums.first.name #=> "AM"
|
48
|
-
|
49
|
-
am = albums.first
|
50
|
-
am.release_date #=> "2013-09-10"
|
51
|
-
am.images #=> (Image array)
|
52
|
-
am.available_markets #=> ["AR", "BO", "BR", ...]
|
53
|
-
|
54
|
-
tracks = am.tracks
|
55
|
-
tracks.first.name #=> "Do I Wanna Know?"
|
56
|
-
|
57
|
-
do_i_wanna_know = tracks.first
|
58
|
-
do_i_wanna_know.duration_ms #=> 272386
|
59
|
-
do_i_wanna_know.track_number #=> 1
|
60
|
-
do_i_wanna_know.preview_url #=> "https://p.scdn.co/mp3-preview/<id>"
|
61
|
-
|
62
|
-
playlists = RSpotify::Playlist.search('Indie')
|
63
|
-
playlists.first.name #=> "The Indie Mix"
|
64
|
-
|
65
|
-
# You can search within other types too
|
66
|
-
albums = RSpotify::Album.search('The Wall')
|
67
|
-
tracks = RSpotify::Track.search('Thriller')
|
68
|
-
```
|
69
|
-
|
70
|
-
Find by id:
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
arctic_monkeys = RSpotify::Artist.find('7Ln80lUS6He07XvHI8qqHH')
|
74
|
-
arctic_monkeys.related_artists #=> (Artist array)
|
75
|
-
|
76
|
-
am = RSpotify::Album.find('41vPD50kQ7JeamkxQW7Vuy')
|
77
|
-
am.album_type #=> "single"
|
78
|
-
|
79
|
-
do_i_wanna_know = RSpotify::Track.find('2UzMpPKPhbcC8RbsmuURAZ')
|
80
|
-
do_i_wanna_know.album #=> (Album object)
|
81
|
-
|
82
|
-
me = RSpotify::User.find('guilhermesad')
|
83
|
-
me.uri #=> "spotify:user:guilhermesad"
|
84
|
-
|
85
|
-
# Or find several objects at once:
|
86
|
-
|
87
|
-
ids = %w(2UzMpPKPhbcC8RbsmuURAZ 7Jzsc04YpkRwB1zeyM39wE)
|
88
|
-
|
89
|
-
my_tracks = RSpotify::Track.find(ids)
|
90
|
-
my_tracks.size #=> 2
|
91
|
-
```
|
92
|
-
|
93
|
-
Some data require authentication to be accessed, such as playlists' details. You can easily get your credentials [here](https://developer.spotify.com/my-applications).
|
94
|
-
|
95
|
-
Then just copy and paste them like so:
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
RSpotify.authenticate("<your_client_id>", "<your_client_secret>")
|
99
|
-
|
100
|
-
# Now you can access playlists in detail, browse featured content and more
|
101
|
-
|
102
|
-
me = RSpotify::User.find('guilhermesad')
|
103
|
-
me.playlists #=> (Playlist array)
|
104
|
-
|
105
|
-
# Find by id
|
106
|
-
playlist = RSpotify::Playlist.find('guilhermesad', '1Xi8mgiuHHPLQYOw2Q16xv')
|
107
|
-
playlist.name #=> "d33p"
|
108
|
-
playlist.description #=> "d33p h0uz"
|
109
|
-
playlist.followers['total'] #=> 1
|
110
|
-
playlist.tracks #=> (Track array)
|
111
|
-
|
112
|
-
# Search by category
|
113
|
-
party = RSpotify::Category.find('party')
|
114
|
-
party.playlists #=> (Playlist array)
|
115
|
-
categories = RSpotify::Category.list # See all available categories
|
116
|
-
|
117
|
-
# Access featured content from Spotify's Browse tab
|
118
|
-
featured_playlists = RSpotify::Playlist.browse_featured(country: 'US')
|
119
|
-
new_releases = RSpotify::Album.new_releases(country: 'ES')
|
120
|
-
|
121
|
-
# Access tracks' audio features
|
122
|
-
sorry = RSpotify::Track.search("Sorry").first
|
123
|
-
sorry.audio_features.danceability #=> 0.605
|
124
|
-
sorry.audio_features.energy #=> 0.768
|
125
|
-
sorry.audio_features.tempo #=> 100.209
|
126
|
-
|
127
|
-
# Get recommendations
|
128
|
-
recommendations = RSpotify::Recommendations.generate(seed_genres: ['blues', 'country'])
|
129
|
-
recommendations = RSpotify::Recommendations.generate(seed_tracks: my_fav_tracks.map(&:id))
|
130
|
-
recommendations = RSpotify::Recommendations.generate(seed_artists: my_fav_artists.map(&:id))
|
131
|
-
recommendations.tracks #=> (Track array)
|
132
|
-
```
|
133
|
-
|
134
|
-
## Rails + OAuth
|
135
|
-
|
136
|
-
You might want your application to access a user's Spotify account.
|
137
|
-
|
138
|
-
For instance, suppose you want your app to create playlists for the user based on their taste, or to add a feature that syncs user's playlists with some external app.
|
139
|
-
|
140
|
-
If so, add the following to your application (Remember to [get your credentials](https://developer.spotify.com/my-applications))
|
141
|
-
|
142
|
-
```ruby
|
143
|
-
# config/application.rb
|
144
|
-
|
145
|
-
RSpotify::authenticate("<your_client_id>", "<your_client_secret>")
|
146
|
-
```
|
147
|
-
|
148
|
-
```ruby
|
149
|
-
# config/initializers/omniauth.rb
|
150
|
-
|
151
|
-
require 'rspotify/oauth'
|
152
|
-
|
153
|
-
Rails.application.config.middleware.use OmniAuth::Builder do
|
154
|
-
provider :spotify, "<your_client_id>", "<your_client_secret>", scope: 'user-read-email playlist-modify-public user-library-read user-library-modify'
|
155
|
-
end
|
156
|
-
```
|
157
|
-
|
158
|
-
You should replace the scope values for the ones your own app will require from the user. You can see the list of available scopes in [here](https://developer.spotify.com/web-api/using-scopes).
|
159
|
-
|
160
|
-
Next, make a link so the user can log in with his Spotify account:
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
<%= link_to 'Sign in with Spotify', '/auth/spotify' %>
|
164
|
-
```
|
165
|
-
|
166
|
-
And create a route to receive the callback:
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
# config/routes.rb
|
170
|
-
|
171
|
-
get '/auth/spotify/callback', to: 'users#spotify'
|
172
|
-
```
|
173
|
-
|
174
|
-
Remember you need to tell Spotify this address is white-listed. You can do this by adding it to the Redirect URIs list in your [application page](https://developer.spotify.com/my-applications). An example of Redirect URI would be http://localhost:3000/auth/spotify/callback.
|
175
|
-
|
176
|
-
Finally, create a new RSpotify User with the response received:
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
class UsersController < ApplicationController
|
180
|
-
def spotify
|
181
|
-
spotify_user = RSpotify::User.new(request.env['omniauth.auth'])
|
182
|
-
# Now you can access user's private data, create playlists and much more
|
183
|
-
|
184
|
-
# Access private data
|
185
|
-
spotify_user.country #=> "US"
|
186
|
-
spotify_user.email #=> "example@email.com"
|
187
|
-
|
188
|
-
# Create playlist in user's Spotify account
|
189
|
-
playlist = spotify_user.create_playlist!('my-awesome-playlist')
|
190
|
-
|
191
|
-
# Add tracks to a playlist in user's Spotify account
|
192
|
-
tracks = RSpotify::Track.search('Know')
|
193
|
-
playlist.add_tracks!(tracks)
|
194
|
-
playlist.tracks.first.name #=> "Somebody That I Used To Know"
|
195
|
-
|
196
|
-
# Access and modify user's music library
|
197
|
-
spotify_user.save_tracks!(tracks)
|
198
|
-
spotify_user.saved_tracks.size #=> 20
|
199
|
-
spotify_user.remove_tracks!(tracks)
|
200
|
-
|
201
|
-
albums = RSpotify::Album.search('launeddas')
|
202
|
-
spotify_user.save_albums!(albums)
|
203
|
-
spotify_user.saved_albums.size #=> 10
|
204
|
-
spotify_user.remove_albums!(albums)
|
205
|
-
|
206
|
-
# Use Spotify Follow features
|
207
|
-
spotify_user.follow(playlist)
|
208
|
-
spotify_user.follows?(artists)
|
209
|
-
spotify_user.unfollow(users)
|
210
|
-
|
211
|
-
# Get user's top played artists and tracks
|
212
|
-
spotify_user.top_artists #=> (Artist array)
|
213
|
-
spotify_user.top_tracks(time_range: 'short_term') #=> (Track array)
|
214
|
-
|
215
|
-
# Check doc for more
|
216
|
-
end
|
217
|
-
end
|
218
|
-
```
|
219
|
-
|
220
|
-
The user's access token is automatically refreshed by RSpotify when needed. This is specially useful if you persist the user data on a database: this way he only needs to log in to Spotify once in his entire use of your application.
|
221
|
-
|
222
|
-
RSpotify provides a way to facilitate persistence:
|
223
|
-
|
224
|
-
```ruby
|
225
|
-
hash = spotify_user.to_hash
|
226
|
-
# hash containing all user attributes, including access tokens
|
227
|
-
|
228
|
-
# Use the hash to persist the data the way you prefer...
|
229
|
-
|
230
|
-
# Then recover the Spotify user whenever you like
|
231
|
-
spotify_user = RSpotify::User.new(hash)
|
232
|
-
spotify_user.create_playlist!('my_awesome_playlist') # automatically refreshes token
|
233
|
-
```
|
234
|
-
|
235
|
-
## Getting raw response
|
236
|
-
|
237
|
-
To get the raw response from Spotify API requests, just toggle the `raw_response` variable:
|
238
|
-
|
239
|
-
```ruby
|
240
|
-
RSpotify.raw_response = true
|
241
|
-
RSpotify::Artist.search('Cher') #=> (String with raw json response)
|
242
|
-
```
|
243
|
-
|
244
|
-
## Notes
|
245
|
-
|
246
|
-
If you'd like to use OAuth outside rails, have a look [here](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) for the requests that need to be made. You should be able to pass the response to RSpotify::User.new just as well, and from there easily create playlists and more for your user.
|
247
|
-
|
248
|
-
## Contributing
|
249
|
-
|
250
|
-
1. Fork it ( https://github.com/guilhermesad/rspotify/fork )
|
251
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
252
|
-
3. Test your changes (`bundle exec rspec`)
|
253
|
-
4. Commit your changes (`git commit -am 'Add some feature'`)
|
254
|
-
5. Push to the branch (`git push origin my-new-feature`)
|
255
|
-
6. Create a new Pull Request
|