rscrobbler 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lastfm/album.rb +78 -24
- data/lib/lastfm/artist.rb +149 -55
- data/lib/lastfm/auth.rb +19 -8
- data/lib/lastfm/chart.rb +41 -17
- data/lib/lastfm/event.rb +46 -17
- data/lib/lastfm/geo.rb +93 -32
- data/lib/lastfm/group.rb +47 -17
- data/lib/lastfm/library.rb +81 -30
- data/lib/lastfm/playlist.rb +23 -9
- data/lib/lastfm/radio.rb +24 -10
- data/lib/lastfm/tag.rb +57 -17
- data/lib/lastfm/tasteometer.rb +25 -3
- data/lib/lastfm/track.rb +185 -66
- data/lib/lastfm/user.rb +178 -53
- data/lib/lastfm/venue.rb +22 -6
- data/lib/rscrobbler.rb +29 -10
- data/test/unit/lib/lastfm/album_test.rb +0 -0
- data/test/unit/lib/lastfm/artist_test.rb +0 -0
- data/test/unit/lib/lastfm/auth_test.rb +0 -0
- data/test/unit/lib/lastfm/chart_test.rb +0 -0
- data/test/unit/lib/lastfm/event_test.rb +0 -0
- data/test/unit/lib/lastfm/geo_test.rb +0 -0
- data/test/unit/lib/lastfm/group_test.rb +0 -0
- data/test/unit/lib/lastfm/library_test.rb +0 -0
- data/test/unit/lib/lastfm/playlist_test.rb +0 -0
- data/test/unit/lib/lastfm/radio_test.rb +0 -0
- data/test/unit/lib/lastfm/tag_test.rb +0 -0
- data/test/unit/lib/lastfm/tasteometer_test.rb +0 -0
- data/test/unit/lib/lastfm/track_test.rb +0 -0
- data/test/unit/lib/lastfm/user_test.rb +0 -0
- data/test/unit/lib/lastfm/venue_test.rb +0 -0
- data/test/unit/lib/rscrobbler_test.rb +0 -0
- metadata +37 -5
data/lib/lastfm/venue.rb
CHANGED
@@ -4,19 +4,35 @@ module LastFM
|
|
4
4
|
|
5
5
|
TYPE = 'venue'
|
6
6
|
|
7
|
+
# Get a list of upcoming events for a venue.
|
8
|
+
#
|
9
|
+
# @option params [Fixnum, required] :venue the id for the venue to fetch event listings for
|
10
|
+
# @option params [Boolean, optional] :festivalsonly whether only festivals should be returned, or all events
|
7
11
|
# @see http://www.last.fm/api/show?service=394
|
8
|
-
def get_events(
|
9
|
-
LastFM.get( "#{TYPE}.getEvents",
|
12
|
+
def get_events( params )
|
13
|
+
LastFM.get( "#{TYPE}.getEvents", params )
|
10
14
|
end
|
11
15
|
|
16
|
+
# Get a paginated list of all the events held at this venue in the past.
|
17
|
+
#
|
18
|
+
# @option params [Fixnum, required] :venue the id for the venue to fetch event listings for
|
19
|
+
# @option params [Boolean, optional] :festivalsonly whether only festivals should be returned, or all events
|
20
|
+
# @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
|
21
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
|
12
22
|
# @see http://www.last.fm/api/show?service=395
|
13
|
-
def get_past_events(
|
14
|
-
LastFM.get( "#{TYPE}.getPastEvents",
|
23
|
+
def get_past_events( params )
|
24
|
+
LastFM.get( "#{TYPE}.getPastEvents", params )
|
15
25
|
end
|
16
26
|
|
27
|
+
# Search for a venue by venue name.
|
28
|
+
#
|
29
|
+
# @option params [String, required] :venue the venue name to search for
|
30
|
+
# @option params [String, optional] :country a country name used to limit results, as defined by ISO 3166-1
|
31
|
+
# @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
|
32
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
|
17
33
|
# @see http://www.last.fm/api/show?service=396
|
18
|
-
def search(
|
19
|
-
LastFM.get( "#{TYPE}.search",
|
34
|
+
def search( params )
|
35
|
+
LastFM.get( "#{TYPE}.search", params )
|
20
36
|
end
|
21
37
|
|
22
38
|
end
|
data/lib/rscrobbler.rb
CHANGED
@@ -22,7 +22,7 @@ require 'lastfm/user'
|
|
22
22
|
require 'lastfm/venue'
|
23
23
|
|
24
24
|
module LastFM
|
25
|
-
VERSION = '0.0
|
25
|
+
VERSION = '0.1.0'
|
26
26
|
|
27
27
|
HOST = 'ws.audioscrobbler.com'
|
28
28
|
API_VERSION = '2.0'
|
@@ -36,7 +36,7 @@ module LastFM
|
|
36
36
|
# Configure the module and begin a session. Once established (and successfully
|
37
37
|
# executed), the module is ready to send api calls to Last.fm.
|
38
38
|
#
|
39
|
-
#
|
39
|
+
# @example
|
40
40
|
# LastFM.establish_session do |session|
|
41
41
|
# session.username = ...
|
42
42
|
# session.auth_token = ...
|
@@ -62,7 +62,7 @@ module LastFM
|
|
62
62
|
[:api_key, :api_secret, :username, :auth_token].each do |cred|
|
63
63
|
raise AuthenticationError, "Missing credential: #{cred}" unless LastFM.send(cred)
|
64
64
|
end
|
65
|
-
self.session_key = Auth.get_mobile_session( username, auth_token ).find_first('session/key').content
|
65
|
+
self.session_key = Auth.get_mobile_session( username: username, auth_token: auth_token ).find_first('session/key').content
|
66
66
|
end
|
67
67
|
|
68
68
|
# Has the service been authenticated?
|
@@ -90,14 +90,14 @@ module LastFM
|
|
90
90
|
# Construct an HTTP GET call from params, and load the response into a LibXML Document.
|
91
91
|
#
|
92
92
|
# @param [String] method last.fm api method to call
|
93
|
-
# @param [
|
93
|
+
# @param [Boolean] secure whether to sign the request with a method signature and session key
|
94
94
|
# (one exception being auth methods, which require a method signature but no session key)
|
95
95
|
# @param [Hash] params parameters to send, excluding method, api_key, api_sig, and sk
|
96
96
|
# @return [LibXML::XML::Document] xml document of the data contained in the response
|
97
97
|
# @raise [LastFMError] if the request fails
|
98
|
-
def get( method,
|
98
|
+
def get( method, params = {}, secure = false )
|
99
99
|
path = generate_path(method, secure, params)
|
100
|
-
logger.debug( "Last.fm HTTP GET: #{HOST
|
100
|
+
logger.debug( "Last.fm HTTP GET: #{HOST}#{path}" ) if logger
|
101
101
|
response = Net::HTTP.get_response( HOST, path )
|
102
102
|
validate( LibXML::XML::Parser.string( response.body ).parse )
|
103
103
|
end
|
@@ -129,8 +129,10 @@ module LastFM
|
|
129
129
|
xml
|
130
130
|
end
|
131
131
|
|
132
|
-
# Normalize the parameter list by converting values to
|
133
|
-
#
|
132
|
+
# Normalize the parameter list by converting boolean values to 0 or 1, array values to
|
133
|
+
# comma-separated strings, and all other values to a string. Remove any nil values, and
|
134
|
+
# camel-case the parameter keys. Add method, api key, session key, and api signature
|
135
|
+
# parameters where necessary.
|
134
136
|
#
|
135
137
|
# @param [String] method last.fm api method
|
136
138
|
# @param [Boolean] secure whether to include session key and api signature in the parameters
|
@@ -138,8 +140,12 @@ module LastFM
|
|
138
140
|
# @return [Hash] complete, normalized parameters
|
139
141
|
# @private
|
140
142
|
def construct_params( method, secure, params )
|
141
|
-
params.
|
142
|
-
|
143
|
+
params = params.each_with_object({}) do |(k,v), h|
|
144
|
+
v = v ? 1 : 0 if !!v == v # convert booleans into 0 or 1
|
145
|
+
v = v.compact.join(',') if v.is_a?(Array) # convert arrays into comma-separated strings
|
146
|
+
v = v.to_i if v.is_a?(Time) # convert times into integer unix timestamps
|
147
|
+
h[camel_case(k)] = v.to_s unless v.nil?
|
148
|
+
end
|
143
149
|
params['method'] = method
|
144
150
|
params['api_key'] = api_key
|
145
151
|
params['sk'] = session_key if authenticated? && secure
|
@@ -147,6 +153,19 @@ module LastFM
|
|
147
153
|
params
|
148
154
|
end
|
149
155
|
|
156
|
+
# Return a the camelCased version of the given string or symbol, with underscores removed,
|
157
|
+
# word capitalized, and the first letter lower case.
|
158
|
+
#
|
159
|
+
# @param [String] str the string (or symbol) to camel case
|
160
|
+
# @return [String] the camelcased version of the given string
|
161
|
+
def camel_case(key)
|
162
|
+
exceptions = {playlist_id: 'playlistID', playlist_url: 'playlistURL',
|
163
|
+
speed_multiplier: 'speed_multiplier', fingerprint_id: 'fingerprintid'}
|
164
|
+
return exceptions[key] if exceptions.include?(key)
|
165
|
+
camel = key.to_s.split('_').map{|s| s.capitalize}.join
|
166
|
+
camel[0].downcase + camel[1..-1]
|
167
|
+
end
|
168
|
+
|
150
169
|
# Generate the path for a particular method call given params.
|
151
170
|
#
|
152
171
|
# @param [String] method last.fm method to call
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rscrobbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: libxml-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164437020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164437020
|
25
25
|
description: rscrobbler is a Ruby gem for accessing Last.fm's API (http://www.last.fm/api).
|
26
26
|
email:
|
27
27
|
- sgt.floydpepper@gmail.com
|
@@ -46,6 +46,22 @@ files:
|
|
46
46
|
- lib/lastfm/user.rb
|
47
47
|
- lib/lastfm/venue.rb
|
48
48
|
- lib/rscrobbler.rb
|
49
|
+
- test/unit/lib/lastfm/album_test.rb
|
50
|
+
- test/unit/lib/lastfm/artist_test.rb
|
51
|
+
- test/unit/lib/lastfm/auth_test.rb
|
52
|
+
- test/unit/lib/lastfm/chart_test.rb
|
53
|
+
- test/unit/lib/lastfm/event_test.rb
|
54
|
+
- test/unit/lib/lastfm/geo_test.rb
|
55
|
+
- test/unit/lib/lastfm/group_test.rb
|
56
|
+
- test/unit/lib/lastfm/library_test.rb
|
57
|
+
- test/unit/lib/lastfm/playlist_test.rb
|
58
|
+
- test/unit/lib/lastfm/radio_test.rb
|
59
|
+
- test/unit/lib/lastfm/tag_test.rb
|
60
|
+
- test/unit/lib/lastfm/tasteometer_test.rb
|
61
|
+
- test/unit/lib/lastfm/track_test.rb
|
62
|
+
- test/unit/lib/lastfm/user_test.rb
|
63
|
+
- test/unit/lib/lastfm/venue_test.rb
|
64
|
+
- test/unit/lib/rscrobbler_test.rb
|
49
65
|
- bin/generate_lastfm_auth_token
|
50
66
|
homepage: https://github.com/sgtFloyd/rscrobbler
|
51
67
|
licenses: []
|
@@ -71,5 +87,21 @@ rubygems_version: 1.8.12
|
|
71
87
|
signing_key:
|
72
88
|
specification_version: 3
|
73
89
|
summary: Last.fm API wrapper
|
74
|
-
test_files:
|
90
|
+
test_files:
|
91
|
+
- test/unit/lib/lastfm/album_test.rb
|
92
|
+
- test/unit/lib/lastfm/artist_test.rb
|
93
|
+
- test/unit/lib/lastfm/auth_test.rb
|
94
|
+
- test/unit/lib/lastfm/chart_test.rb
|
95
|
+
- test/unit/lib/lastfm/event_test.rb
|
96
|
+
- test/unit/lib/lastfm/geo_test.rb
|
97
|
+
- test/unit/lib/lastfm/group_test.rb
|
98
|
+
- test/unit/lib/lastfm/library_test.rb
|
99
|
+
- test/unit/lib/lastfm/playlist_test.rb
|
100
|
+
- test/unit/lib/lastfm/radio_test.rb
|
101
|
+
- test/unit/lib/lastfm/tag_test.rb
|
102
|
+
- test/unit/lib/lastfm/tasteometer_test.rb
|
103
|
+
- test/unit/lib/lastfm/track_test.rb
|
104
|
+
- test/unit/lib/lastfm/user_test.rb
|
105
|
+
- test/unit/lib/lastfm/venue_test.rb
|
106
|
+
- test/unit/lib/rscrobbler_test.rb
|
75
107
|
has_rdoc:
|