firstfm 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,9 +8,17 @@ My main focus is to import events from Last.FM, but with time I will try to add
8
8
 
9
9
  sudo gem install firstfm
10
10
 
11
- create a ~/.firstfm file with this content
11
+ or add to your Gemfile
12
12
 
13
- api_key: YOUR_API_KEY
13
+ gem 'firstfm'
14
+
15
+ == Configuration
16
+
17
+ This goes to your initializers/firstfm.rb
18
+
19
+ Firstfm.configure do |ffm|
20
+ ffm.api_key = "YOUR_KEY_HERE"
21
+ end
14
22
 
15
23
  == Usage
16
24
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 4
4
- :patch: 1
3
+ :minor: 5
4
+ :patch: 0
5
5
  :build:
data/firstfm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "firstfm"
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aleksandr Lossenko"]
12
- s.date = "2012-07-18"
12
+ s.date = "2013-01-02"
13
13
  s.description = "Firstfm is a ruby wrapper for the Last.fm APIs ( http://www.last.fm/api ). My main focus is to import events from Last.FM, but with time I will try to add support for all API methods."
14
14
  s.email = "aleksandr.lossenko@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "firstfm.gemspec",
28
28
  "lib/firstfm.rb",
29
29
  "lib/firstfm/artist.rb",
30
+ "lib/firstfm/configuration.rb",
30
31
  "lib/firstfm/event.rb",
31
32
  "lib/firstfm/geo.rb",
32
33
  "lib/firstfm/image.rb",
@@ -20,7 +20,7 @@ module Firstfm
20
20
 
21
21
  def get_tags
22
22
  name_params = self.mbid.nil? ? {:artist => self.name} : {:mbid => self.mbid}
23
- response = self.class.get("/2.0/", {:query => {:method => 'artist.getInfo', :api_key => Firstfm::CONFIG['api_key']}.merge(name_params)})
23
+ response = self.class.get("/2.0/", {:query => {:method => 'artist.getInfo', :api_key => Firstfm.config.api_key}.merge(name_params)})
24
24
  tags_array = (response["lfm"] and response["lfm"]["artist"] and response["lfm"]["artist"]["tags"] and response["lfm"]["artist"]["tags"]["tag"]) || []
25
25
  tags_array.map {|t| t["name"] }
26
26
  end
@@ -31,7 +31,7 @@ module Firstfm
31
31
 
32
32
  def get_images(page = 1, limit = 50)
33
33
  name_params = self.mbid.nil? ? {:artist => self.name} : {:mbid => self.mbid}
34
- response = self.class.get("/2.0/", {:query => {:method => 'artist.getImages', :page => page, :limit => limit, :api_key => Firstfm::CONFIG['api_key']}.merge(name_params)})
34
+ response = self.class.get("/2.0/", {:query => {:method => 'artist.getImages', :page => page, :limit => limit, :api_key => Firstfm.config.api_key}.merge(name_params)})
35
35
  images_array = (response["lfm"] and response["lfm"]["images"] and response["lfm"]["images"]["image"]) || []
36
36
  images = Image.init_from_array(images_array)
37
37
  WillPaginate::Collection.create(page, limit) do |pager|
@@ -41,7 +41,7 @@ module Firstfm
41
41
  end
42
42
 
43
43
  def self.search(artist, page = 1, limit = 50)
44
- response = get("/2.0/", {:query => {:method => 'artist.search', :artist => artist, :page => page, :limit => limit, :api_key => Firstfm::CONFIG['api_key']}})
44
+ response = get("/2.0/", {:query => {:method => 'artist.search', :artist => artist, :page => page, :limit => limit, :api_key => Firstfm.config.api_key}})
45
45
  artists_array = (response and response["lfm"] and response["lfm"]["results"] and response["lfm"]["results"]["artistmatches"] and response["lfm"]["results"]["artistmatches"]["artist"]) || []
46
46
  artists = Artist.init_from_array(artists_array)
47
47
  WillPaginate::Collection.create(page, limit) do |pager|
@@ -51,7 +51,7 @@ module Firstfm
51
51
  end
52
52
 
53
53
  def self.get_top_tracks(artist, page = 1, limit = 50)
54
- response = get("/2.0/", {:query => {:method => 'artist.getTopTracks', :artist => artist, :page => page, :limit => limit, :api_key => Firstfm::CONFIG['api_key']}})
54
+ response = get("/2.0/", {:query => {:method => 'artist.getTopTracks', :artist => artist, :page => page, :limit => limit, :api_key => Firstfm.config.api_key}})
55
55
  tracks_array = (response and response["lfm"] and response["lfm"]["toptracks"] and response["lfm"]["toptracks"]["track"]) || []
56
56
  tracks = Track.init_from_array(tracks_array)
57
57
  WillPaginate::Collection.create(page, limit) do |pager|
@@ -0,0 +1,24 @@
1
+ module Firstfm
2
+ class Configuration
3
+ attr_accessor :api_key
4
+
5
+ DEFAULT_API_KEY = "REPLACE_WITH_REAL_KEY"
6
+
7
+ def initialize
8
+ @api_key = DEFAULT_API_KEY
9
+ end
10
+
11
+ end
12
+
13
+ module Configurable
14
+ def configure
15
+ raise "Configuration missing" unless block_given?
16
+ yield @config ||= Firstfm::Configuration.new
17
+ end
18
+
19
+ def config
20
+ @config
21
+ end
22
+ end
23
+ extend Configurable
24
+ end
data/lib/firstfm/geo.rb CHANGED
@@ -13,7 +13,7 @@ module Firstfm
13
13
  page = params.delete(:page) || 1
14
14
  distance = params.delete(:distance)
15
15
 
16
- response = get("/2.0/", {:query => {:method => 'geo.getevents', :location => location, :page => page, :lat => lat, :lng => lng, :distance => distance, :api_key => Firstfm::CONFIG['api_key']}})
16
+ response = get("/2.0/", {:query => {:method => 'geo.getevents', :location => location, :page => page, :lat => lat, :lng => lng, :distance => distance, :api_key => Firstfm.config.api_key}})
17
17
  events = response && response['lfm'] ? Event.init_events_from_hash(response['lfm']) : []
18
18
 
19
19
  collection = WillPaginate::Collection.create(page, 10) do |pager|
@@ -33,7 +33,7 @@ module Firstfm
33
33
  :country => country,
34
34
  :page => page,
35
35
  :limit => limit,
36
- :api_key => Firstfm::CONFIG['api_key']
36
+ :api_key => Firstfm.config.api_key
37
37
  }})
38
38
 
39
39
  artists_array = (response and response['lfm'] and response['lfm']['topartists'] and response['lfm']['topartists']['artist']) || []
@@ -72,7 +72,7 @@ module Firstfm
72
72
  :end => end_timestamp,
73
73
  :page => page,
74
74
  :limit => limit,
75
- :api_key => Firstfm::CONFIG['api_key'] }.reject {|k,v| v.nil?}
75
+ :api_key => Firstfm.config.api_key }.reject {|k,v| v.nil?}
76
76
  })
77
77
 
78
78
  artists_array = (response and response['lfm'] and response['lfm']['topartists'] and response['lfm']['topartists']['artist']) || []
data/lib/firstfm/track.rb CHANGED
@@ -9,7 +9,7 @@ module Firstfm
9
9
  format :xml
10
10
 
11
11
  def self.search(track, page = 1, limit = 30)
12
- response = get("/2.0/", {:query => {:method => 'track.search', :track => track, :page => page, :limit => limit, :api_key => Firstfm::CONFIG['api_key']}})
12
+ response = get("/2.0/", {:query => {:method => 'track.search', :track => track, :page => page, :limit => limit, :api_key => Firstfm.config.api_key}})
13
13
  tracks_array = (response and response["lfm"] and response["lfm"]["results"] and response["lfm"]["results"]["trackmatches"] and response["lfm"]["results"]["trackmatches"]["track"]) || []
14
14
  tracks = Track.init_from_array(tracks_array)
15
15
  WillPaginate::Collection.create(page, limit) do |pager|
data/lib/firstfm/venue.rb CHANGED
@@ -9,7 +9,7 @@ module Firstfm
9
9
  format :xml
10
10
 
11
11
  def self.search(venue, page = 1, limit = 50, country = nil)
12
- response = get("/2.0/", {:query => {:method => 'venue.search', :venue => venue, :page => page, :limit => limit, :country => country, :api_key => Firstfm::CONFIG['api_key']}})
12
+ response = get("/2.0/", {:query => {:method => 'venue.search', :venue => venue, :page => page, :limit => limit, :country => country, :api_key => Firstfm.config.api_key}})
13
13
  venues = response && response['lfm'] ? Venue.init_venues_from_hash(response['lfm']) : []
14
14
  collection = WillPaginate::Collection.create(page, limit) do |pager|
15
15
  pager.replace venues
@@ -18,7 +18,7 @@ module Firstfm
18
18
  end
19
19
 
20
20
  def self.get_events(venue_id)
21
- response = get("/2.0/", {:query => {:method => 'venue.getEvents', :venue => venue_id, :api_key => Firstfm::CONFIG['api_key']}})
21
+ response = get("/2.0/", {:query => {:method => 'venue.getEvents', :venue => venue_id, :api_key => Firstfm.config.api_key}})
22
22
  events = response && response['lfm'] ? Event.init_events_from_hash(response['lfm']) : []
23
23
  end
24
24
 
data/lib/firstfm.rb CHANGED
@@ -3,6 +3,7 @@ require 'crack'
3
3
  require 'httparty'
4
4
  require 'chronic'
5
5
  require 'will_paginate/collection'
6
+ require 'firstfm/configuration'
6
7
  require 'firstfm/track'
7
8
  require 'firstfm/image'
8
9
  require 'firstfm/artist'
@@ -13,6 +14,6 @@ require 'firstfm/geo'
13
14
 
14
15
  module Firstfm
15
16
 
16
- CONFIG = YAML::load(File.read(File.join(ENV['HOME'], '.firstfm')))
17
+ GH_PAGE_URL = "https://github.com/egze/firstfm"
17
18
 
18
19
  end
data/test/helper.rb CHANGED
@@ -14,5 +14,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
14
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
15
  require 'firstfm'
16
16
 
17
+ Firstfm.configure do |ffm|
18
+ ffm.api_key = "TEST"
19
+ end
20
+
17
21
  class Test::Unit::TestCase
18
22
  end
23
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firstfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -159,6 +159,7 @@ files:
159
159
  - firstfm.gemspec
160
160
  - lib/firstfm.rb
161
161
  - lib/firstfm/artist.rb
162
+ - lib/firstfm/configuration.rb
162
163
  - lib/firstfm/event.rb
163
164
  - lib/firstfm/geo.rb
164
165
  - lib/firstfm/image.rb
@@ -197,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
198
  version: '0'
198
199
  segments:
199
200
  - 0
200
- hash: 1482993190146460741
201
+ hash: 2311566496128087561
201
202
  required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  none: false
203
204
  requirements: