forked from jrmehle/songkickr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Remote#location_search, LocationResult collection model with tests
- Loading branch information
Showing
8 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Songkickr | ||
class LocationResult | ||
# TODO: very similar to event_result and artist_result, | ||
# extract common stuff to module/superclass | ||
attr_accessor :page, :total_entries, :results | ||
|
||
def initialize(result_hash = {}) | ||
results_page = result_hash["resultsPage"] | ||
|
||
if results_page | ||
@page = results_page["page"] | ||
@total_entries = results_page["totalEntries"] | ||
@results = parse_results results_page["results"] | ||
end | ||
end | ||
|
||
|
||
protected | ||
|
||
def parse_results(results = {}) | ||
locations = [] | ||
if results.include?("location") | ||
results["location"].each do |location| | ||
locations << Songkickr::Location.new(location) | ||
end | ||
end | ||
|
||
locations | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'helper' | ||
|
||
class TestLocation < Test::Unit::TestCase | ||
context "Given Locations from fixture" do | ||
setup do | ||
@locations = Songkickr::LocationResult.new(fixture_hash('locations_bar.json')) | ||
end | ||
|
||
should "properly load data from JSON" do | ||
assert_equal 8, @locations.results.size | ||
assert_equal 8, @locations.total_entries | ||
|
||
potters_bar = @locations.results.first | ||
assert_equal "Potters Bar", potters_bar.city | ||
assert_equal 51.6833, potters_bar.lat | ||
assert_equal -0.166667, potters_bar.lng | ||
end | ||
|
||
end | ||
end |