beatport 0.1.1 → 0.1.2
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 +1 -1
- data/beatport.gemspec +9 -8
- data/lib/beatport.rb +1 -3
- data/lib/beatport/catalog/account_type.rb +7 -1
- data/lib/beatport/catalog/artist.rb +8 -5
- data/lib/beatport/catalog/audio_format.rb +5 -0
- data/lib/beatport/catalog/autocomplete.rb +1 -1
- data/lib/beatport/catalog/chart.rb +12 -6
- data/lib/beatport/catalog/country.rb +1 -1
- data/lib/beatport/catalog/feature.rb +1 -1
- data/lib/beatport/catalog/genre.rb +10 -6
- data/lib/beatport/catalog/label.rb +5 -5
- data/lib/beatport/catalog/mixed.rb +1 -1
- data/lib/beatport/catalog/release.rb +10 -5
- data/lib/beatport/catalog/search.rb +1 -1
- data/lib/beatport/catalog/slide.rb +3 -3
- data/lib/beatport/catalog/track.rb +18 -12
- data/lib/beatport/client.rb +9 -3
- data/lib/beatport/collection.rb +1 -1
- data/lib/beatport/support.rb +7 -0
- data/lib/beatport/support/inflector.rb +47 -0
- data/lib/beatport/support/parser.rb +10 -0
- data/lib/beatport/support/query_builder.rb +88 -0
- data/spec/catalog/account_type_spec.rb +29 -8
- data/spec/catalog/artist_spec.rb +41 -18
- data/spec/catalog/audio_format_spec.rb +23 -5
- data/spec/catalog/autocomplete_spec.rb +23 -14
- data/spec/catalog/chart_overview_spec.rb +4 -5
- data/spec/catalog/chart_spec.rb +37 -18
- data/spec/catalog/country_spec.rb +16 -14
- data/spec/catalog/currency_spec.rb +6 -4
- data/spec/catalog/genre_spec.rb +24 -50
- data/spec/catalog/home_spec.rb +7 -8
- data/spec/catalog/item_type_spec.rb +5 -3
- data/spec/catalog/label_spec.rb +20 -19
- data/spec/catalog/mixed_spec.rb +4 -4
- data/spec/catalog/release_spec.rb +26 -24
- data/spec/catalog/source_type_spec.rb +5 -3
- data/spec/catalog/track_spec.rb +31 -30
- data/spec/{inflector_spec.rb → support/inflector_spec.rb} +1 -1
- data/spec/{query_builder_spec.rb → support/query_builder_spec.rb} +13 -19
- metadata +10 -9
- data/lib/beatport/inflector.rb +0 -44
- data/lib/beatport/parser.rb +0 -8
- data/lib/beatport/query_builder.rb +0 -74
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/beatport.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{beatport}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mateo Murphy"]
|
12
|
-
s.date = %q{2011-12-
|
12
|
+
s.date = %q{2011-12-21}
|
13
13
|
s.description = %q{A ruby gem for accessing the beatport api}
|
14
14
|
s.email = %q{mateo.murphy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -58,11 +58,12 @@ Gem::Specification.new do |s|
|
|
58
58
|
"lib/beatport/catalog/track.rb",
|
59
59
|
"lib/beatport/client.rb",
|
60
60
|
"lib/beatport/collection.rb",
|
61
|
-
"lib/beatport/inflector.rb",
|
62
61
|
"lib/beatport/item.rb",
|
63
|
-
"lib/beatport/parser.rb",
|
64
62
|
"lib/beatport/price.rb",
|
65
|
-
"lib/beatport/
|
63
|
+
"lib/beatport/support.rb",
|
64
|
+
"lib/beatport/support/inflector.rb",
|
65
|
+
"lib/beatport/support/parser.rb",
|
66
|
+
"lib/beatport/support/query_builder.rb",
|
66
67
|
"spec/catalog/account_type_spec.rb",
|
67
68
|
"spec/catalog/artist_spec.rb",
|
68
69
|
"spec/catalog/audio_format_spec.rb",
|
@@ -82,10 +83,10 @@ Gem::Specification.new do |s|
|
|
82
83
|
"spec/catalog/source_type_spec.rb",
|
83
84
|
"spec/catalog/track_spec.rb",
|
84
85
|
"spec/collection_spec.rb",
|
85
|
-
"spec/inflector_spec.rb",
|
86
86
|
"spec/item_spec.rb",
|
87
|
-
"spec/
|
88
|
-
"spec/
|
87
|
+
"spec/spec_helper.rb",
|
88
|
+
"spec/support/inflector_spec.rb",
|
89
|
+
"spec/support/query_builder_spec.rb"
|
89
90
|
]
|
90
91
|
s.homepage = %q{http://github.com/mateomurphy/beatport}
|
91
92
|
s.licenses = ["MIT"]
|
data/lib/beatport.rb
CHANGED
@@ -7,9 +7,7 @@ module Beatport
|
|
7
7
|
autoload :Catalog, 'beatport/catalog'
|
8
8
|
autoload :Client, 'beatport/client'
|
9
9
|
autoload :Collection, 'beatport/collection'
|
10
|
-
autoload :Inflector, 'beatport/inflector'
|
11
10
|
autoload :Item, 'beatport/item'
|
12
|
-
autoload :Parser, 'beatport/parser'
|
13
11
|
autoload :Price, 'beatport/price'
|
14
|
-
autoload :
|
12
|
+
autoload :Support, 'beatport/support'
|
15
13
|
end
|
@@ -3,9 +3,15 @@ module Beatport
|
|
3
3
|
class AccountType < Item
|
4
4
|
has_one :images, Images
|
5
5
|
|
6
|
+
# Returns the account type with the name given
|
7
|
+
def self.find(key)
|
8
|
+
Client.retrieve 'account-types', AccountType, :key => key
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns all the account types
|
6
12
|
def self.all
|
7
13
|
Client.retrieve 'account-types', AccountType
|
8
|
-
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
@@ -5,16 +5,19 @@ module Beatport
|
|
5
5
|
has_many :subgenres, Genre
|
6
6
|
has_one :images, Images
|
7
7
|
has_many :top_downloads, Track
|
8
|
-
has_many :featured_releases, Release
|
8
|
+
# has_many :featured_releases, Release
|
9
9
|
|
10
|
-
def self.find(
|
11
|
-
Client.retrieve
|
10
|
+
def self.find(*args)
|
11
|
+
Client.retrieve 'artists', Artist, *args
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.all(
|
15
|
-
Client.retrieve 'artists', Artist,
|
14
|
+
def self.all(options = {})
|
15
|
+
Client.retrieve 'artists', Artist, options
|
16
16
|
end
|
17
17
|
|
18
|
+
def top_downloads(options = {})
|
19
|
+
@top_downloads ||= Track.most_popular_for_artist(id, options)
|
20
|
+
end
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -2,6 +2,11 @@ module Beatport
|
|
2
2
|
module Catalog
|
3
3
|
class AudioFormat < Item
|
4
4
|
|
5
|
+
# Returns the audio format with the name given
|
6
|
+
def self.find(key)
|
7
|
+
Client.retrieve 'audio-formats', AudioFormat, :key => key
|
8
|
+
end
|
9
|
+
|
5
10
|
def self.all
|
6
11
|
Client.retrieve 'audio-formats', AudioFormat
|
7
12
|
end
|
@@ -7,12 +7,12 @@ module Beatport
|
|
7
7
|
has_one :price, Price
|
8
8
|
has_many :tracks, Track
|
9
9
|
|
10
|
-
def self.find(
|
11
|
-
Client.retrieve
|
10
|
+
def self.find(*keys)
|
11
|
+
Client.retrieve 'charts', Chart, *keys
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.all(
|
15
|
-
Client.retrieve 'charts', Chart,
|
14
|
+
def self.all(options = {})
|
15
|
+
Client.retrieve 'charts', Chart, options
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.overview
|
@@ -20,8 +20,14 @@ module Beatport
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.featured(*args)
|
23
|
-
Client.retrieve
|
24
|
-
end
|
23
|
+
Client.retrieve 'featured/charts', Chart, *args
|
24
|
+
end
|
25
|
+
|
26
|
+
def tracks(options = {})
|
27
|
+
options[:chart_id] = id
|
28
|
+
@tracks ||= Track.all(options)
|
29
|
+
end
|
30
|
+
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -6,7 +6,7 @@ module Beatport
|
|
6
6
|
attr_reader :items
|
7
7
|
|
8
8
|
def initialize(data = {})
|
9
|
-
item_klass = Inflector.constantize("Beatport::Catalog::#{data['type']}")
|
9
|
+
item_klass = Support::Inflector.constantize("Beatport::Catalog::#{data['type']}")
|
10
10
|
|
11
11
|
associate(data, 'items', true, item_klass)
|
12
12
|
super
|
@@ -8,22 +8,26 @@ module Beatport
|
|
8
8
|
has_one :counts, Item
|
9
9
|
has_one :list, List
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# Returns the genre with the given id or slug
|
12
|
+
def self.find(key)
|
13
|
+
Client.retrieve 'genres', Genre, :key => key, :string_key_type => :slug, :subgenres => true
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
# Returns all the genres
|
17
|
+
def self.all(options = {})
|
18
|
+
Client.retrieve 'genres', Genre, options
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.overview
|
20
|
-
Client.retrieve
|
22
|
+
Client.retrieve 'genres/overview', Genre
|
21
23
|
end
|
22
|
-
|
24
|
+
|
25
|
+
# Returns the top downloads for the genre
|
23
26
|
def top_downloads
|
24
27
|
@top_downloads ||= Track.most_popular_for_genre(id)
|
25
28
|
end
|
26
29
|
|
30
|
+
# Returns the slideshow for the genre
|
27
31
|
def slideshow
|
28
32
|
@slideshow ||= Slideshow.find(id)
|
29
33
|
end
|
@@ -8,16 +8,16 @@ module Beatport
|
|
8
8
|
has_many :most_popular_releases, Release
|
9
9
|
has_one :images, Images
|
10
10
|
|
11
|
-
def self.find(
|
12
|
-
Client.retrieve
|
11
|
+
def self.find(*args)
|
12
|
+
Client.retrieve 'labels', Label, *args
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.all(
|
16
|
-
Client.retrieve
|
15
|
+
def self.all(options = {})
|
16
|
+
Client.retrieve 'labels', Label, options
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.featured(*args)
|
20
|
-
Client.retrieve
|
20
|
+
Client.retrieve 'featured/labels', Label, *args
|
21
21
|
end
|
22
22
|
|
23
23
|
def releases(options)
|
@@ -15,16 +15,21 @@ module Beatport
|
|
15
15
|
tracks_price - price
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.find(
|
19
|
-
Client.retrieve
|
18
|
+
def self.find(*args)
|
19
|
+
Client.retrieve 'releases', Release, *args
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.all(
|
23
|
-
Client.retrieve
|
22
|
+
def self.all(options={})
|
23
|
+
Client.retrieve 'releases', Release, options
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.featured(*args)
|
27
|
-
Client.retrieve
|
27
|
+
Client.retrieve 'featured/releases', Release, *args
|
28
|
+
end
|
29
|
+
|
30
|
+
def tracks(options = {})
|
31
|
+
options[:release_id] = id
|
32
|
+
@tracks ||= Track.all(options)
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -2,15 +2,15 @@ module Beatport
|
|
2
2
|
module Catalog
|
3
3
|
class Slide < Item
|
4
4
|
def self.header(*args)
|
5
|
-
Client.retrieve
|
5
|
+
Client.retrieve 'slideshows/header', Slide, *args
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.feature(*args)
|
9
|
-
Client.retrieve
|
9
|
+
Client.retrieve 'slideshows/feature', Slide, *args
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.small(*args)
|
13
|
-
Client.retrieve
|
13
|
+
Client.retrieve 'slideshows/small', Slide, *args
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -13,29 +13,35 @@ module Beatport
|
|
13
13
|
has_one :key, Keys
|
14
14
|
|
15
15
|
# Returns the track with the given id
|
16
|
-
def self.find(
|
17
|
-
Client.retrieve
|
16
|
+
def self.find(key)
|
17
|
+
Client.retrieve 'tracks', Track, :key => key
|
18
18
|
end
|
19
19
|
|
20
20
|
# Returns all the tracks matching the criterea
|
21
|
-
def self.all(
|
22
|
-
Client.retrieve 'tracks', Track,
|
21
|
+
def self.all(options = {})
|
22
|
+
Client.retrieve 'tracks', Track, options
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.most_popular(
|
26
|
-
Client.retrieve 'most-popular', Track,
|
25
|
+
def self.most_popular(options = {})
|
26
|
+
Client.retrieve 'most-popular', Track, options
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.most_popular_for_genre(
|
30
|
-
|
29
|
+
def self.most_popular_for_genre(id, options = {})
|
30
|
+
options[:id] = id
|
31
|
+
options[:collection] = true
|
32
|
+
Client.retrieve "most-popular/genre", Track, options
|
31
33
|
end
|
32
34
|
|
33
|
-
def self.most_popular_for_artist(
|
34
|
-
|
35
|
+
def self.most_popular_for_artist(id, options = {})
|
36
|
+
options[:id] = id
|
37
|
+
options[:collection] = true
|
38
|
+
Client.retrieve "most-popular/artist", Track, options
|
35
39
|
end
|
36
40
|
|
37
|
-
def self.most_popular_for_label(
|
38
|
-
|
41
|
+
def self.most_popular_for_label(id, options = {})
|
42
|
+
options[:id] = id
|
43
|
+
options[:collection] = true
|
44
|
+
Client.retrieve "most-popular/label", Track, options
|
39
45
|
end
|
40
46
|
|
41
47
|
end
|
data/lib/beatport/client.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
module Beatport
|
2
2
|
module Client
|
3
3
|
include HTTParty
|
4
|
-
parser Beatport::Parser
|
4
|
+
parser Beatport::Support::Parser
|
5
5
|
base_uri "http://api.beatport.com/catalog/3"
|
6
6
|
format :json
|
7
7
|
# default_params :v => '1.0', :format => 'json'
|
8
8
|
|
9
9
|
def self.retrieve(path, klass, *args)
|
10
|
-
|
10
|
+
builder = Support::QueryBuilder.new
|
11
|
+
|
12
|
+
result = get("/#{path}", :query => builder.process(*args))
|
11
13
|
|
12
14
|
case result['results']
|
13
15
|
when Array
|
14
|
-
|
16
|
+
if builder.single_result?
|
17
|
+
klass.new(result['results'].first) if result['results'].any?
|
18
|
+
else
|
19
|
+
Collection.new(klass, result)
|
20
|
+
end
|
15
21
|
when Hash
|
16
22
|
klass.new(result['results'])
|
17
23
|
else
|
data/lib/beatport/collection.rb
CHANGED
@@ -21,7 +21,7 @@ module Beatport
|
|
21
21
|
|
22
22
|
@results = if klass == :auto
|
23
23
|
data['results'].map do |r|
|
24
|
-
item_klass = Inflector.constantize("Beatport::Catalog::#{r['type'].capitalize}")
|
24
|
+
item_klass = Support::Inflector.constantize("Beatport::Catalog::#{r['type'].capitalize}")
|
25
25
|
item_klass.new(r)
|
26
26
|
end
|
27
27
|
else
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Beatport
|
2
|
+
module Support
|
3
|
+
module Inflector
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def constantize(camel_cased_word)
|
7
|
+
names = camel_cased_word.split('::')
|
8
|
+
names.shift if names.empty? || names.first.empty?
|
9
|
+
|
10
|
+
constant = Object
|
11
|
+
names.each do |name|
|
12
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
13
|
+
end
|
14
|
+
constant
|
15
|
+
end
|
16
|
+
|
17
|
+
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
18
|
+
if first_letter_in_uppercase
|
19
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
20
|
+
else
|
21
|
+
lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def underscore(camel_cased_word)
|
26
|
+
word = camel_cased_word.to_s.dup
|
27
|
+
word.gsub!(/::/, '/')
|
28
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
29
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
30
|
+
word.tr!("-", "_")
|
31
|
+
word.downcase!
|
32
|
+
word
|
33
|
+
end
|
34
|
+
|
35
|
+
def process_keys(obj, &block)
|
36
|
+
case obj
|
37
|
+
when Hash
|
38
|
+
Hash[obj.map {|k, v| [yield(k), process_keys(v, &block)]}]
|
39
|
+
when Array
|
40
|
+
obj.map {|o| process_keys(o, &block)}
|
41
|
+
else
|
42
|
+
obj
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|