Class: Subsonic::Client
- Inherits:
-
Object
- Object
- Subsonic::Client
- Includes:
- HTTParty
- Defined in:
- lib/subsonic-rb/client.rb
Constant Summary collapse
- API_VERSION =
{ '3.8' => '1.0.0', '3.9' => '1.1.1', '4.0' => '1.2.0', '4.1' => '1.3.0', '4.2' => '1.4.0', '4.3.1' => '1.5.0' }
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #add_song(*ids) ⇒ Object
-
#initialize(url, username, password, options = {}) ⇒ Client
constructor
A new instance of Client.
- #messages ⇒ Object
- #now_playing ⇒ Object
- #random_songs ⇒ Object
- #say(message) ⇒ Object
Constructor Details
#initialize(url, username, password, options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/subsonic-rb/client.rb', line 16 def initialize(url, username, password, ={}) pass_prefix = [:enc] ? "enc:" : "" version = @version = [:version] || API_VERSION.values.last @api_version = API_VERSION[@version] || version format = [:format] || "json" Struct.new("User", :username, :password) @user = Struct::User.new(username, "#{pass_prefix}#{password}") username, password = @user.username, @user.password self.class.class_eval do base_uri url default_params :u => username, :p => password, :v => version, :f => format, :c => "subsonic-rb.gem" end end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
14 15 16 |
# File 'lib/subsonic-rb/client.rb', line 14 def api_version @api_version end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/subsonic-rb/client.rb', line 14 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
14 15 16 |
# File 'lib/subsonic-rb/client.rb', line 14 def user @user end |
#version ⇒ Object
Returns the value of attribute version.
14 15 16 |
# File 'lib/subsonic-rb/client.rb', line 14 def version @version end |
Instance Method Details
#add_song(*ids) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/subsonic-rb/client.rb', line 72 def add_song(*ids) count = ids.length ids = ids.join(',').gsub(/\s/, '') response = self.class.post('/jukeboxControl.view', :query => {:action => 'add', :id => ids}) response.code == 200 ? "#{count} songs added" : false end |
#messages ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/subsonic-rb/client.rb', line 50 def response = self.class.get('/getChatMessages.view') if response.code == 200 = response.parsed_response['subsonic-response']['chatMessages']['chatMessage'] .map do |msg| time = Time.at(msg['time'] / 1000) "[#{time.strftime("%b-%e")}] #{msg['username']}: #{msg['message']}" end end end |
#now_playing ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/subsonic-rb/client.rb', line 33 def response = self.class.get('/getNowPlaying.view') if response.code == 200 = response.parsed_response['subsonic-response']['nowPlaying']['entry'] if .is_a? Array .map {|entry| "#{entry['artist']} - #{entry['title']}"} else "#{['artist']} - #{['title']}" end end end |
#random_songs ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/subsonic-rb/client.rb', line 61 def random_songs response = self.class.get('/getRandomSongs') if response.code == 200 songs = response['subsonic-response']['randomSongs']['song'] songs.map do |song| {:song => "#{song['artist']} - #{song['title']}", :id => song['id']} end end end |
#say(message) ⇒ Object
45 46 47 48 |
# File 'lib/subsonic-rb/client.rb', line 45 def say() response = self.class.post('/addChatMessage.view', :query => {:message => }) response.code == 200 ? : false end |