beatport 0.1.1

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.
Files changed (70) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +44 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +23 -0
  7. data/Rakefile +55 -0
  8. data/VERSION +1 -0
  9. data/beatport.gemspec +129 -0
  10. data/lib/beatport.rb +15 -0
  11. data/lib/beatport/catalog.rb +93 -0
  12. data/lib/beatport/catalog/account_type.rb +11 -0
  13. data/lib/beatport/catalog/artist.rb +20 -0
  14. data/lib/beatport/catalog/audio_format.rb +10 -0
  15. data/lib/beatport/catalog/audio_format_fee.rb +8 -0
  16. data/lib/beatport/catalog/autocomplete.rb +11 -0
  17. data/lib/beatport/catalog/chart.rb +27 -0
  18. data/lib/beatport/catalog/chart_overview.rb +12 -0
  19. data/lib/beatport/catalog/country.rb +16 -0
  20. data/lib/beatport/catalog/currency.rb +9 -0
  21. data/lib/beatport/catalog/feature.rb +16 -0
  22. data/lib/beatport/catalog/genre.rb +32 -0
  23. data/lib/beatport/catalog/home.rb +13 -0
  24. data/lib/beatport/catalog/image.rb +7 -0
  25. data/lib/beatport/catalog/images.rb +13 -0
  26. data/lib/beatport/catalog/item_type.rb +9 -0
  27. data/lib/beatport/catalog/key.rb +7 -0
  28. data/lib/beatport/catalog/keys.rb +7 -0
  29. data/lib/beatport/catalog/label.rb +29 -0
  30. data/lib/beatport/catalog/list.rb +7 -0
  31. data/lib/beatport/catalog/mixed.rb +9 -0
  32. data/lib/beatport/catalog/recommendations.rb +7 -0
  33. data/lib/beatport/catalog/release.rb +32 -0
  34. data/lib/beatport/catalog/search.rb +11 -0
  35. data/lib/beatport/catalog/slide.rb +17 -0
  36. data/lib/beatport/catalog/slideshow.rb +30 -0
  37. data/lib/beatport/catalog/source_type.rb +9 -0
  38. data/lib/beatport/catalog/state.rb +7 -0
  39. data/lib/beatport/catalog/track.rb +43 -0
  40. data/lib/beatport/client.rb +22 -0
  41. data/lib/beatport/collection.rb +37 -0
  42. data/lib/beatport/inflector.rb +44 -0
  43. data/lib/beatport/item.rb +81 -0
  44. data/lib/beatport/parser.rb +8 -0
  45. data/lib/beatport/price.rb +8 -0
  46. data/lib/beatport/query_builder.rb +74 -0
  47. data/spec/catalog/account_type_spec.rb +16 -0
  48. data/spec/catalog/artist_spec.rb +83 -0
  49. data/spec/catalog/audio_format_spec.rb +14 -0
  50. data/spec/catalog/autocomplete_spec.rb +25 -0
  51. data/spec/catalog/chart_overview_spec.rb +15 -0
  52. data/spec/catalog/chart_spec.rb +96 -0
  53. data/spec/catalog/country_spec.rb +22 -0
  54. data/spec/catalog/currency_spec.rb +13 -0
  55. data/spec/catalog/genre_spec.rb +118 -0
  56. data/spec/catalog/home_spec.rb +16 -0
  57. data/spec/catalog/item_type_spec.rb +11 -0
  58. data/spec/catalog/label_spec.rb +103 -0
  59. data/spec/catalog/mixed_spec.rb +26 -0
  60. data/spec/catalog/release_spec.rb +138 -0
  61. data/spec/catalog/search_spec.rb +24 -0
  62. data/spec/catalog/slide_spec.rb +45 -0
  63. data/spec/catalog/source_type_spec.rb +11 -0
  64. data/spec/catalog/track_spec.rb +173 -0
  65. data/spec/collection_spec.rb +11 -0
  66. data/spec/inflector_spec.rb +34 -0
  67. data/spec/item_spec.rb +11 -0
  68. data/spec/query_builder_spec.rb +100 -0
  69. data/spec/spec_helper.rb +19 -0
  70. metadata +251 -0
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe Country do
5
+ describe 'structure' do
6
+ before(:all) { @country = Country.find('au') }
7
+ it { @country.id.should == 5 }
8
+ it { @country.code.should == "AUS" }
9
+ it { @country.code_short.should == "AU" }
10
+ it { @country.name.should == "Australia" }
11
+ it { @country.vat_enabled.should == false }
12
+ it { @country.vat_rate.should == 0 }
13
+ it { @country.iso3166_3.should == "AUS" }
14
+ it { @country.iso3166_2.should == "AU" }
15
+ it { @country.currency.code.should == "USD" }
16
+ it { @country.currency.name.should == "Dollar" }
17
+ it { @country.states.first.code.should == 'ACT' }
18
+ it { @country.states.first.type.should == 'territory' }
19
+ it { @country.states.first.name.should == "Australian Capital Territory" }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe Currency do
5
+ describe "structure" do
6
+ before(:all) { @currency = Currency.all.first }
7
+ it { @currency.id.should == 1 }
8
+ it { @currency.code.should == "USD" }
9
+ it { @currency.name.should == "Dollar" }
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO improve this
4
+ module Beatport::Catalog
5
+ describe Genre do
6
+
7
+ describe "structure" do
8
+ before(:all) { @genre = Genre.find(7) }
9
+
10
+ it { @genre.name.should == "Trance" }
11
+ it { @genre.slug.should == "trance" }
12
+ it { @genre.subgenres.length.should be > 1}
13
+ it { @genre.slideshow.header.length.should be > 1 }
14
+ it { @genre.slideshow.small.length.should be > 1 }
15
+ it { @genre.top_downloads.length.should be > 1 }
16
+ # it { @genre.features.length.should be > 1}
17
+ end
18
+
19
+ describe '.find' do
20
+ it "should retrieve information about the trance genre via its id" do
21
+ genre = Genre.find(7)
22
+ genre.name.should == "Trance"
23
+ =begin
24
+ genre.features.each do |feature|
25
+ if feature.autoload
26
+ feature.items.length.should be > 1
27
+ feature.items.first.class.to_s.should == "Beatport::Catalog::#{feature.type}"
28
+ end
29
+ end
30
+ =end
31
+ end
32
+
33
+ it "should return nil with an invalid id" do
34
+ genre = Beatport::Catalog.genre(9999999)
35
+ genre.should be nil
36
+ end
37
+ end
38
+
39
+ describe '.all' do
40
+ it "should retrieve all genres" do
41
+ genres = Genre.all
42
+ genres.length.should > 1
43
+ genres.length.should == genres.count
44
+ genres.length.should == genres.per_page
45
+ end
46
+
47
+ it "should retrieve genres with their subgenres" do
48
+ genres = Genre.all(:subgenres => true)
49
+ genres.first.subgenres.length.should be > 1
50
+ end
51
+
52
+ it "should retrieve information about the trance genre via the slug" do
53
+ Genre.all('trance').first.name.should == "Trance"
54
+ end
55
+
56
+ it "should retrieve information about the trance genre via the slug passed as a symbol" do
57
+ Genre.all(:trance).first.name.should == "Trance"
58
+ end
59
+
60
+ it "should retrieve information about the trance genre via its id" do
61
+ Genre.all(7).first.name.should == "Trance"
62
+ end
63
+ end
64
+
65
+ describe '.overview' do
66
+ it "should retrieve an overview" do
67
+ overview = Genre.overview
68
+ overview.length.should be > 0
69
+ overview.each do |genre|
70
+ genre.counts.releases.should be > 0
71
+
72
+ # This fails for glitch hop?
73
+ # genre.list.items.length.should == 3
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ describe '#top_downloads' do
80
+ it "should return the top downloads of a genre loaded via find" do
81
+ genre = Genre.find(7)
82
+ genre.top_downloads.length.should == 10
83
+ end
84
+
85
+ it "should return the top downloads of a genre loaded via all" do
86
+ genre = Genre.all(7).first
87
+ genre.top_downloads.length.should == 10
88
+ end
89
+
90
+ it "should return the same downloads no matter how the genre was loaded" do
91
+ by_find = Genre.find(7)
92
+ by_all = Genre.all(7).first
93
+
94
+ by_find.top_downloads.map(&:id).should == by_all.top_downloads.map(&:id)
95
+ end
96
+ end
97
+
98
+ describe '#slideshow' do
99
+ it "should return the slideshow of a genre loaded via find" do
100
+ genre = Genre.find(7)
101
+ genre.slideshow.header.length.should be > 1
102
+ end
103
+
104
+ it "should return the slideshow of a genre loaded via all" do
105
+ genre = Genre.all(7).first
106
+ genre.slideshow.header.length.should be > 1
107
+ end
108
+
109
+ it "should return the same slideshow no matter how the genre was loaded" do
110
+ by_find = Genre.find(7)
111
+ by_all = Genre.all(7).first
112
+
113
+ by_find.slideshow.header.map(&:link).should == by_all.slideshow.header.map(&:link)
114
+ end
115
+ end
116
+ end
117
+ end
118
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe Home do
5
+ describe '.get' do
6
+ it "should get the home page" do
7
+ home = Home.get
8
+
9
+ home.slideshow.header.length.should be >= 1
10
+ home.slideshow.feature.length.should be > 1
11
+ home.features.length.should be > 1
12
+ home.top_downloads.length.should be > 1
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe ItemType do
5
+ describe "structure" do
6
+ before(:all) { @item_type = ItemType.all.first }
7
+ it { @item_type.id.should == 1 }
8
+ it { @item_type.name.should == "track" }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe Label do
5
+
6
+ describe 'structure' do
7
+ before(:all) { @label = Label.find(1390) }
8
+ it { @label.id.should == 1390 }
9
+ it { @label.type.should == "label" }
10
+ it { @label.name.should == "Anjunadeep" }
11
+ it { @label.slug.should == "anjunadeep" }
12
+ it { @label.source_type.should == ["store", "mobile", "sushi"] }
13
+ it { @label.last_publish_date.should == Date.new(2011, 12, 07) }
14
+ it { @label.biography.should == "" }
15
+ it { @label.genres.length.should be > 1 }
16
+ it { @label.sub_genres.length.should be > 0 }
17
+ it { @label.display_level.should == 1 }
18
+ it { @label.images.small.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/0/0/3000/400/0/3406.jpg"}
19
+ it { @label.images.medium.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/0/0/1000/100/90/1191.jpg"}
20
+ it { @label.images.banner.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/40000/5000/100/50/345152.jpg"}
21
+
22
+ it { @label.top_downloads.length.should be > 1 }
23
+ it { @label.featured_releases.length.should be > 1 }
24
+ it { @label.most_popular_releases.length.should be > 1 }
25
+ end
26
+
27
+ describe '.find' do
28
+ it "should get Anjunadeep give id 1390" do
29
+ label = Label.find(1390)
30
+ label.id.should == 1390
31
+ end
32
+ end
33
+
34
+ describe '.all' do
35
+ it "should get arbitrary labels" do
36
+ labels = Label.all
37
+ labels.length.should == 10
38
+ end
39
+
40
+ it "should get the first page with 5 labels per page" do
41
+ labels = Label.all :per_page => 5, :page => 1
42
+ labels.length.should == 5
43
+ labels.page.should == 1
44
+ labels.per_page.should == 5
45
+ end
46
+
47
+ it "should get the first page with 5 labels per page, sorted by publish date and label id, for the House genre" do
48
+ labels = Label.all(:sort_by=> ['publishDate asc', 'labelId asc'], :genre_id=> 5, :per_page=>5, :page=>1)
49
+ labels.length.should == 5
50
+
51
+ old_id = nil
52
+ old_date = labels.first.last_publish_date
53
+
54
+ labels.each do |label|
55
+ old_id = nil if old_date.to_s != label.last_publish_date.to_s
56
+
57
+ # beatport has some bad genre data?
58
+ # label.genres.map(&:id).should include(5)
59
+ label.id.should be >= old_id if old_id
60
+ label.last_publish_date.should be >= old_date if old_date
61
+
62
+ old_id = label.id
63
+ old_date = label.last_publish_date
64
+ end
65
+ end
66
+
67
+ it "should get arbitrary labels with filter metadata for all genre names and label names" do
68
+ labels = Label.all :return_facets => ['genre_name', 'performer_name']
69
+
70
+ # no worky
71
+ # labels.facets['fields']['performer_name'].count.should be > 1
72
+ labels.facets['fields']['genre_name'].count.should be > 1
73
+ end
74
+
75
+ it "should get all trance labels for above & beyond" do
76
+ labels = Label.all :facets => {:genre_name => ['Trance', 'Progessive House']}
77
+
78
+ labels.each do |label|
79
+ labels = label['labels'].map { |a| a['name'] }
80
+ labels.should include("Above & Beyond")
81
+
82
+ genres = label['genres'].map { |a| a['name'] }
83
+ genres.should include('Trance')
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '.featured' do
89
+ it "should get the featured labels for the Home page" do
90
+ labels = Label.featured
91
+ labels.length.should be > 1
92
+ end
93
+
94
+ it "should get the featured labels for the Trance page" do
95
+ labels = Label.featured :genre_id => 7
96
+ labels.length.should be > 1
97
+ labels.each do |label|
98
+ label.genres.map(&:id).should include(7)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe Mixed do
5
+ describe '.all' do
6
+ before(:all) do
7
+ @results = Mixed.all(
8
+ :label_ids => [804,1390],
9
+ :artist_ids => [7181, 10395],
10
+ :chart_ids => [15722, 29514],
11
+ :release_ids => [164808, 385763],
12
+ :track_ids => [1873426,1746687]
13
+ )
14
+ end
15
+
16
+ it "should return two of each type" do
17
+ @results.map(&:type).should == ['label', 'label', 'artist', 'artist', 'chart', 'chart', 'release', 'release', 'track', 'track']
18
+ end
19
+
20
+ it "should return the right ids" do
21
+ @results.map(&:id).should == [804, 1390, 7181, 10395, 15722, 29514, 164808, 385763, 1746687, 1873426]
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ module Beatport::Catalog
4
+ describe Release do
5
+
6
+ describe 'structure' do
7
+ before(:all) { @release = Release.find(164808) }
8
+ it { @release.id.should == 164808 }
9
+ it { @release.type.should == 'release' }
10
+ it { @release.name.should == "Anjunabeats Volume 6 (Unmixed - DJ Ready)" }
11
+ it { @release.slug.should == 'anjunabeats-volume-6-unmixed-dj-ready'}
12
+ it { @release.release_date.should == Date.new(2009, 04, 06) }
13
+ it { @release.publish_date.should == Date.new(2009, 04, 06) }
14
+ it { @release.exclusive.should == false }
15
+ it { @release.category.should == 'Album' }
16
+ it { @release.current_status.should == "General Content"}
17
+ it { @release.catalog_number.should == "ANJCDCO011D"}
18
+ it { @release.purchasable.should == true }
19
+ it { @release.price.to_s.should == "15.99" }
20
+ it { @release.tracks_price.to_s.should == "43.21" }
21
+ it { @release.audio_format_fee.wav.to_s.should == '29.00'}
22
+ it { @release.audio_format_fee.aiff.to_s.should == '29.00'}
23
+ it { @release.label.id.should == 804 }
24
+ it { @release.artists.map(&:name).should include("Paul Keeley") }
25
+ it { @release.genres.map(&:name).should == ["Trance", "Progressive House"]}
26
+ it { @release.images.small.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/90000/2000/600/90/392699.jpg" }
27
+ it { @release.images.medium.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/90000/2000/700/0/392700.jpg" }
28
+ it { @release.images.large.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/90000/2000/700/0/392701.jpg" }
29
+ it { @release.discount.to_s.should == "27.22" }
30
+ it { @release.recommendations.releases.length.should > 1 }
31
+ end
32
+
33
+ describe '.find' do
34
+ it "should get Anjunabeats Volume 6 when given id 164808" do
35
+ release = Release.find(164808)
36
+ release.id.should == 164808
37
+ end
38
+ end
39
+
40
+ describe '.all' do
41
+ it "should get arbitrary releases" do
42
+ releases = Release.all
43
+ releases.length.should == 10
44
+ end
45
+
46
+ it "should get the first page with 5 releases per page" do
47
+ releases = Release.all :per_page => 5, :page => 1
48
+ releases.length.should == 5
49
+ releases.page.should == 1
50
+ releases.per_page.should == 5
51
+ end
52
+
53
+ it "should get the first page with 5 releases per page, sorted by publish date and release id, for the House genre" do
54
+ releases = Release.all(:sort_by=> ['publishDate asc', 'releaseId asc'], :genre_id=> 5, :per_page=>5, :page=>1)
55
+ releases.length.should == 5
56
+
57
+ old_id = nil
58
+ old_date = releases.first.publish_date
59
+
60
+ releases.each do |release|
61
+ old_id = nil if old_date.to_s != release.publish_date.to_s
62
+
63
+ release.genres.first.id.should == 5
64
+ release.id.should be >= old_id if old_id
65
+ release.publish_date.should be >= old_date if old_date
66
+
67
+ old_id = release.id
68
+ old_date = release.publish_date
69
+ end
70
+ end
71
+
72
+ it "should get arbitrary releases with filter metadata for all genre names and artist names" do
73
+ releases = Release.all :return_facets => ['genre_name', 'performer_name']
74
+
75
+ releases.facets['fields']['performer_name'].count.should be > 1
76
+ releases.facets['fields']['genre_name'].count.should be > 1
77
+ end
78
+
79
+ it "should get all trance releases for above & beyond" do
80
+ releases = Release.all :facets => {:genre_name => 'Trance', :performer_name => 'Above & Beyond'}
81
+
82
+ releases.each do |release|
83
+ artists = release['artists'].map { |a| a['name'] }
84
+ artists.should include("Above & Beyond")
85
+
86
+ genres = release['genres'].map { |a| a['name'] }
87
+ genres.should include('Trance')
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '.featured' do
93
+ it "should get the featured releases for the Home page" do
94
+ releases = Release.featured
95
+ releases.length.should be > 1
96
+ end
97
+
98
+ it "should get the featured releases for the Trance page" do
99
+ releases = Release.featured :genre_id => 7
100
+ releases.length.should be > 1
101
+ releases.each do |release|
102
+ release.genres.map(&:id).should include(7)
103
+ end
104
+ end
105
+
106
+ it "should get 'Just Added' featured releases for the Trance page" do
107
+ releases = Release.featured :genre_id => 7, :just_added => true
108
+ releases.length.should be > 1
109
+ releases.each do |release|
110
+ release.genres.map(&:id).should include(7)
111
+ end
112
+ end
113
+
114
+ it "should not give the same releases with justAdded true and false" do
115
+ featured = Release.featured :genre_id => 7
116
+ just_added = Release.featured :genre_id => 7, :just_added => true
117
+
118
+ featured.map(&:id).should_not == just_added.map(&:id)
119
+ end
120
+ end
121
+
122
+ describe '#tracks' do
123
+ before :all do
124
+ @release = Release.find(164808)
125
+ @tracks = @release.tracks
126
+ end
127
+
128
+ it "should return all 29 tracks for Anjunabeats Volume 6" do
129
+ @tracks.count.should == 29
130
+ end
131
+
132
+ it "should return paper jet as the first track" do
133
+ @tracks.first.name.should == "Paper Jet"
134
+ end
135
+
136
+ end
137
+ end
138
+ end