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/lib/beatport/parser.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
module Beatport
|
2
|
-
# Converts a set of arguments into a format that beatport will understand
|
3
|
-
class QueryBuilder
|
4
|
-
SPECIAL_OPTIONS = ['sortBy', 'facets', 'returnFacets']
|
5
|
-
|
6
|
-
def self.process(*args)
|
7
|
-
new.process(*args)
|
8
|
-
end
|
9
|
-
|
10
|
-
def special_option?(key)
|
11
|
-
SPECIAL_OPTIONS.include?(key)
|
12
|
-
end
|
13
|
-
|
14
|
-
def process(*args)
|
15
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
16
|
-
|
17
|
-
key = options.delete(:key) || (args.length > 1 ? args.compact : args.first)
|
18
|
-
|
19
|
-
case key
|
20
|
-
when Integer
|
21
|
-
options[:id] = key
|
22
|
-
when String, Symbol
|
23
|
-
options[:slug] = key.to_s
|
24
|
-
when Array
|
25
|
-
options[:ids] = key
|
26
|
-
end
|
27
|
-
|
28
|
-
options = camelize_keys(options)
|
29
|
-
|
30
|
-
options.map do |key, value|
|
31
|
-
options[key] = send(Inflector.underscore("process_#{key}"), value) if special_option?(key)
|
32
|
-
end
|
33
|
-
|
34
|
-
options
|
35
|
-
end
|
36
|
-
|
37
|
-
# Camelizes all the keys in the options hash
|
38
|
-
def camelize_keys(options)
|
39
|
-
Inflector.process_keys(options) { |k| Inflector.camelize(k.to_s, false) }
|
40
|
-
end
|
41
|
-
|
42
|
-
def process_sort_by(values)
|
43
|
-
map_values(values) do |value|
|
44
|
-
split_value(value, " ").join(" ")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def process_facets(values)
|
49
|
-
map_values(values) do |value|
|
50
|
-
k, v = split_value(value, ':')
|
51
|
-
v.to_a.map {|v| "#{k}:#{v}"}.join(',')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def process_return_facets(values)
|
56
|
-
map_values(values) do |value|
|
57
|
-
Inflector.camelize(value, false)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def map_values(values)
|
62
|
-
values = values.split(/,\s*/) if values.is_a?(String)
|
63
|
-
values.map do |value|
|
64
|
-
yield value
|
65
|
-
end.join(",")
|
66
|
-
end
|
67
|
-
|
68
|
-
def split_value(value, seperator)
|
69
|
-
value = value.split(seperator) if value.is_a?(String)
|
70
|
-
|
71
|
-
[Inflector.camelize(value.first, false), value.last]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|