subsonic-api 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +10 -0
- data/lib/subsonic-api/client.rb +76 -0
- data/lib/subsonic-api.rb +13 -0
- metadata +86 -0
data/README.markdown
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Subsonic
|
2
|
+
class Client
|
3
|
+
include ::HTTParty
|
4
|
+
|
5
|
+
API_VERSION = {
|
6
|
+
'3.8' => '1.0.0',
|
7
|
+
'3.9' => '1.1.1',
|
8
|
+
'4.0' => '1.2.0',
|
9
|
+
'4.1' => '1.3.0',
|
10
|
+
'4.2' => '1.4.0',
|
11
|
+
'4.3.1' => '1.5.0'
|
12
|
+
}
|
13
|
+
|
14
|
+
attr_accessor :url, :version, :api_version, :user, :uri_prepend
|
15
|
+
|
16
|
+
def initialize(url, username, password, options={})
|
17
|
+
pass_prefix = options[:enc] ? "enc:" : ""
|
18
|
+
version = @version = options[:version] || API_VERSION.values.last
|
19
|
+
@api_version = API_VERSION[@version] || version
|
20
|
+
|
21
|
+
if(@api_version == '1.5.0')
|
22
|
+
@uri_prepend = '/rest'
|
23
|
+
end
|
24
|
+
|
25
|
+
format = options[:format] || "json"
|
26
|
+
|
27
|
+
Struct.new("User", :username, :password)
|
28
|
+
@user = Struct::User.new(username, "#{pass_prefix}#{password}")
|
29
|
+
username, password = @user.username, @user.password
|
30
|
+
|
31
|
+
self.class.class_eval do
|
32
|
+
base_uri url
|
33
|
+
default_params :u => username, :p => password,
|
34
|
+
:v => version, :f => format, :c => "subsonic-rb.gem"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def now_playing
|
39
|
+
response = self.class.get(@uri_prepend + '/getNowPlaying.view')
|
40
|
+
if response.code == 200
|
41
|
+
response.parsed_response['subsonic-response']['nowPlaying']['entry']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def say(message)
|
46
|
+
response = self.class.post(@uri_prepend + '/addChatMessage.view', :query => {:message => message})
|
47
|
+
response.code == 200 ? message : false
|
48
|
+
end
|
49
|
+
|
50
|
+
def messages
|
51
|
+
response = self.class.get(@uri_prepend + '/getChatMessages.view')
|
52
|
+
if response.code == 200
|
53
|
+
chat_messages = response.parsed_response['subsonic-response']['chatMessages']['chatMessage']
|
54
|
+
chat_messages.map do |msg|
|
55
|
+
time = Time.at(msg['time'] / 1000)
|
56
|
+
"[#{time.strftime("%b-%e")}] #{msg['username']}: #{msg['message']}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def random_songs
|
62
|
+
response = self.class.get(@uri_prepend + '/getRandomSongs')
|
63
|
+
if response.code == 200
|
64
|
+
response['subsonic-response']['randomSongs']['song']
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_song(*ids)
|
69
|
+
count = ids.length
|
70
|
+
ids = ids.join(',').gsub(/\s/, '')
|
71
|
+
response = self.class.post(@uri_prepend + '/jukeboxControl.view', :query => {:action => 'add', :id => ids})
|
72
|
+
response.code == 200 ? "#{count} songs added" : false
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/subsonic-api.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/subsonic')
|
2
|
+
|
3
|
+
%w[
|
4
|
+
httparty
|
5
|
+
json
|
6
|
+
awesome_print
|
7
|
+
].each do |file|
|
8
|
+
require file
|
9
|
+
end
|
10
|
+
|
11
|
+
module Subsonic
|
12
|
+
autoload :Client, File.join(File.expand_path(File.dirname(__FILE__)), "subsonic-rb", "client")
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: subsonic-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
version: "0.3"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Joseph Hsu
|
12
|
+
- James Hart
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-20 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 7
|
31
|
+
- 0
|
32
|
+
version: 0.7.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Interact with a subsonic music streaming server
|
36
|
+
email:
|
37
|
+
- jhsu@josephhsu.com
|
38
|
+
- hjhart@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- README.markdown
|
47
|
+
- lib/subsonic-api/client.rb
|
48
|
+
- lib/subsonic-api.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/hjhart/subsonic-api
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 8
|
66
|
+
- 7
|
67
|
+
version: 1.8.7
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 3
|
76
|
+
- 6
|
77
|
+
version: 1.3.6
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Subsonic music streaming api client
|
85
|
+
test_files: []
|
86
|
+
|