rspotify 1.27.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9ea5b18ac0e9a38c03d231de16d8f0386178b09
4
- data.tar.gz: 7599ceb37479b2a7fce0892090c0d27b1c03e0b3
3
+ metadata.gz: 3a560e9bc44938d7a54e6df175ee4f17f05e5bd5
4
+ data.tar.gz: df0f62eabdef80756d5733dcf8c2662991ab8620
5
5
  SHA512:
6
- metadata.gz: c19a812dbdf2ffeca4a223d494082d8886c5b17839497d1e23d48851998d38efd4e7dc79479a69a2603a1728a99fb73fb53afc2a35d3588aad74013e1ceadfd9
7
- data.tar.gz: 9b5e8a23eb7eb33d0812628a91edcc86b759351ec63d11f2e98ff866eb1ca211f48c82325be8e00e68edb3c9b717f1fad3454e7e1c339769b4f3c299fecde40f
6
+ metadata.gz: 1ab393b11f5dcfc668506b3d5765dd305da5cb6f623fe61c6d9e62bb8616055f2f622d412fb8c13b7caf4fe45aa98b6c30aedeffa376f8c64e7bb3efb03db48e
7
+ data.tar.gz: 3e1f2c2e6283dbebaeac0db621a785805d6e25cc2d5a1af0382bd612e236703809fb7d15fc4d3a14a75fed7789bfcf3a6d8cbb2ec06323e0df7bcebfec6c3e5b
data/lib/rspotify.rb CHANGED
@@ -8,10 +8,11 @@ module RSpotify
8
8
  autoload :Base, 'rspotify/base'
9
9
  autoload :Category, 'rspotify/category'
10
10
  autoload :Device, 'rspotify/device'
11
- autoload :TrackLink, 'rspotify/track_link'
11
+ autoload :Player, 'rspotify/player'
12
12
  autoload :Playlist, 'rspotify/playlist'
13
13
  autoload :Recommendations, 'rspotify/recommendations'
14
14
  autoload :RecommendationSeed, 'rspotify/recommendation_seed'
15
15
  autoload :Track, 'rspotify/track'
16
+ autoload :TrackLink, 'rspotify/track_link'
16
17
  autoload :User, 'rspotify/user'
17
18
  end
@@ -0,0 +1,100 @@
1
+ module RSpotify
2
+ class Player < Base
3
+
4
+ def initialize(user, options = {})
5
+ @user = user
6
+
7
+ @repeat_state = options['repeat_state']
8
+ @shuffle_state = options['shuffle_state']
9
+ @progress = options['progress_ms']
10
+ @is_playing = options['is_playing']
11
+
12
+ @track = if options['track']
13
+ Track.new options['track']
14
+ end
15
+
16
+ @device = if options['device']
17
+ Device.new options['device']
18
+ end
19
+ end
20
+
21
+ def playing?
22
+ is_playing
23
+ end
24
+
25
+ # Allow user to play a specific context(albums, artists & playlists).
26
+ # If `device_id` is not passed, the currently active spotify app will be triggered
27
+ #
28
+ # @example
29
+ # player = user.player
30
+ # player.play_context(nil,"spotify:album:1Je1IMUlBXcx1Fz0WE7oPT")
31
+ def play_context(device_id=nil, uri)
32
+ params = {"context_uri": uri}
33
+ play(device_id, params)
34
+ end
35
+
36
+ # Allow user to play a list of tracks.
37
+ # If `device_id` is not passed, the currently active spotify app will be triggered
38
+ #
39
+ # @example
40
+ # player = user.player
41
+ # tracks_uris = ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"]
42
+ # player.play_tracks(nil, tracks_uris)
43
+ def play_tracks(device_id=nil, uris)
44
+ params = {"uris": uris}
45
+ play(device_id, params)
46
+ end
47
+
48
+ # Allow browser to trigger playback in the user's currently active spotify app.
49
+ # If `device_id` is not passed, the currently active spotify app will be triggered
50
+ #
51
+ # @example
52
+ # player = user.player
53
+ # player.play_track(nil, "spotify:track:4iV5W9uYEdYUVa79Axb7Rh")
54
+ # # User must be a premium subscriber for this feature to work.
55
+ def play_track(device_id=nil, uri)
56
+ params = {"uris": [uri]}
57
+ play(device_id, params)
58
+ end
59
+
60
+ # Play the user's currently active player or specific device
61
+ # If `device_id` is not passed, the currently active spotify app will be triggered
62
+ #
63
+ # @example
64
+ # player = user.player
65
+ # player.play
66
+ def play(device_id = nil, params = {})
67
+ url = "me/player/play"
68
+ url = device_id.nil? ? url : url+"?device_id=#{device_id}"
69
+
70
+ User.oauth_put(@user.id, url, params.to_json)
71
+ end
72
+
73
+ # Pause the user's currently active player
74
+ #
75
+ # @example
76
+ # player = user.player
77
+ # player.pause
78
+ def pause
79
+ url = 'me/player/pause'
80
+ User.oauth_put(@user.id, url, {})
81
+ end
82
+
83
+ # Update the user's currently active player volume
84
+ #
85
+ # @example
86
+ # player = user.player
87
+ # player.volume(50)
88
+ def volume(percent)
89
+ url = "me/player/volume?volume_percent=#{percent}"
90
+ User.oauth_put(@user.id, url, {})
91
+ end
92
+
93
+ def currently_playing
94
+ url = "me/player/currently-playing"
95
+ response = RSpotify.resolve_auth_request(@user.id, url)
96
+ return response if RSpotify.raw_response
97
+ Track.new response["item"]
98
+ end
99
+ end
100
+ end
data/lib/rspotify/user.rb CHANGED
@@ -115,48 +115,15 @@ module RSpotify
115
115
  Playlist.new response
116
116
  end
117
117
 
118
- def currently_playing
119
- url = "me/player/currently-playing"
120
- response = RSpotify.resolve_auth_request(@id, url)
121
- return response if RSpotify.raw_response
122
- Track.new response["item"]
123
- end
124
-
125
- # Allow browser to trigger playback in the user's currently active spotify app.
126
- # User must be a premium subscriber for this feature to work.
127
- def play_track(song_uri)
128
- url = "me/player/play"
129
- params = {"uris": [song_uri]}
130
- User.oauth_put(@id, url, params.to_json)
131
- end
132
-
133
- # Play the user's currently active player
134
- #
135
- # @example
136
- # player = user.player
137
- # player.play
138
- def play
139
- url = 'me/player/play'
140
- User.oauth_put(@id, url, {})
141
- end
142
-
143
- # Pause the user's currently active player
144
- #
145
- # @example
146
- # player = user.player
147
- # player.pause
148
- def pause
149
- url = 'me/player/pause'
150
- User.oauth_put(@id, url, {})
151
- end
152
-
153
118
  # Get the current user’s player
154
119
  #
155
120
  # @example
156
121
  # player = user.player
157
122
  def player
158
- url = 'me/player'
159
- User.oauth_get(@id, url)
123
+ url = "me/player"
124
+ response = User.oauth_get(@id, url)
125
+ return response if RSpotify.raw_response
126
+ response.present? ? Player.new(self, response) : nil
160
127
  end
161
128
 
162
129
  # Get the current user’s recently played tracks. Requires the *user-read-recently-played* scope.
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.27.0'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.27.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Sad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-04 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -146,6 +146,7 @@ files:
146
146
  - lib/rspotify/connection.rb
147
147
  - lib/rspotify/device.rb
148
148
  - lib/rspotify/oauth.rb
149
+ - lib/rspotify/player.rb
149
150
  - lib/rspotify/playlist.rb
150
151
  - lib/rspotify/recommendation_seed.rb
151
152
  - lib/rspotify/recommendations.rb