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,10 @@
1
+ module Beatport
2
+ module Catalog
3
+ class AudioFormat < Item
4
+
5
+ def self.all
6
+ Client.retrieve 'audio-formats', AudioFormat
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Beatport
2
+ module Catalog
3
+ class AudioFormatFee < Item
4
+ has_one :wav, Price
5
+ has_one :aiff, Price
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Autocomplete < Item
4
+ def self.query(query, options = {})
5
+ options['query'] = query
6
+
7
+ Client.retrieve('autocomplete', Autocomplete, options)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Chart < Item
4
+ has_one :audio_format_fee, AudioFormatFee
5
+ has_many :genres, Genre
6
+ has_one :images, Images
7
+ has_one :price, Price
8
+ has_many :tracks, Track
9
+
10
+ def self.find(id)
11
+ Client.retrieve('charts/detail', Chart, :id => id)
12
+ end
13
+
14
+ def self.all(*args)
15
+ Client.retrieve 'charts', Chart, *args
16
+ end
17
+
18
+ def self.overview
19
+ ChartOverview.get
20
+ end
21
+
22
+ def self.featured(*args)
23
+ Client.retrieve('featured/charts', Chart, *args)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module Beatport
2
+ module Catalog
3
+ class ChartOverview < Item
4
+ has_many :newest, Chart
5
+ has_many :featured, Chart
6
+
7
+ def self.get
8
+ Client.retrieve 'charts/overview', ChartOverview
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Country < Item
4
+ has_one :currency, Currency
5
+ has_many :states, State
6
+
7
+ def self.all
8
+ Client.retrieve 'countries', Country
9
+ end
10
+
11
+ def self.find(code)
12
+ Client.retrieve('countries', Country, :code_short => code).first
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Currency < Item
4
+ def self.all
5
+ Client.retrieve 'currencies', Currency
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ #TODO deprecated in latest api version?
2
+ module Beatport
3
+ module Catalog
4
+ class Feature < Item
5
+ # associated this manually since we don't know the type of the items by default
6
+ attr_reader :items
7
+
8
+ def initialize(data = {})
9
+ item_klass = Inflector.constantize("Beatport::Catalog::#{data['type']}")
10
+
11
+ associate(data, 'items', true, item_klass)
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Genre < Item
4
+ has_many :subgenres, Genre
5
+ # has_many :top_downloads, Track
6
+ # has_one :slideshow, Slideshow
7
+ # has_many :features, Feature
8
+ has_one :counts, Item
9
+ has_one :list, List
10
+
11
+ def self.find(id)
12
+ Client.retrieve('genres', Genre, :id => id, :subgenres => true).first
13
+ end
14
+
15
+ def self.all(*args)
16
+ Client.retrieve('genres', Genre, *args)
17
+ end
18
+
19
+ def self.overview
20
+ Client.retrieve('genres/overview', Genre)
21
+ end
22
+
23
+ def top_downloads
24
+ @top_downloads ||= Track.most_popular_for_genre(id)
25
+ end
26
+
27
+ def slideshow
28
+ @slideshow ||= Slideshow.find(id)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Home < Item
4
+ has_one :slideshow, Slideshow
5
+ has_many :features, Feature
6
+ has_many :top_downloads, Track
7
+
8
+ def self.get
9
+ Client.retrieve 'home', Home
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Image < Item
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Images
4
+ attr_reader :small, :medium, :large, :waveform, :banner
5
+
6
+ def initialize(images)
7
+ images.each do |format, data|
8
+ instance_variable_set(:"@#{format}", Image.new(data))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Beatport
2
+ module Catalog
3
+ class ItemType < Item
4
+ def self.all
5
+ Client.retrieve 'item-types', ItemType
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Key < Item
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Keys < Item
4
+ has_one :standard, Key
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Label < Item
4
+ has_many :genres, Genre
5
+ has_many :subgenres, Genre
6
+ has_many :top_downloads, Track
7
+ has_many :featured_releases, Release
8
+ has_many :most_popular_releases, Release
9
+ has_one :images, Images
10
+
11
+ def self.find(id)
12
+ Client.retrieve('labels/detail', Label, :id => id)
13
+ end
14
+
15
+ def self.all(*args)
16
+ Client.retrieve('labels', Label, *args)
17
+ end
18
+
19
+ def self.featured(*args)
20
+ Client.retrieve('featured/labels', Label, *args)
21
+ end
22
+
23
+ def releases(options)
24
+ options[:label_id] = id
25
+ Release.all(options)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Beatport
2
+ module Catalog
3
+ class List < Item
4
+ has_many :items, Release
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Mixed
4
+ def self.all(options = {})
5
+ Client.retrieve('mixed', :auto, options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Recommendations < Item
4
+ has_many :releases, Release
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Release < Item
4
+ has_many :artists, Artist
5
+ has_one :audio_format_fee, AudioFormatFee
6
+ has_many :genres, Genre
7
+ has_one :images, Images
8
+ has_one :label, Label
9
+ has_one :price, Price
10
+ has_one :recommendations, Recommendations
11
+ has_many :tracks, Track
12
+ has_one :tracks_price, Price
13
+
14
+ def discount
15
+ tracks_price - price
16
+ end
17
+
18
+ def self.find(id)
19
+ Client.retrieve('releases/detail', Release, :id => id)
20
+ end
21
+
22
+ def self.all(*args)
23
+ Client.retrieve('releases', Release, *args)
24
+ end
25
+
26
+ def self.featured(*args)
27
+ Client.retrieve('featured/releases', Release, *args)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,11 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Search
4
+ def self.query(query, options = {})
5
+ options['query'] = query
6
+
7
+ Client.retrieve('search', :auto, options)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Slide < Item
4
+ def self.header(*args)
5
+ Client.retrieve('slideshows/header', Slide, *args)
6
+ end
7
+
8
+ def self.feature(*args)
9
+ Client.retrieve('slideshows/feature', Slide, *args)
10
+ end
11
+
12
+ def self.small(*args)
13
+ Client.retrieve('slideshows/small', Slide, *args)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Slideshow < Item
4
+ attr_accessor :genre_id
5
+
6
+ has_many :header, Slide
7
+ has_many :feature, Slide
8
+ has_many :small, Slide
9
+
10
+ def self.find(id = nil)
11
+ obj = Slideshow.new
12
+ obj.genre_id = id
13
+ obj
14
+ end
15
+
16
+ def header
17
+ @header ||= Slide.header(:genre_id => genre_id)
18
+ end
19
+
20
+ def feature
21
+ @feature ||= Slide.feature(:genre_id => genre_id)
22
+ end
23
+
24
+ def small
25
+ @small ||= Slide.small(:genre_id => genre_id)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module Beatport
2
+ module Catalog
3
+ class SourceType < Item
4
+ def self.all
5
+ Client.retrieve 'source-types', SourceType
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Beatport
2
+ module Catalog
3
+ class State < Item
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ module Beatport
2
+ module Catalog
3
+ class Track < Item
4
+ has_many :genres, Genre
5
+ has_many :sub_genres, Genre
6
+ has_many :artists, Artist
7
+ has_many :charts, Chart
8
+ has_one :release, Release
9
+ has_one :label, Label
10
+ has_one :price, Price
11
+ has_one :images, Images
12
+ has_one :audio_format_fee, AudioFormatFee
13
+ has_one :key, Keys
14
+
15
+ # Returns the track with the given id
16
+ def self.find(id)
17
+ Client.retrieve('tracks', Track, :id => id).first
18
+ end
19
+
20
+ # Returns all the tracks matching the criterea
21
+ def self.all(*args)
22
+ Client.retrieve 'tracks', Track, *args
23
+ end
24
+
25
+ def self.most_popular(*args)
26
+ Client.retrieve 'most-popular', Track, *args
27
+ end
28
+
29
+ def self.most_popular_for_genre(*args)
30
+ Client.retrieve "most-popular/genre", Track, *args
31
+ end
32
+
33
+ def self.most_popular_for_artist(*args)
34
+ Client.retrieve "most-popular/artist", Track, *args
35
+ end
36
+
37
+ def self.most_popular_for_label(*args)
38
+ Client.retrieve "most-popular/label", Track, *args
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ module Beatport
2
+ module Client
3
+ include HTTParty
4
+ parser Beatport::Parser
5
+ base_uri "http://api.beatport.com/catalog/3"
6
+ format :json
7
+ # default_params :v => '1.0', :format => 'json'
8
+
9
+ def self.retrieve(path, klass, *args)
10
+ result = get("/#{path}", :query => QueryBuilder.process(*args))
11
+
12
+ case result['results']
13
+ when Array
14
+ Collection.new(klass, result)
15
+ when Hash
16
+ klass.new(result['results'])
17
+ else
18
+ raise "results is an unexpected class #{result['results'].class}"
19
+ end
20
+ end
21
+ end
22
+ end