scrobbler-ng 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/VERSION.yml +1 -1
- data/lib/scrobbler/base.rb +25 -11
- data/lib/scrobbler.rb +2 -2
- data/scrobbler-ng.gemspec +110 -0
- data/tasks/jeweler.rake +1 -1
- data/test/mocks/rest.rb +0 -1
- metadata +9 -7
- data/lib/scrobbler/rest.rb +0 -47
data/.gitignore
CHANGED
data/VERSION.yml
CHANGED
data/lib/scrobbler/base.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'digest/md5'
|
2
4
|
require 'nokogiri'
|
3
5
|
|
4
|
-
|
6
|
+
# Only set KCODE in Ruby 1.8.X, not in 1.9.X as it is deprecated
|
7
|
+
if RUBY_VERSION =~ /1\.8\.[0-9]/ then
|
8
|
+
$KCODE = 'u'
|
9
|
+
end
|
10
|
+
|
5
11
|
|
6
12
|
module Scrobbler
|
7
13
|
|
@@ -28,13 +34,6 @@ module Scrobbler
|
|
28
34
|
@@secret = secret
|
29
35
|
end
|
30
36
|
|
31
|
-
# Get a HTTP/REST connection to the webservice.
|
32
|
-
#
|
33
|
-
# @return [REST::Connection]
|
34
|
-
def Base.connection
|
35
|
-
@connection ||= REST::Connection.new(API_URL)
|
36
|
-
end
|
37
|
-
|
38
37
|
# Clean up a URL parameter.
|
39
38
|
#
|
40
39
|
# @param [String, Symbol] param The parameter which needs cleanup.
|
@@ -107,9 +106,24 @@ module Scrobbler
|
|
107
106
|
paramlist << "#{sanitize(key)}=#{sanitize(value)}"
|
108
107
|
end
|
109
108
|
end
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
|
110
|
+
# TODO Caching!
|
111
|
+
|
112
|
+
url = URI.join(API_URL, "/2.0/?#{paramlist.join('&')}")
|
113
|
+
|
114
|
+
# Fetch the http answer
|
115
|
+
case request_method
|
116
|
+
when "get"
|
117
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
118
|
+
when "post"
|
119
|
+
req = Net::HTTP::Post.new(url.request_uri)
|
120
|
+
end
|
121
|
+
http = Net::HTTP.new(url.host, url.port)
|
122
|
+
http.use_ssl = (url.port == 443)
|
123
|
+
|
124
|
+
# Process it
|
125
|
+
res = http.start() { |conn| conn.request(req) }
|
126
|
+
doc = Nokogiri::XML(res.body) do |config|
|
113
127
|
config.noent.noblanks.nonet
|
114
128
|
end
|
115
129
|
doc
|
data/lib/scrobbler.rb
CHANGED
@@ -7,7 +7,8 @@ require 'time'
|
|
7
7
|
$: << File.expand_path(File.dirname(__FILE__))
|
8
8
|
|
9
9
|
# Load base class
|
10
|
-
require File.expand_path('scrobbler/base.rb', File.dirname(__FILE__))
|
10
|
+
#require File.expand_path('scrobbler/base.rb', File.dirname(__FILE__))
|
11
|
+
require 'scrobbler/base'
|
11
12
|
|
12
13
|
# Load helper modules
|
13
14
|
require 'scrobbler/helper/image'
|
@@ -28,5 +29,4 @@ require 'scrobbler/library'
|
|
28
29
|
require 'scrobbler/playlist'
|
29
30
|
require 'scrobbler/radio'
|
30
31
|
|
31
|
-
require 'scrobbler/rest'
|
32
32
|
require 'scrobbler/authentication'
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{scrobbler-ng}
|
8
|
+
s.version = "2.0.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Nunemaker", "Jonathan Rudenberg", "Uwe L. Korn"]
|
12
|
+
s.date = %q{2010-07-28}
|
13
|
+
s.description = %q{A ruby library for accessing the Last.fm 2.0 API. It is higly optimized so that it uses less memory and parses XML (through Nokogiri) than other implementations.}
|
14
|
+
s.email = %q{uwelk@xhochy.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION.yml",
|
24
|
+
"examples/album.rb",
|
25
|
+
"examples/artist.rb",
|
26
|
+
"examples/scrobble.rb",
|
27
|
+
"examples/tag.rb",
|
28
|
+
"examples/track.rb",
|
29
|
+
"examples/user.rb",
|
30
|
+
"lib/scrobbler.rb",
|
31
|
+
"lib/scrobbler/album.rb",
|
32
|
+
"lib/scrobbler/artist.rb",
|
33
|
+
"lib/scrobbler/authentication.rb",
|
34
|
+
"lib/scrobbler/base.rb",
|
35
|
+
"lib/scrobbler/basexml.rb",
|
36
|
+
"lib/scrobbler/basexmlinfo.rb",
|
37
|
+
"lib/scrobbler/event.rb",
|
38
|
+
"lib/scrobbler/geo.rb",
|
39
|
+
"lib/scrobbler/helper/image.rb",
|
40
|
+
"lib/scrobbler/helper/streamable.rb",
|
41
|
+
"lib/scrobbler/library.rb",
|
42
|
+
"lib/scrobbler/playlist.rb",
|
43
|
+
"lib/scrobbler/radio.rb",
|
44
|
+
"lib/scrobbler/session.rb",
|
45
|
+
"lib/scrobbler/shout.rb",
|
46
|
+
"lib/scrobbler/tag.rb",
|
47
|
+
"lib/scrobbler/track.rb",
|
48
|
+
"lib/scrobbler/user.rb",
|
49
|
+
"lib/scrobbler/venue.rb",
|
50
|
+
"scrobbler-ng.gemspec",
|
51
|
+
"tasks/jeweler.rake",
|
52
|
+
"tasks/rdoc.rake",
|
53
|
+
"tasks/tests.rake",
|
54
|
+
"tasks/yardoc.rake"
|
55
|
+
]
|
56
|
+
s.homepage = %q{http://github.com/xhochy/scrobbler}
|
57
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
58
|
+
s.require_paths = ["lib"]
|
59
|
+
s.rubygems_version = %q{1.3.7}
|
60
|
+
s.summary = %q{A ruby library for accessing the last.fm v2 webservices}
|
61
|
+
s.test_files = [
|
62
|
+
"test/unit/tag_spec.rb",
|
63
|
+
"test/unit/playlist_spec.rb",
|
64
|
+
"test/unit/album_spec.rb",
|
65
|
+
"test/unit/radio_spec.rb",
|
66
|
+
"test/unit/event_spec.rb",
|
67
|
+
"test/unit/venue_spec.rb",
|
68
|
+
"test/unit/user_spec.rb",
|
69
|
+
"test/unit/artist_spec.rb",
|
70
|
+
"test/unit/playing_test.rb",
|
71
|
+
"test/unit/simpleauth_test.rb",
|
72
|
+
"test/unit/geo_spec.rb",
|
73
|
+
"test/unit/library_spec.rb",
|
74
|
+
"test/unit/track_spec.rb",
|
75
|
+
"test/unit/authentication_spec.rb",
|
76
|
+
"test/spec_helper.rb",
|
77
|
+
"test/test_helper.rb",
|
78
|
+
"test/mocks/library.rb",
|
79
|
+
"test/mocks/rest.rb",
|
80
|
+
"examples/tag.rb",
|
81
|
+
"examples/track.rb",
|
82
|
+
"examples/user.rb",
|
83
|
+
"examples/artist.rb",
|
84
|
+
"examples/scrobble.rb",
|
85
|
+
"examples/album.rb"
|
86
|
+
]
|
87
|
+
|
88
|
+
if s.respond_to? :specification_version then
|
89
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
90
|
+
s.specification_version = 3
|
91
|
+
|
92
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
93
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
94
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
95
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
96
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.2"])
|
97
|
+
else
|
98
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
99
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
100
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
101
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
|
102
|
+
end
|
103
|
+
else
|
104
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
105
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
106
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
107
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
data/tasks/jeweler.rake
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
s.add_development_dependency "rspec", ">= 1.2.9"
|
12
12
|
s.add_development_dependency "yard", ">= 0"
|
13
13
|
s.add_development_dependency "fakeweb", ">= 0"
|
14
|
-
s.add_dependency 'nokogiri'
|
14
|
+
s.add_dependency 'nokogiri', ">= 1.4.2"
|
15
15
|
|
16
16
|
s.files.exclude 'test/**/*'
|
17
17
|
end
|
data/test/mocks/rest.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrobbler-ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 4
|
10
|
+
version: 2.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Nunemaker
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-07-
|
20
|
+
date: 2010-07-28 00:00:00 +02:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -74,8 +74,10 @@ dependencies:
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
hash: 3
|
76
76
|
segments:
|
77
|
-
-
|
78
|
-
|
77
|
+
- 1
|
78
|
+
- 4
|
79
|
+
- 2
|
80
|
+
version: 1.4.2
|
79
81
|
type: :runtime
|
80
82
|
version_requirements: *id004
|
81
83
|
description: A ruby library for accessing the Last.fm 2.0 API. It is higly optimized so that it uses less memory and parses XML (through Nokogiri) than other implementations.
|
@@ -112,13 +114,13 @@ files:
|
|
112
114
|
- lib/scrobbler/library.rb
|
113
115
|
- lib/scrobbler/playlist.rb
|
114
116
|
- lib/scrobbler/radio.rb
|
115
|
-
- lib/scrobbler/rest.rb
|
116
117
|
- lib/scrobbler/session.rb
|
117
118
|
- lib/scrobbler/shout.rb
|
118
119
|
- lib/scrobbler/tag.rb
|
119
120
|
- lib/scrobbler/track.rb
|
120
121
|
- lib/scrobbler/user.rb
|
121
122
|
- lib/scrobbler/venue.rb
|
123
|
+
- scrobbler-ng.gemspec
|
122
124
|
- tasks/jeweler.rake
|
123
125
|
- tasks/rdoc.rake
|
124
126
|
- tasks/tests.rake
|
data/lib/scrobbler/rest.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
|
3
|
-
module Scrobbler
|
4
|
-
module REST
|
5
|
-
class Connection
|
6
|
-
def initialize(base_url, args = {})
|
7
|
-
@base_url = base_url
|
8
|
-
@username = args[:username]
|
9
|
-
@password = args[:password]
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(resource, args = nil)
|
13
|
-
request(resource, "get", args)
|
14
|
-
end
|
15
|
-
|
16
|
-
def post(resource, args = nil)
|
17
|
-
request(resource, "post", args)
|
18
|
-
end
|
19
|
-
|
20
|
-
def request(resource, method = "get", args = nil)
|
21
|
-
url = URI.join(@base_url, resource)
|
22
|
-
|
23
|
-
if args
|
24
|
-
# TODO: What about keys without value?
|
25
|
-
url.query = args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join("&")
|
26
|
-
end
|
27
|
-
|
28
|
-
case method
|
29
|
-
when "get"
|
30
|
-
req = Net::HTTP::Get.new(url.request_uri)
|
31
|
-
when "post"
|
32
|
-
req = Net::HTTP::Post.new(url.request_uri)
|
33
|
-
end
|
34
|
-
|
35
|
-
if @username and @password
|
36
|
-
req.basic_auth(@username, @password)
|
37
|
-
end
|
38
|
-
|
39
|
-
http = Net::HTTP.new(url.host, url.port)
|
40
|
-
http.use_ssl = (url.port == 443)
|
41
|
-
|
42
|
-
res = http.start() { |conn| conn.request(req) }
|
43
|
-
res.body
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|