Class: Subsonic::Client
- Inherits:
-
Object
- Object
- Subsonic::Client
- Includes:
- HTTParty
- Defined in:
- lib/subsonic-api/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.
-
#uri_prepend ⇒ Object
Returns the value of attribute uri_prepend.
-
#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 32 33 34 35 36 |
# File 'lib/subsonic-api/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 if(@api_version == '1.5.0') @uri_prepend = '/rest' end 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-api/client.rb', line 14 def api_version @api_version end |
#uri_prepend ⇒ Object
Returns the value of attribute uri_prepend.
14 15 16 |
# File 'lib/subsonic-api/client.rb', line 14 def uri_prepend @uri_prepend end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/subsonic-api/client.rb', line 14 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
14 15 16 |
# File 'lib/subsonic-api/client.rb', line 14 def user @user end |
#version ⇒ Object
Returns the value of attribute version.
14 15 16 |
# File 'lib/subsonic-api/client.rb', line 14 def version @version end |
Instance Method Details
#add_song(*ids) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/subsonic-api/client.rb', line 68 def add_song(*ids) count = ids.length ids = ids.join(',').gsub(/\s/, '') response = self.class.post(@uri_prepend + '/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-api/client.rb', line 50 def response = self.class.get(@uri_prepend + '/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
38 39 40 41 42 43 |
# File 'lib/subsonic-api/client.rb', line 38 def response = self.class.get(@uri_prepend + '/getNowPlaying.view') if response.code == 200 response.parsed_response['subsonic-response']['nowPlaying']['entry'] end end |
#random_songs ⇒ Object
61 62 63 64 65 66 |
# File 'lib/subsonic-api/client.rb', line 61 def random_songs response = self.class.get(@uri_prepend + '/getRandomSongs') if response.code == 200 response['subsonic-response']['randomSongs']['song'] end end |
#say(message) ⇒ Object
45 46 47 48 |
# File 'lib/subsonic-api/client.rb', line 45 def say() response = self.class.post(@uri_prepend + '/addChatMessage.view', :query => {:message => }) response.code == 200 ? : false end |