glutton_lastfm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ For more information, please refer to <http://unlicense.org/>
data/README.rdoc ADDED
@@ -0,0 +1,135 @@
1
+ = glutton_lastfm
2
+
3
+ Ruby last.fm API wrapper written using HTTParty. A last.fm API key is required.
4
+
5
+ See: http://last.fm/api & http://httparty.rubyforge.org
6
+
7
+ == Implemented Methods
8
+
9
+ <tt>[method invocation]</tt> => [api docs url]:
10
+
11
+ * <tt>artist_search( artist_name )</tt> => http://www.last.fm/api/show/?service=272
12
+ * <tt>artist_info( artist_name )</tt> => http://www.last.fm/api/show/?service=267
13
+ * <tt>artist_info_by_mbid( artist_musicbrainz_id )</tt> => http://www.last.fm/api/show/?service=267
14
+ * <tt>artist_top_albums( artist_name )</tt> => http://www.last.fm/api/show/?service=287
15
+ * <tt>artist_top_tracks( artist_name )</tt> => http://www.last.fm/api/show/?service=277
16
+ * <tt>atrist_top_tags( artist_name )</tt> => http://www.last.fm/api/show/?service=288
17
+ * <tt>artist_events( artist_name )</tt> => http://www.last.fm/api/show/?service=117
18
+ * <tt>album_search( album_name, artist_name )</tt> => http://www.last.fm/api/show?service=357
19
+ * <tt>album_info( album_name )</tt> => http://www.last.fm/api/show?service=290
20
+ * <tt>album_info_by_mbid( album_musicbrainz_id )</tt> => http://www.last.fm/api/show?service=290
21
+
22
+ <b>Note:</b> Not all of the last.fm API methods have been implemented. Fork this gem to implement your own using the provided <tt>q</tt> method.
23
+
24
+ == Example
25
+
26
+ require 'rubygems'
27
+ require 'glutton_lastfm'
28
+ require 'pp'
29
+
30
+ last = GluttonLastfm.new '<your last.fm API key>'
31
+
32
+ artist = 'Green Day'
33
+
34
+ artist_search = last.artist_search artist
35
+ artist_info = last.artist_info artist
36
+ artist_info_by_mbid = last.artist_info_by_mbid '084308bd-1654-436f-ba03-df6697104e19'
37
+ artist_top_albums = last.artist_top_albums artist
38
+ artist_top_tracks = last.artist_top_tracks artist
39
+ artist_top_tags = last.artist_top_tags artist
40
+ artist_events = last.artist_events artist
41
+
42
+ album = 'Dookie'
43
+
44
+ album_search = last.album_search album
45
+ album_info = last.album_info artist, album
46
+ album_info_by_mbid = last.album_info_by_mbid '17ca17ed-f061-4d5b-97e2-848d85e47d95'
47
+
48
+ # Inspect any of the returned structures using pp (pretty print):
49
+
50
+ pp album_info
51
+
52
+ == Query Responses
53
+
54
+ Queries to glutton_lastfm methods return hierarchical hash / array strucutres. As shown above, it is best to familarize yourself with the returned data using the <tt>pp</tt> (pretty print) inspector.
55
+
56
+ Here's a look at the returned data in a pseudo-structure. In reality all hash keys are strings.
57
+
58
+ * artist_info & artist_info_by_mbid
59
+ artist info{
60
+ name
61
+ mbid
62
+ url
63
+ image[]
64
+ similar{ artist }[]{ name url image[] }
65
+ tags{ tag }[]{ name url }
66
+ bio{ published summary content }
67
+ }
68
+ * album_info & album_info_by_mbid
69
+ album_info{
70
+ name
71
+ artist
72
+ releasedate
73
+ url
74
+ id
75
+ mbid
76
+ toptags{ tag }[]{ name url }
77
+ image[]
78
+ wiki{ published content summary}
79
+ }
80
+ * artist_search
81
+ artist_search[]{
82
+ name
83
+ url
84
+ mbid
85
+ image[]
86
+ }
87
+ * album_search
88
+ album_search[]{
89
+ name
90
+ url
91
+ mbid
92
+ image[]
93
+ }
94
+ * artist_top_albums
95
+ artist_top_albums[]{
96
+ name
97
+ mbid
98
+ rank
99
+ image[]
100
+ artist{ name url mbid }
101
+ url
102
+ }
103
+ * artist_top_tracks
104
+ artist_top_tracks[]{
105
+ name
106
+ artist{ name url mbid }
107
+ url
108
+ rank
109
+ mbid
110
+ image[]
111
+ }
112
+ * atrist_top_tags
113
+ artist_top_tags[]{
114
+ name
115
+ url
116
+ count
117
+ }
118
+ * artist_events
119
+ artist_events[]{
120
+ artists{ artist headliner }
121
+ title
122
+ url
123
+ startDate
124
+ id
125
+ tags{ tag }[]
126
+ website
127
+ tickets
128
+ venue{ name website location{ city country postalcode street geo:point } }
129
+ description
130
+ image[]
131
+ }
132
+
133
+ == License
134
+
135
+ This is free and unencumbered software released into the public domain. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "glutton_lastfm"
8
+ gem.summary = %Q{Ruby last.fm API wrapper.}
9
+ gem.description = %Q{Simple last.fm API wrapper written using HTTParty in Ruby.}
10
+ gem.email = "stungeye@gmail.com"
11
+ gem.homepage = "http://github.com/stungeye/glutton_lastfm"
12
+ gem.authors = ["Wally Glutton"]
13
+ gem.add_dependency("httparty", ">= 0.5.0")
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "glutton_lastfm #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,54 @@
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{glutton_lastfm}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Wally Glutton"]
12
+ s.date = %q{2010-05-09}
13
+ s.description = %q{Simple last.fm API wrapper written using HTTParty in Ruby.}
14
+ s.email = %q{stungeye@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "glutton_lastfm.gemspec",
27
+ "lib/glutton_lastfm.rb",
28
+ "test/helper.rb",
29
+ "test/test_glutton_lastfm.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/stungeye/glutton_lastfm}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.6}
35
+ s.summary = %q{Ruby last.fm API wrapper.}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_glutton_lastfm.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.0"])
47
+ else
48
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,95 @@
1
+ # glutton_lastfm
2
+ #
3
+ # A last.fm Ruby API Wrapper
4
+ #
5
+ # Author : Wally Glutton - http://stungeye.com
6
+ # Required : Last.fm API Key - http://www.last.fm/api
7
+ # Gem Dependence : HTTParty - Installed by gem along with glutton_lastfm.
8
+ # Ruby Version : Written and tested using Ruby 1.8.7.
9
+ # License : This is free and unencumbered software released into the public domain. See LICENSE for details.
10
+
11
+ require 'httparty'
12
+
13
+ class GluttonLastfm
14
+ include HTTParty
15
+ API_VERSION = "2.0".freeze
16
+ base_uri "http://ws.audioscrobbler.com/#{API_VERSION}/"
17
+ format :xml
18
+
19
+ class QueryStatusFail < StandardError; end
20
+ class QueryArgumentFail < StandardError; end
21
+ class Unauthorized < StandardError; end
22
+ class NotFound < StandardError; end
23
+ class UnknownFail < StandardError; end
24
+
25
+ def initialize( key )
26
+ self.class.default_params :api_key => key
27
+ end
28
+
29
+ def q( options )
30
+ response = self.class.get( '', :query => options )
31
+ raise_errors(response, options)
32
+ response['lfm']
33
+ end
34
+
35
+ def artist_search( artist )
36
+ q( :method => 'artist.search', :artist => artist )['results']['artistmatches']['artist']
37
+ end
38
+
39
+ def album_search( album )
40
+ q( :method => 'album.search', :album => album )['results']['albummatches']['album']
41
+ end
42
+
43
+ def artist_top_albums( artist )
44
+ q( :method => 'artist.gettopalbums', :artist => artist )['topalbums']['album']
45
+ end
46
+
47
+ def artist_top_tracks( artist )
48
+ q( :method => 'artist.gettoptracks', :artist => artist )['toptracks']['track']
49
+ end
50
+
51
+ def artist_top_tags( artist )
52
+ q( :method => 'artist.gettoptags', :artist => artist )['toptags']['tag']
53
+ end
54
+
55
+ def artist_events( artist )
56
+ response = q( :method => 'artist.getevents', :artist => artist )['events']
57
+ (response['total'].to_i == 0) ? [] : response['event']
58
+ end
59
+
60
+ def album_info( artist, album )
61
+ q( :method => 'album.getinfo', :artist => artist, :album => album )['album']
62
+ end
63
+
64
+ def album_info_by_mbid( mbid )
65
+ q( :method => 'album.getinfo', :mbid => mbid )['album']
66
+ end
67
+
68
+ def artist_info( artist )
69
+ q( :method => 'artist.getinfo', :artist => artist )['artist']
70
+ end
71
+
72
+ def artist_info_by_mbid( mbid )
73
+ q( :method => 'artist.getinfo', :mbid => mbid )['artist']
74
+ end
75
+
76
+ private
77
+
78
+ def raise_errors(response, options)
79
+ case response.code.to_i
80
+ when 400
81
+ raise QueryArgumentFail, "#{response['lfm']['error'] if response['lfm']} #{options.inspect}"
82
+ when 403
83
+ raise Unauthorized, "#{response['lfm']['error'] if response['lfm']} #{options.inspect}"
84
+ when 404
85
+ raise NotFound, options.inspect
86
+ when 200 # Is it overkill to test all successfully received requests like this?
87
+ if response['lfm']
88
+ raise QueryStatusFail, "#{response['lfm']['error']} #{options.inspect}" if response['lfm']['status'] != 'ok'
89
+ else
90
+ raise UnknownFail, "Successfully received an HTTP response but could not correctly parse data. #{options.inspect}"
91
+ end
92
+ end
93
+ end
94
+
95
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'glutton_lastfm'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGluttonLastfm < Test::Unit::TestCase
4
+ def test_something_for_real
5
+ flunk "Nothing to see here. Wally hasn't added any tests yet."
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glutton_lastfm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Wally Glutton
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-09 00:00:00 -05: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
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 0
31
+ version: 0.5.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Simple last.fm API wrapper written using HTTParty in Ruby.
35
+ email: stungeye@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - glutton_lastfm.gemspec
51
+ - lib/glutton_lastfm.rb
52
+ - test/helper.rb
53
+ - test/test_glutton_lastfm.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/stungeye/glutton_lastfm
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.6
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Ruby last.fm API wrapper.
84
+ test_files:
85
+ - test/helper.rb
86
+ - test/test_glutton_lastfm.rb