lastdotfm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lastdotfm.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ Wrapper around the http://www.last.fm public API.
2
+
3
+ Still in development. Although probably won't be doing much more with it.
4
+
5
+ ToDo
6
+ ====
7
+
8
+ 1. Authenticated Functions
9
+ 1. Fix up redundancy
10
+
11
+ Usage
12
+ ======
13
+
14
+ 1. lastfm = Lastdotfm.new
15
+ 1. lastfm.album("Cher", "Believe").info
16
+ 1. lastfm.artist("Bjork").images
17
+ 1. lastfm.album_search("LCD Soundsystem", "This is Happening")
18
+ 1. lastfm.tag("Disco").info
19
+ 1. lastfm.venue(<venue_id_>).events
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lastdotfm.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'lastdotfm', 'version')
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "lastdotfm"
7
+ s.version = Lastdotfm::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brooke McKim"]
10
+ s.email = ["brooke.mckim@gmail.com"]
11
+ s.homepage = "https://github.com/brookemckim/lastdotfm"
12
+ s.summary = %q{Wrapper for the last.fm API.}
13
+ s.description = %q{Simple wrapper for the last.fm API. Will return raw API results in an HTTParty hash.}
14
+
15
+ s.rubyforge_project = "lastdotfm"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('httparty')
23
+ end
data/lastdotfm.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+ require 'uri'
3
+
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'lastdotfm', "base")
5
+
6
+ module Lastdotfm
7
+
8
+ end
@@ -0,0 +1,52 @@
1
+ module Lastdotfm
2
+ class Album < Base
3
+
4
+ def initialize(lastfm, album)
5
+ @lastfm = lastfm
6
+ @album = {}
7
+
8
+ @album[:album] = album[:album]
9
+ @album[:artist] = album[:artist]
10
+ end
11
+
12
+ #options[:language]
13
+ #options[:username]
14
+ #options[:autocorrect]
15
+ def info(options = {})
16
+ method = "album.getinfo"
17
+ params = @album.merge(options)
18
+ @lastfm.get(method, params)
19
+ end
20
+
21
+ #options[:country]
22
+ #options[:autocorrect]
23
+ def buy_links(optons = {})
24
+ method = "album.getbuylinks"
25
+ params = @album.merge(options)
26
+ @lastfm.get(method, params)
27
+ end
28
+
29
+ #options[:limit]
30
+ #options[:autocorrect]
31
+ #options[:page]
32
+ def shouts(options = {})
33
+ method = "album.getshouts"
34
+ params = @album.merge(options)
35
+ @lastfm.get(method, params)
36
+ end
37
+
38
+ #Not working yet
39
+ #def tags_by_user(artist, album, api_sig, session_key)
40
+ # method = "album.gettags"
41
+ # params = {:artist => artist, :album => album, :api_sig => api_sig, :session_key => session_key}
42
+ # @lastfm.get(method, params)
43
+ #end
44
+
45
+ #options[:autocorrect]
46
+ def top_tags(options = {})
47
+ method = "album.gettoptags"
48
+ params = @album.merge(options)
49
+ @lastfm.get(method, params)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,91 @@
1
+ module Lastdotfm
2
+ class Artist < Base
3
+
4
+ def initialize(lastfm, artist)
5
+ @lastfm = lastfm
6
+ @artist = artist
7
+ end
8
+
9
+ #mbid, autocorrect, limit, page,
10
+ def events(options = {})
11
+ method = "artist.getevents"
12
+ params = {:artist => @artist}.merge(options)
13
+ @lastfm.get(method, params)
14
+ end
15
+
16
+ #mbid, autocorrect, limit, page, order
17
+ def images(options = {})
18
+ method = "artist.getimages"
19
+ params = {:artist => @artist}.merge(options)
20
+ @lastfm.get(method, params)
21
+ end
22
+
23
+ #mbid, autocorrect, lang, username
24
+ def info(options = {})
25
+ method = "artist.getinfo"
26
+ params = {:artist => @artist}.merge(options)
27
+ @lastfm.get(method, params)
28
+ end
29
+
30
+ #autocorrect, mbid, page, limit
31
+ def past_events(options = {})
32
+ method = "artist.getpastevents"
33
+ params = {:artist => @artist}.merge(options)
34
+ @lastfm.get(method, params)
35
+ end
36
+
37
+ #autocorrect, mbid
38
+ def podcast(options = {})
39
+ method = "artist.getpodcast"
40
+ params = {:artist => @artist}.merge(options)
41
+ @lastfm.get(method, params)
42
+ end
43
+
44
+ #mbid, limit, autocorect, page
45
+ def shouts(options = {})
46
+ method = "artist.getshouts"
47
+ params = {:artist => @artist}.merge(options)
48
+ @lastfm.get(method, params)
49
+ end
50
+
51
+ #limit, autocorrect, mbid
52
+ def similar(options = {})
53
+ method = "artist.getsimilar"
54
+ params = {:artist => @artist}.merge(options)
55
+ @lastfm.get(method, params)
56
+ end
57
+
58
+ #Needs user auth
59
+ #def tags(options = {})
60
+ #
61
+ #end
62
+
63
+ #mbid, autocorrect, page, limit
64
+ def top_albums(options = {})
65
+ method = "artist.gettopalbums"
66
+ params = {:artist => @artist}.merge(options)
67
+ @lastfm.get(method, params)
68
+ end
69
+
70
+ #mbid, autocorrect
71
+ def top_fans(options = {})
72
+ method = "artist.topfans"
73
+ params = {:artist => @artist}.merge(options)
74
+ @lastfm.get(method, params)
75
+ end
76
+
77
+ #mbid, autocorrect
78
+ def top_tags(options = {})
79
+ method = "artist.gettoptags"
80
+ params = {:artist => @artist}.merge(options)
81
+ @lastfm.get(method, params)
82
+ end
83
+
84
+ #mbid, autocorrect
85
+ def top_tracks(options = {})
86
+ method = "artist.gettoptags"
87
+ params = {:artist => @artist}.merge(options)
88
+ @lastfm.get(method, params)
89
+ end
90
+ end
91
+ end
data/lastdotfm/base.rb ADDED
@@ -0,0 +1,53 @@
1
+ module Lastdotfm
2
+ def self.new(api_key)
3
+ self::Base.new(api_key)
4
+ end
5
+
6
+ class Base
7
+
8
+ [ "album",
9
+ "artist",
10
+ "venue",
11
+ "search",
12
+ "event"
13
+ ].each do |file|
14
+ require File.join(File.expand_path(File.dirname(__FILE__)), file)
15
+ end
16
+
17
+ include Lastdotfm::Search
18
+
19
+ attr :api_key, true
20
+ attr :api_secret, true
21
+
22
+ URL_BASE = "http://ws.audioscrobbler.com/2.0/"
23
+
24
+ def initialize(api_key)
25
+ @api_key = api_key
26
+ end
27
+
28
+ def album(album) @album ||= Lastdotfm::Album.new(self, album) end
29
+ def artist(artist) @artist ||= Lastdotfm::Artist.new(self, artist) end
30
+ def user(user) @user ||= Lastdotfm::User.new(self, user) end
31
+ def venue(venue) @venue ||= Lastdotfm::Venue.new(self, venue) end
32
+ def event(event) @event ||= Lastdotfm::Event.new(self, venue) end
33
+
34
+ protected
35
+
36
+ def get(method, options)
37
+ options.merge!(:api_key => @api_key, :method => method)
38
+ url = generate_url(options)
39
+ puts url
40
+ res = HTTParty.get(url)["lfm"]
41
+
42
+ unless res["status"] == "ok"
43
+ raise Lastdotfm, res["error"]
44
+ end
45
+
46
+ return res
47
+ end
48
+
49
+ def generate_url(options = nil)
50
+ url = URI.encode(URL_BASE + "?" + options.collect { |k,v| "#{k}=#{v.to_s}" }.join('&'))
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,32 @@
1
+ module Lastdotfm
2
+ class Event < Base
3
+ def initalize(lastfm, event)
4
+ @lastfm = lastfm
5
+ @event = event
6
+ end
7
+
8
+ #Requires Authentication
9
+ #def attend
10
+ #
11
+ #end
12
+ #def share(); end
13
+ #def shout(); end
14
+ def info
15
+ method = 'event.getInfo'
16
+ params = {:event => @event}
17
+ @lastfm.get(method, params)
18
+ end
19
+
20
+ def attendees(options = {})
21
+ method = 'event.getAttendees'
22
+ params = {:event => @event}.merge(options)
23
+ @lastfm.get(method, params)
24
+ end
25
+
26
+ def shouts(options = {})
27
+ method = 'event.getShouts'
28
+ params = {:event => @event}.merge(options)
29
+ @lastfm.get(method, params)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ module Lastdotfm
2
+ module Search
3
+ #Feel like these should be class methods
4
+ def album_search(artist, album, options = {})
5
+ method = "album.search"
6
+ params = {:artist => artist, :album => album}
7
+ get(method, params)
8
+ end
9
+
10
+ def artist_search(artist, options = {})
11
+ method = "artist.search"
12
+ params = {:artist => artist}
13
+ get(method, params)
14
+ end
15
+
16
+ def tag_search(tag, options = {})
17
+ method = "tag.search"
18
+ params = {:tag => tag}
19
+ get(method, params)
20
+ end
21
+
22
+ def venue_search(venue, options = {})
23
+ method = "venue.search"
24
+ params = {:venue => venue}
25
+ get(method, params)
26
+ end
27
+ end
28
+ end
data/lastdotfm/tag.rb ADDED
@@ -0,0 +1,50 @@
1
+ module Lastdotfm
2
+ class Tag
3
+ def initalize(lastfm, tag)
4
+ @lastfm = lastfm
5
+ @tag = tag
6
+ end
7
+
8
+ def info(options = {})
9
+ method = 'tag.getInfo'
10
+ params = {:tag => @tag}.merge(options)
11
+ @lastfm.get(method, params)
12
+ end
13
+
14
+ def similar(options = {})
15
+ method = 'getSimilar'
16
+ params {:tag => @tag}.merge(options)
17
+ @lastfm.get(method, params)
18
+ end
19
+
20
+ def top_albums(options = {})
21
+ method = 'getTopAlbums'
22
+ params {:tag => @tag}.merge(options)
23
+ @lastfm.get(method, params)
24
+ end
25
+
26
+ def top(options = {})
27
+ method = 'getTopTags'
28
+ params {:tag => @tag}.merge(options)
29
+ @lastfm.get(method, params)
30
+ end
31
+
32
+ def top_tracks(options = {})
33
+ method = 'getTopTracks'
34
+ params {:tag => @tag}.merge(options)
35
+ @lastfm.get(method, params)
36
+ end
37
+
38
+ def weekly_artists(options = {})
39
+ method = 'getWeeklyArtistChart'
40
+ params {:tag => @tag}.merge(options)
41
+ @lastfm.get(method, params)
42
+ end
43
+
44
+ def weekly_charts(options = {})
45
+ method = 'getWeeklyChartList'
46
+ params {:tag => @tag}.merge(options)
47
+ @lastfm.get(method, params)
48
+ end
49
+ end
50
+ end
data/lastdotfm/user.rb ADDED
@@ -0,0 +1,161 @@
1
+ module Lastdotfm
2
+ class User < Base
3
+ attr :username, true
4
+
5
+ def initalize(lastfm, user)
6
+ @lastfm = lastfm
7
+ @user = user
8
+ end
9
+
10
+ def artist_tracks(options = {})
11
+ method = 'user.getArtistTracks'
12
+ params = {:user => @user}.merge(options)
13
+ @lastfm.get(method, params)
14
+ end
15
+
16
+ def banned_tracks(options = {})
17
+ method = 'user.getBannedTracks'
18
+ params = {:user => @user}.merge(options)
19
+ @lastfm.get(method, params)
20
+ end
21
+
22
+ def events(options = {})
23
+ method = 'user.getEvents'
24
+ params = {:user => @user}.merge(options)
25
+ @lastfm.get(method, params)
26
+ end
27
+
28
+ def friends(options = {})
29
+ method = 'user.getFriends'
30
+ params = {:user => @user}.merge(options)
31
+ @lastfm.get(method, params)
32
+ end
33
+
34
+ def info(options = {})
35
+ method = 'user.getInfo'
36
+ params = {:user => @user}.merge(options)
37
+ @lastfm.get(method, params)
38
+ end
39
+
40
+ def loved_tracks(options = {})
41
+ method = 'user.getLovedTracks'
42
+ params = {:user => @user}.merge(options)
43
+ @lastfm.get(method, params)
44
+ end
45
+
46
+ def neighbours(options = {})
47
+ method = 'user.getNeighbours'
48
+ params = {:user => @user}.merge(options)
49
+ @lastfm.get(method, params)
50
+ end
51
+
52
+ def new_releases(options = {})
53
+ method = 'user.getNewRelases'
54
+ params = {:user => @user}.merge(options)
55
+ @lastfm.get(method, params)
56
+ end
57
+
58
+ def past_events(options = {})
59
+ method = 'user.getPastEvents'
60
+ params = {:user => @user}.merge(options)
61
+ @lastfm.get(method, params)
62
+ end
63
+
64
+ def personal_tags(options = {})
65
+ method = 'user.getPersonalTags'
66
+ params = {:user => @user}.merge(options)
67
+ @lastfm.get(method, params)
68
+ end
69
+
70
+ def playlists(options = {})
71
+ method = 'user.getPlaylists'
72
+ params = {:user => @user}.merge(options)
73
+ @lastfm.get(method, params)
74
+ end
75
+
76
+ def recent_stations(options = {})
77
+ method = 'user.getRecentStations'
78
+ params = {:user => @user}.merge(options)
79
+ @lastfm.get(method, params)
80
+ end
81
+
82
+ def recent_tracks(options = {})
83
+ method = 'user.getRecentTracks'
84
+ params = {:user => @user}.merge(options)
85
+ @lastfm.get(method, params)
86
+ end
87
+
88
+ def recommended_artists(options = {})
89
+ method = 'user.getRecommendedArtists'
90
+ params = {:user => @user}.merge(options)
91
+ @lastfm.get(method, params)
92
+ end
93
+
94
+ def recommended_events(options = {})
95
+ method = 'user.getRecommendedEvents'
96
+ params = {:user => @user}.merge(options)
97
+ @lastfm.get(method, params)
98
+ end
99
+
100
+ def shouts(options = {})
101
+ method = 'user.getShouts'
102
+ params = {:user => @user}.merge(options)
103
+ @lastfm.get(method, params)
104
+ end
105
+
106
+ def top_albums(options = {})
107
+ method = 'user.getTopAlbums'
108
+ params = {:user => @user}.merge(options)
109
+ @lastfm.get(method, params)
110
+ end
111
+
112
+ def top_artists(options = {})
113
+ method = 'user.getTopArtists'
114
+ params = {:user => @user}.merge(options)
115
+ @lastfm.get(method, params)
116
+ end
117
+
118
+ def top_tags(options = {})
119
+ method = 'user.getTopTags'
120
+ params = {:user => @user}.merge(options)
121
+ @lastfm.get(method, params)
122
+ end
123
+
124
+ def top_tracks(options = {})
125
+ method = 'user.getTopTracks'
126
+ params = {:user => @user}.merge(options)
127
+ @lastfm.get(method, params)
128
+ end
129
+
130
+ def weekly_album_chart(options = {})
131
+ method = 'user.getWeeklyAlbumChart'
132
+ params = {:user => @user}.merge(options)
133
+ @lastfm.get(method, params)
134
+ end
135
+
136
+ def weekly_artist_chart(options = {})
137
+ method = 'user.getWeeklyArtistChart'
138
+ params = {:user => @user}.merge(options)
139
+ @lastfm.get(method, params)
140
+ end
141
+
142
+ def weekly_chart_list(options = {})
143
+ method = 'user.getWeeklyChartList'
144
+ params = {:user => @user}.merge(options)
145
+ @lastfm.get(method, params)
146
+ end
147
+
148
+ def weekly_track_chart(options = {})
149
+ method = 'user.getWeeklyArtistChart'
150
+ params = {:user => @user}.merge(options)
151
+ @lastfm.get(method, params)
152
+ end
153
+
154
+ #Need to implement authentication
155
+ #def shout(options = {})
156
+ # method =
157
+ # params = {:user => @user}.merge(options)
158
+ # @lastfm.get(method, params)
159
+ #end
160
+ end
161
+ end
@@ -0,0 +1,20 @@
1
+ module Lastdotfm
2
+ class Venue < Base
3
+ def initalize(lastfm, venue_id)
4
+ @lastfm = lastfm
5
+ @venue = venue_id
6
+ end
7
+
8
+ def events
9
+ method = 'venue.getEvents'
10
+ params = {:venue => @venue}
11
+ @lastfm.get(method, params)
12
+ end
13
+
14
+ def past_events(options = {})
15
+ method = 'venue.getPastEvents'
16
+ params = {:venue => @venue}.merge(options)
17
+ @lastfm.get(method, params)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Lastdotfm
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lastdotfm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Brooke McKim
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-08 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: Simple wrapper for the last.fm API. Will return raw API results in an HTTParty hash.
27
+ email:
28
+ - brooke.mckim@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - lastdotfm.gemspec
40
+ - lastdotfm.rb
41
+ - lastdotfm/album.rb
42
+ - lastdotfm/artist.rb
43
+ - lastdotfm/base.rb
44
+ - lastdotfm/event.rb
45
+ - lastdotfm/search.rb
46
+ - lastdotfm/tag.rb
47
+ - lastdotfm/user.rb
48
+ - lastdotfm/venue.rb
49
+ - lastdotfm/version.rb
50
+ homepage: https://github.com/brookemckim/lastdotfm
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
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project: lastdotfm
73
+ rubygems_version: 1.7.2
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Wrapper for the last.fm API.
77
+ test_files: []
78
+