songkickr 0.1.3 → 0.1.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -3,9 +3,17 @@ module Songkickr
3
3
  attr_accessor :city, :lat, :lng
4
4
 
5
5
  def initialize(location_hash)
6
- @city = location_hash["city"]
7
- @lat = location_hash["lat"]
8
- @lng = location_hash["lng"]
6
+ if(location_hash["city"].is_a?(String)) # location in Event
7
+ @city = location_hash["city"]
8
+ @lat = location_hash["lat"]
9
+ @lng = location_hash["lng"]
10
+ elsif(location_hash["city"].is_a?(Hash)) # stand-alone Location
11
+ city_hash = location_hash["city"]
12
+ @city = city_hash["displayName"]
13
+ # some locations have a null lng, lat in city hash, but have non-null in metroArea hash
14
+ @lat = city_hash["lat"]
15
+ @lng = city_hash["lng"]
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -0,0 +1,31 @@
1
+ module Songkickr
2
+ class LocationResult
3
+ # TODO: very similar to event_result and artist_result,
4
+ # extract common stuff to module/superclass
5
+ attr_accessor :page, :total_entries, :results
6
+
7
+ def initialize(result_hash = {})
8
+ results_page = result_hash["resultsPage"]
9
+
10
+ if results_page
11
+ @page = results_page["page"]
12
+ @total_entries = results_page["totalEntries"]
13
+ @results = parse_results results_page["results"]
14
+ end
15
+ end
16
+
17
+
18
+ protected
19
+
20
+ def parse_results(results = {})
21
+ locations = []
22
+ if results.include?("location")
23
+ results["location"].each do |location|
24
+ locations << Songkickr::Location.new(location)
25
+ end
26
+ end
27
+
28
+ locations
29
+ end
30
+ end
31
+ end
@@ -50,7 +50,7 @@ module Songkickr
50
50
  # per_page
51
51
  # page
52
52
 
53
- def gigography (artist_id, query= {})
53
+ def gigography(artist_id, query= {})
54
54
  result = self.class.get("/artists/#{artist_id}/gigography.json",:query=>query)
55
55
  Songkickr::EventResult.new result
56
56
  end
@@ -98,6 +98,16 @@ module Songkickr
98
98
  Songkickr::ConcertSetlistResult.new result
99
99
  end
100
100
 
101
+ # Parameters - http://www.songkick.com/developer/location-search
102
+ #
103
+ # location - 'geo:{lat,lng}' string
104
+ # query - name of location to search for
105
+
106
+ def location_search(query = {})
107
+ result = self.class.get("/search/locations.json",:query=>query)
108
+ Songkickr::LocationResult.new result
109
+ end
110
+
101
111
  private
102
112
 
103
113
  def extract_path_from_query(query = {})
data/lib/songkickr.rb CHANGED
@@ -6,6 +6,7 @@ dir = File.dirname(__FILE__)
6
6
  require dir + '/songkickr/performance'
7
7
  require dir + '/songkickr/artist'
8
8
  require dir + '/songkickr/location'
9
+ require dir + '/songkickr/location_result'
9
10
  require dir + '/songkickr/venue'
10
11
  require dir + '/songkickr/event'
11
12
  require dir + '/songkickr/setlist_item'
data/songkickr.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{songkickr}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jared Mehle"]
12
- s.date = %q{2011-05-11}
12
+ s.date = %q{2011-05-17}
13
13
  s.description = %q{A Ruby wrapper around the Songkick API. Visit www.songkick.com/developer for documentation on the Songkick API. }
14
14
  s.email = %q{jrmehle@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/songkickr/event.rb",
30
30
  "lib/songkickr/event_result.rb",
31
31
  "lib/songkickr/location.rb",
32
+ "lib/songkickr/location_result.rb",
32
33
  "lib/songkickr/performance.rb",
33
34
  "lib/songkickr/remote.rb",
34
35
  "lib/songkickr/setlist.rb",
@@ -39,10 +40,12 @@ Gem::Specification.new do |s|
39
40
  "test/fixtures/event_7391451.json",
40
41
  "test/fixtures/events.json",
41
42
  "test/fixtures/invalid_api_key.json",
43
+ "test/fixtures/locations_bar.json",
42
44
  "test/fixtures/no_events.json",
43
45
  "test/helper.rb",
44
46
  "test/songkickr/test_artist.rb",
45
47
  "test/songkickr/test_event.rb",
48
+ "test/songkickr/test_location.rb",
46
49
  "test/songkickr/test_remote.rb",
47
50
  "test/test_songkickr.rb"
48
51
  ]
@@ -54,6 +57,7 @@ Gem::Specification.new do |s|
54
57
  "test/helper.rb",
55
58
  "test/songkickr/test_artist.rb",
56
59
  "test/songkickr/test_event.rb",
60
+ "test/songkickr/test_location.rb",
57
61
  "test/songkickr/test_remote.rb",
58
62
  "test/test_songkickr.rb"
59
63
  ]
@@ -0,0 +1 @@
1
+ {"resultsPage":{"results":{"location":[{"city":{"displayName":"Potters Bar","country":{"displayName":"UK"},"lng":-0.166667,"lat":51.6833},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/24426-uk-london?utm_source=4961&utm_medium=partner","displayName":"London","country":{"displayName":"UK"},"id":24426,"lng":-0.128,"lat":51.5078}},{"city":{"displayName":"Diamond Bar","country":{"displayName":"US"},"lng":-117.809,"lat":34.0286,"state":{"displayName":"CA"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/17835-us-los-angeles?utm_source=4961&utm_medium=partner","displayName":"Los Angeles","country":{"displayName":"US"},"id":17835,"lng":-118.376,"lat":34.0862,"state":{"displayName":"CA"}}},{"city":{"displayName":"Old Bar","country":{"displayName":"Australia"},"lng":null,"lat":null,"state":{"displayName":"NSW"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/26791-australia-newcastle?utm_source=4961&utm_medium=partner","displayName":"Newcastle","country":{"displayName":"Australia"},"id":26791,"lng":151.75,"lat":-32.9167,"state":{"displayName":"NSW"}}},{"city":{"displayName":"Bar Haven","country":{"displayName":"Canada"},"lng":null,"lat":null,"state":{"displayName":"NL"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/33223-canada-saint-johns?utm_source=4961&utm_medium=partner","displayName":"Saint John's","country":{"displayName":"Canada"},"id":33223,"lng":-52.6667,"lat":47.55,"state":{"displayName":"NL"}}},{"city":{"displayName":"Gold Bar","country":{"displayName":"Canada"},"lng":null,"lat":null,"state":{"displayName":"BC"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/27383-canada-prince-george?utm_source=4961&utm_medium=partner","displayName":"Prince George","country":{"displayName":"Canada"},"id":27383,"lng":-122.767,"lat":53.9167,"state":{"displayName":"BC"}}},{"city":{"displayName":"Bar Harbor","country":{"displayName":"US"},"lng":null,"lat":null,"state":{"displayName":"ME"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/78086-us-bar-harbor?utm_source=4961&utm_medium=partner","displayName":"Bar Harbor","country":{"displayName":"US"},"id":78086,"lng":null,"lat":null,"state":{"displayName":"ME"}}},{"city":{"displayName":"Marble Bar","country":{"displayName":"Australia"},"lng":null,"lat":null,"state":{"displayName":"WA"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/43434-australia-marble-bar?utm_source=4961&utm_medium=partner","displayName":"Marble Bar","country":{"displayName":"Australia"},"id":43434,"lng":null,"lat":null,"state":{"displayName":"WA"}}},{"city":{"displayName":"Jimble Bar Mining Centre","country":{"displayName":"Australia"},"lng":null,"lat":null,"state":{"displayName":"WA"}},"metroArea":{"uri":"http:\/\/www.songkick.com\/metro_areas\/42274-australia-jimble-bar-mining-centre?utm_source=4961&utm_medium=partner","displayName":"Jimble Bar Mining Centre","country":{"displayName":"Australia"},"id":42274,"lng":null,"lat":null,"state":{"displayName":"WA"}}}]},"totalEntries":8,"perPage":50,"page":1,"status":"ok"}}
data/test/helper.rb CHANGED
@@ -23,6 +23,10 @@ def fixture_file(filename)
23
23
  File.read(file_path)
24
24
  end
25
25
 
26
+ def fixture_hash(filename)
27
+ Crack::JSON.parse(fixture_file(filename))
28
+ end
29
+
26
30
  def stub_get(url, filename, status = nil)
27
31
  options = {:body => fixture_file(filename)}
28
32
  options.merge!({:status => status}) unless status.nil?
@@ -3,8 +3,7 @@ require 'helper'
3
3
  class TestArtist < Test::Unit::TestCase
4
4
  context "Given an Event from fixture" do
5
5
  setup do
6
- fixture_hash = Crack::JSON.parse(fixture_file('event_7391451.json')) # extract to helper?
7
- @event = Songkickr::Event.new(fixture_hash["resultsPage"]["results"]["event"])
6
+ @event = Songkickr::Event.new(fixture_hash('event_7391451.json')["resultsPage"]["results"]["event"])
8
7
  end
9
8
 
10
9
  should "properly load data from JSON" do
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class TestLocation < Test::Unit::TestCase
4
+ context "Given Locations from fixture" do
5
+ setup do
6
+ @locations = Songkickr::LocationResult.new(fixture_hash('locations_bar.json'))
7
+ end
8
+
9
+ should "properly load data from JSON" do
10
+ assert_equal 8, @locations.results.size
11
+ assert_equal 8, @locations.total_entries
12
+
13
+ potters_bar = @locations.results.first
14
+ assert_equal "Potters Bar", potters_bar.city
15
+ assert_equal 51.6833, potters_bar.lat
16
+ assert_equal -0.166667, potters_bar.lng
17
+ end
18
+
19
+ end
20
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: songkickr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jared Mehle
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-11 00:00:00 Z
18
+ date: 2011-05-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: shoulda
@@ -55,6 +55,7 @@ files:
55
55
  - lib/songkickr/event.rb
56
56
  - lib/songkickr/event_result.rb
57
57
  - lib/songkickr/location.rb
58
+ - lib/songkickr/location_result.rb
58
59
  - lib/songkickr/performance.rb
59
60
  - lib/songkickr/remote.rb
60
61
  - lib/songkickr/setlist.rb
@@ -65,10 +66,12 @@ files:
65
66
  - test/fixtures/event_7391451.json
66
67
  - test/fixtures/events.json
67
68
  - test/fixtures/invalid_api_key.json
69
+ - test/fixtures/locations_bar.json
68
70
  - test/fixtures/no_events.json
69
71
  - test/helper.rb
70
72
  - test/songkickr/test_artist.rb
71
73
  - test/songkickr/test_event.rb
74
+ - test/songkickr/test_location.rb
72
75
  - test/songkickr/test_remote.rb
73
76
  - test/test_songkickr.rb
74
77
  homepage: http://github.com/jrmehle/songkickr
@@ -108,5 +111,6 @@ test_files:
108
111
  - test/helper.rb
109
112
  - test/songkickr/test_artist.rb
110
113
  - test/songkickr/test_event.rb
114
+ - test/songkickr/test_location.rb
111
115
  - test/songkickr/test_remote.rb
112
116
  - test/test_songkickr.rb