beatport 0.1.10 → 0.2.0

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/Gemfile CHANGED
@@ -3,7 +3,8 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gem 'httparty'
6
+ gem 'addressable'
7
+ gem 'signet'
7
8
  gem 'money', '~> 5.1.1' # https://github.com/RubyMoney/money
8
9
 
9
10
  # Add dependencies to develop your gem here.
data/README.md CHANGED
@@ -8,6 +8,16 @@ Currently incomplete, but under development.
8
8
 
9
9
  [![Dependency Status](https://gemnasium.com/mateomurphy/beatport.png)](https://gemnasium.com/mateomurphy/beatport)
10
10
 
11
+ ## Oauth
12
+
13
+ Beatport's api now requires authentication via Oauth. This means you now need to provide the gem
14
+ you oauth credentials to make requests, for example in a rails initializer:
15
+
16
+ Beatport.consumer_key = 'consumer_key'
17
+ Beatport.consumer_secret = 'consumer_secret'
18
+ Beatport.access_token_key = 'access_token_key'
19
+ Beatport.access_token_secret = 'access_token_secret'
20
+
11
21
  ## Facets
12
22
 
13
23
  Many queries to beatport support facets, but they aren't properly documentated on their site. These are the ones I've found so far:
@@ -19,8 +29,9 @@ Many queries to beatport support facets, but they aren't properly documentated o
19
29
  ## Examples
20
30
 
21
31
  ```ruby
22
- require 'beatport'
23
- # Search using the query "Mord Fustang" on Beatport
32
+ require 'beatport'
33
+
34
+ # Search using the query "Mord Fustang" on Beatport
24
35
  query = Beatport::Catalog::Search.query("Mord Fustang")
25
36
 
26
37
  query.class # => returns a Beatport::Collection object
@@ -34,7 +45,7 @@ require 'beatport'
34
45
  # Note that search results change frequently, so first result may not
35
46
  necessarily be a Beatport::Catalog::Artist object
36
47
 
37
- # Find top downloads for a given genre
48
+ # Find top downloads for a given genre
38
49
  genres = Beatport::Catalog::Genre.all # => list all genres
39
50
  # display each genre and its corresponding Beatport genre slug
40
51
 
@@ -54,9 +65,7 @@ require 'beatport'
54
65
 
55
66
  # An alternative for searching for genre by slug is searching by genre ID
56
67
  trance_genre = Beatport::Catalog::Genre.find(7) # => returns a Trance Genre object
57
-
58
-
59
- ```
68
+ ```
60
69
 
61
70
  ## Contributing to beatport
62
71
 
@@ -70,6 +79,6 @@ require 'beatport'
70
79
 
71
80
  ## Copyright
72
81
 
73
- Copyright (c) 2011-2012 Mateo Murphy. See LICENSE.txt for
82
+ Copyright (c) 2011-2013 Mateo Murphy. See LICENSE.txt for
74
83
  further details.
75
84
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.2.0
data/beatport.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "beatport"
8
- s.version = "0.1.10"
8
+ s.version = "0.2.0"
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 = "2013-08-14"
12
+ s.date = "2013-08-31"
13
13
  s.description = "A ruby gem for accessing the beatport api"
14
14
  s.email = "mateo.murphy@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".rspec",
22
22
  "Gemfile",
23
- "Gemfile.lock",
24
23
  "LICENSE.txt",
25
24
  "README.md",
26
25
  "Rakefile",
@@ -61,6 +60,8 @@ Gem::Specification.new do |s|
61
60
  "lib/beatport/catalog/track.rb",
62
61
  "lib/beatport/client.rb",
63
62
  "lib/beatport/collection.rb",
63
+ "lib/beatport/config.rb",
64
+ "lib/beatport/error.rb",
64
65
  "lib/beatport/item.rb",
65
66
  "lib/beatport/price.rb",
66
67
  "lib/beatport/support.rb",
@@ -87,21 +88,6 @@ Gem::Specification.new do |s|
87
88
  "spec/catalog/source_type_spec.rb",
88
89
  "spec/catalog/track_spec.rb",
89
90
  "spec/collection_spec.rb",
90
- "spec/fixtures/account_type.yml",
91
- "spec/fixtures/artist.yml",
92
- "spec/fixtures/audio_format.yml",
93
- "spec/fixtures/autocomplete.yml",
94
- "spec/fixtures/chart.yml",
95
- "spec/fixtures/country.yml",
96
- "spec/fixtures/currency.yml",
97
- "spec/fixtures/genre.yml",
98
- "spec/fixtures/item_type.yml",
99
- "spec/fixtures/label.yml",
100
- "spec/fixtures/mixed.yml",
101
- "spec/fixtures/release.yml",
102
- "spec/fixtures/search.yml",
103
- "spec/fixtures/source_type.yml",
104
- "spec/fixtures/track.yml",
105
91
  "spec/item_spec.rb",
106
92
  "spec/price_spec.rb",
107
93
  "spec/spec_helper.rb",
@@ -118,7 +104,8 @@ Gem::Specification.new do |s|
118
104
  s.specification_version = 3
119
105
 
120
106
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
121
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
107
+ s.add_runtime_dependency(%q<addressable>, [">= 0"])
108
+ s.add_runtime_dependency(%q<signet>, [">= 0"])
122
109
  s.add_runtime_dependency(%q<money>, ["~> 5.1.1"])
123
110
  s.add_development_dependency(%q<bundler>, [">= 0"])
124
111
  s.add_development_dependency(%q<webmock>, [">= 0"])
@@ -128,7 +115,8 @@ Gem::Specification.new do |s|
128
115
  s.add_development_dependency(%q<yard>, [">= 0"])
129
116
  s.add_development_dependency(%q<vcr>, [">= 0"])
130
117
  else
131
- s.add_dependency(%q<httparty>, [">= 0"])
118
+ s.add_dependency(%q<addressable>, [">= 0"])
119
+ s.add_dependency(%q<signet>, [">= 0"])
132
120
  s.add_dependency(%q<money>, ["~> 5.1.1"])
133
121
  s.add_dependency(%q<bundler>, [">= 0"])
134
122
  s.add_dependency(%q<webmock>, [">= 0"])
@@ -139,7 +127,8 @@ Gem::Specification.new do |s|
139
127
  s.add_dependency(%q<vcr>, [">= 0"])
140
128
  end
141
129
  else
142
- s.add_dependency(%q<httparty>, [">= 0"])
130
+ s.add_dependency(%q<addressable>, [">= 0"])
131
+ s.add_dependency(%q<signet>, [">= 0"])
143
132
  s.add_dependency(%q<money>, ["~> 5.1.1"])
144
133
  s.add_dependency(%q<bundler>, [">= 0"])
145
134
  s.add_dependency(%q<webmock>, [">= 0"])
data/lib/beatport.rb CHANGED
@@ -1,15 +1,19 @@
1
1
  # http://api.beatport.com/index.html
2
2
  require 'ostruct'
3
- require 'httparty'
3
+ require 'signet/oauth_1/client'
4
4
  require 'money'
5
5
 
6
6
  module Beatport
7
7
  autoload :Catalog, 'beatport/catalog'
8
+ autoload :Config, 'beatport/config'
8
9
  autoload :Client, 'beatport/client'
9
10
  autoload :Collection, 'beatport/collection'
10
11
  autoload :Item, 'beatport/item'
11
12
  autoload :Price, 'beatport/price'
12
13
  autoload :Support, 'beatport/support'
14
+ autoload :Error, 'beatport/error'
15
+
16
+ extend Config
13
17
 
14
18
  def self.const_missing(name)
15
19
  if Beatport::Catalog.const_defined?(name)
@@ -1,15 +1,35 @@
1
1
  module Beatport
2
2
  module Client
3
- include HTTParty
4
- parser Beatport::Support::Parser
5
- base_uri "http://api.beatport.com/catalog/3"
6
- format :json
7
- # default_params :v => '1.0', :format => 'json'
3
+ def self.client
4
+ @client ||= Signet::OAuth1::Client.new(
5
+ :client_credential_key => Beatport.consumer_key,
6
+ :client_credential_secret => Beatport.consumer_secret,
7
+ :token_credential_key => Beatport.access_token_key,
8
+ :token_credential_secret => Beatport.access_token_secret
9
+ )
10
+ end
11
+
12
+ def self.builder
13
+ @builder ||= Support::QueryBuilder.new
14
+ end
8
15
 
9
16
  def self.retrieve(path, klass, *args)
10
- builder = Support::QueryBuilder.new
17
+ uri = Addressable::URI.new(
18
+ :scheme => 'https',
19
+ :host => 'api.beatport.com',
20
+ :path => "/catalog/3/#{path}",
21
+ :query_values => builder.process(*args)
22
+ )
11
23
 
12
- result = get("/#{path}", :query => builder.process(*args))
24
+ result = client.fetch_protected_resource(:uri => uri.to_s)
25
+ result = JSON.parse(result.body)
26
+
27
+ # underscore result keys
28
+ result = Support::Inflector.process_keys(result) { |k| Support::Inflector.underscore(k) }
29
+
30
+ if result['metadata']['error']
31
+ raise Error.new("#{result['metadata']['error']}: #{result['metadata']['message']}")
32
+ end
13
33
 
14
34
  case result['results']
15
35
  when Array
@@ -21,7 +41,7 @@ module Beatport
21
41
  when Hash
22
42
  klass.new(result['results'])
23
43
  else
24
- raise "results is an unexpected class #{result['results'].class}"
44
+ raise Error.new("results is an unexpected class #{result['results'].class}")
25
45
  end
26
46
  end
27
47
  end
@@ -0,0 +1,8 @@
1
+ module Beatport
2
+ module Config
3
+ attr_accessor :consumer_key
4
+ attr_accessor :consumer_secret
5
+ attr_accessor :access_token_key
6
+ attr_accessor :access_token_secret
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Beatport
2
+ class Error < StandardError
3
+
4
+ end
5
+ end
@@ -2,7 +2,7 @@ module Beatport
2
2
  module Support
3
3
  # Converts a set of arguments into a format that beatport will understand
4
4
  class QueryBuilder
5
- SPECIAL_OPTIONS = ['sortBy', 'facets', 'returnFacets']
5
+ SPECIAL_OPTIONS = ['sortBy', 'facets', 'returnFacets', 'subgenres']
6
6
 
7
7
  def single_result?
8
8
  @single_result
@@ -37,8 +37,13 @@ module Beatport
37
37
 
38
38
  options = camelize_keys(options)
39
39
 
40
+ # Handle special options that need to be generated in a specific manner
40
41
  options.map do |key, value|
41
- options[key] = send(Inflector.underscore("process_#{key}"), value) if special_option?(key)
42
+ if special_option?(key)
43
+ options[key] = send(Inflector.underscore("process_#{key}"), value)
44
+ elsif value.is_a?(Array)
45
+ options[key] = value.join(',')
46
+ end
42
47
  end
43
48
 
44
49
  options
@@ -71,6 +76,12 @@ module Beatport
71
76
  end
72
77
  end
73
78
 
79
+ # Special processing for subgenres
80
+ def process_subgenres(value)
81
+ value ? 'true' : 'false'
82
+ end
83
+
84
+ # Map values delimited by ,
74
85
  def map_values(values)
75
86
  values = values.split(/,\s*/) if values.is_a?(String)
76
87
  values.map do |value|
@@ -11,7 +11,7 @@ module Beatport::Catalog
11
11
  end
12
12
 
13
13
  describe 'structure' do
14
- subject do
14
+ subject :account_type do
15
15
  AccountType.all.first
16
16
  end
17
17
 
@@ -48,7 +48,7 @@ module Beatport::Catalog
48
48
  end
49
49
 
50
50
  context 'with an array of ids' do
51
- subject { Artist.find(7181, 7182) }
51
+ subject { Artist.find([7181, 7182]) }
52
52
 
53
53
  # it { should be_a(Collection) }
54
54
  its (:length) { should == 2 }
@@ -13,11 +13,11 @@ module Beatport::Catalog
13
13
  describe '.all' do
14
14
  subject do
15
15
  Mixed.all(
16
- :label_ids => [804,1390],
16
+ :label_ids => [804, 1390],
17
17
  :artist_ids => [7181, 10395],
18
18
  :chart_ids => [15722, 29514],
19
19
  :release_ids => [164808, 385763],
20
- :track_ids => [1873426,1746687]
20
+ :track_ids => [1873426, 1746687]
21
21
  )
22
22
  end
23
23
 
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,8 @@ require 'beatport'
14
14
  require 'pp'
15
15
  require 'log_buddy'
16
16
  require 'vcr'
17
+ require 'config'
18
+
17
19
 
18
20
  VCR.configure do |c|
19
21
  c.cassette_library_dir = 'spec/fixtures'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beatport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,26 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-14 00:00:00.000000000 Z
12
+ date: 2013-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: httparty
15
+ name: addressable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: signet
16
32
  requirement: !ruby/object:Gem::Requirement
17
33
  none: false
18
34
  requirements:
@@ -166,7 +182,6 @@ files:
166
182
  - .document
167
183
  - .rspec
168
184
  - Gemfile
169
- - Gemfile.lock
170
185
  - LICENSE.txt
171
186
  - README.md
172
187
  - Rakefile
@@ -207,6 +222,8 @@ files:
207
222
  - lib/beatport/catalog/track.rb
208
223
  - lib/beatport/client.rb
209
224
  - lib/beatport/collection.rb
225
+ - lib/beatport/config.rb
226
+ - lib/beatport/error.rb
210
227
  - lib/beatport/item.rb
211
228
  - lib/beatport/price.rb
212
229
  - lib/beatport/support.rb
@@ -233,21 +250,6 @@ files:
233
250
  - spec/catalog/source_type_spec.rb
234
251
  - spec/catalog/track_spec.rb
235
252
  - spec/collection_spec.rb
236
- - spec/fixtures/account_type.yml
237
- - spec/fixtures/artist.yml
238
- - spec/fixtures/audio_format.yml
239
- - spec/fixtures/autocomplete.yml
240
- - spec/fixtures/chart.yml
241
- - spec/fixtures/country.yml
242
- - spec/fixtures/currency.yml
243
- - spec/fixtures/genre.yml
244
- - spec/fixtures/item_type.yml
245
- - spec/fixtures/label.yml
246
- - spec/fixtures/mixed.yml
247
- - spec/fixtures/release.yml
248
- - spec/fixtures/search.yml
249
- - spec/fixtures/source_type.yml
250
- - spec/fixtures/track.yml
251
253
  - spec/item_spec.rb
252
254
  - spec/price_spec.rb
253
255
  - spec/spec_helper.rb
@@ -268,7 +270,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
268
270
  version: '0'
269
271
  segments:
270
272
  - 0
271
- hash: 3099949540174036320
273
+ hash: -3985965663943551168
272
274
  required_rubygems_version: !ruby/object:Gem::Requirement
273
275
  none: false
274
276
  requirements:
data/Gemfile.lock DELETED
@@ -1,52 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- addressable (2.3.2)
5
- crack (0.3.2)
6
- diff-lcs (1.1.3)
7
- git (1.2.5)
8
- httparty (0.10.2)
9
- multi_json (~> 1.0)
10
- multi_xml (>= 0.5.2)
11
- i18n (0.6.5)
12
- jeweler (1.8.4)
13
- bundler (~> 1.0)
14
- git (>= 1.2.5)
15
- rake
16
- rdoc
17
- json (1.7.6)
18
- log_buddy (0.7.0)
19
- money (5.1.1)
20
- i18n (~> 0.6.0)
21
- multi_json (1.5.0)
22
- multi_xml (0.5.3)
23
- rake (10.0.3)
24
- rdoc (3.12.1)
25
- json (~> 1.4)
26
- rspec (2.12.0)
27
- rspec-core (~> 2.12.0)
28
- rspec-expectations (~> 2.12.0)
29
- rspec-mocks (~> 2.12.0)
30
- rspec-core (2.12.2)
31
- rspec-expectations (2.12.1)
32
- diff-lcs (~> 1.1.3)
33
- rspec-mocks (2.12.2)
34
- vcr (2.4.0)
35
- webmock (1.9.0)
36
- addressable (>= 2.2.7)
37
- crack (>= 0.1.7)
38
- yard (0.8.4.1)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- bundler
45
- httparty
46
- jeweler
47
- log_buddy
48
- money (~> 5.1.1)
49
- rspec
50
- vcr
51
- webmock
52
- yard