acoustid-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTNhNzg1MTY2MTgyNTEyYWFjZTQzYzAyNjQ0NzA1YzQyNTQ1ZTU0YQ==
5
+ data.tar.gz: !binary |-
6
+ OWQ1ZTBhNTE1OGUwZGMxYTRhYTU1ZjRlMWI4OTRiYWE4Y2EyZTI1MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDczMTBjMmYxOTlmOGQ4ZDI2MTMyODc5MGQyNGVhZGQ1MDY2N2Y4MWNmNTY4
10
+ MmUwZTMxZDMyZTE2YmYyNTFkYmI5MjQ1YzYxZjRkOTAzZmE3NjYyNGNhOGZi
11
+ YWIxZDU5YzUzMzVhOWUzOTYwZDYwNWNmM2U1ODM3YzBhODI3ZTU=
12
+ data.tar.gz: !binary |-
13
+ Zjk1OGE5OTJmYjljOTc4N2U1MWNkODZjNzdiODY1MjBhZWNkNWMxNjkyNjJj
14
+ OTJlZTgxMjBiNTI4N2Q3MDcxNTVlOTQyNDg4ZTY3MDI5Yzc4NGE4MzJlZmZk
15
+ YjI2Y2Q0M2IwM2IxMmJkNzQ3Njk1OTFhMjZhYzM5NDY0ZTI4Zjc=
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acoustid-api (0.0.0)
5
+ httpi (~> 2.1.0)
6
+ version (~> 1.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ httpi (2.1.0)
12
+ rack
13
+ rubyntlm (~> 0.3.2)
14
+ rack (1.5.2)
15
+ rubyntlm (0.3.4)
16
+ version (1.0.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ acoustid-api!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Ryan Scott Lewis <ryan@rynet.us>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ require 'pathname'
2
+ require 'rake/version_task'
3
+ require 'rubygems/package_task'
4
+
5
+ gemspec = Pathname.glob( Pathname.new(__FILE__).join('..', '*.gemspec') ).first
6
+ $spec = Gem::Specification.load( gemspec.to_s )
7
+
8
+ Gem::PackageTask.new($spec) do |task|
9
+ task.need_zip = false
10
+ end
11
+
12
+ Rake::VersionTask.new do |task|
13
+ task.with_git_tag = true
14
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,25 @@
1
+ require 'pathname'
2
+
3
+ Gem::Specification.new do |s|
4
+
5
+ # Variables
6
+ s.author = 'Ryan Scott Lewis'
7
+ s.email = 'ryan@rynet.us'
8
+ s.summary = 'A simple HTTP interface to the Acoustid.org API.'
9
+ s.license = 'MIT'
10
+
11
+ # Dependencies
12
+ s.add_dependency 'httpi', '~> 2.1.0'
13
+ s.add_dependency 'version', '~> 1.0.0'
14
+ # s.add_development_dependency 'awesome_print', '~> 1.1.0'
15
+
16
+ # Pragmatically set variables
17
+ s.homepage = "http://github.com/RyanScottLewis/#{s.name}"
18
+ s.version = Pathname.glob('VERSION*').first.read rescue '0.0.0'
19
+ s.description = s.summary
20
+ s.name = Pathname.new(__FILE__).basename('.gemspec').to_s
21
+ s.require_paths = ['lib']
22
+ s.files = Dir['{{Rake,Gem}file{.lock,},README*,VERSION,LICENSE,*.gemspec,{lib,bin,examples,spec,test}/**/*}']
23
+ s.test_files = Dir['{examples,spec,test}/**/*']
24
+
25
+ end
@@ -0,0 +1,129 @@
1
+ require 'version'
2
+ require 'httpi'
3
+
4
+ module Acoustid
5
+
6
+ module API
7
+
8
+ is_versioned
9
+
10
+ class << self
11
+
12
+ def lookup(options={})
13
+ options = parse_options(options)
14
+
15
+ require 'acoustid/api/request/lookup'
16
+
17
+ request = Request::Lookup.new( options[:params] )
18
+
19
+ send( options[:method], request, options[:adapter] )
20
+ end
21
+
22
+ def get(request, http_adapter=nil)
23
+ raise TypeError unless request.is_a?(Request::Base)
24
+
25
+ http_request = HTTPI::Request.new( url: request.uri, query: request.params )
26
+
27
+ HTTPI.get(http_request, http_adapter)
28
+ end
29
+
30
+ def post(request, adapter=nil)
31
+ raise TypeError unless request.is_a?(Request::Base)
32
+
33
+ http_request = HTTPI::Request.new( url: request.uri, body: request.params )
34
+
35
+ HTTPI.post(http_request, adapter)
36
+ end
37
+
38
+ protected
39
+
40
+ def parse_options(options={})
41
+ raise TypeError, 'options must respond to :to_hash or :to_h' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h)
42
+ options = options.to_hash rescue options.to_h
43
+
44
+ options = { method: :post }.merge(options)
45
+
46
+ raise TypeError, 'option :method must respond_to :to_sym' unless options[:method].respond_to?(:to_sym)
47
+ options[:method] = options[:method].to_s.strip.to_sym
48
+ raise TypeError, 'option :method must be either :get or :post' unless [:get, :post].include?( options[:method] )
49
+
50
+ raise TypeError, 'option :params must respond to :to_hash or :to_h' unless options[:params].respond_to?(:to_hash) || options[:params].respond_to?(:to_h)
51
+ options[:params] = options[:params].to_hash rescue options[:params].to_h
52
+
53
+ raise TypeError, 'option :adapter must respond_to :to_sym or be nil' unless options[:adapter].nil? || options[:adapter].respond_to?(:to_sym)
54
+ options[:adapter] = options[:adapter].to_s.strip.to_sym unless options[:adapter].nil?
55
+
56
+ options
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ # request = Acoustid::API.lookup(params: { client: 'omgomg' })
66
+
67
+ __END__
68
+
69
+ Lookup by fingerprint
70
+ http://api.acoustid.org/v2/lookup
71
+
72
+ Name Required Values Description
73
+ format no json, jsonp, xml response format
74
+ jsoncallback no jsonAcoustidApi
75
+ client yes 8XaBELgH application's API key
76
+ duration yes 641 duration of the whole audio file in seconds
77
+ fingerprint yes AQABz0qUkZ... audio fingerprint data
78
+ meta no recordings, recordingids, releases, releaseids, releasegroups, releasegroupids, tracks, compress, usermeta, sources returned metadata
79
+
80
+ Lookup by track ID
81
+ http://api.acoustid.org/v2/lookup
82
+
83
+ Name Required Values Description
84
+ format no json, jsonp, xml response format
85
+ jsoncallback no jsonAcoustidApi JSONP callback, only applicable if you select the jsonp format
86
+ client yes 8XaBELgH application's API key
87
+ trackid yes 9ff43b6a-4f16-427c-93c2-92307ca505e0 track id (UUID)
88
+ meta no recordings, recordingids, releases, releaseids, releasegroups, releasegroupids, tracks, compress, usermeta, sources returned metadata
89
+
90
+ Submit
91
+ http://api.acoustid.org/v2/submit
92
+
93
+ Name Required Values Description
94
+ format no json, xml response format
95
+ client yes 8XaBELgH application's API key
96
+ clientversion no 1.0 application's version
97
+ wait no 1 wait up to N seconds for the submission(s) to import
98
+ user yes 9Hg1oNwY users's API key
99
+ duration.# yes 641 duration of the whole audio file in seconds
100
+ fingerprint.# yes AQABz0qUkZ... audio fingerprint data
101
+ bitrate.# no 192 bitrate of the audio file
102
+ fileformat.# no MP3, M4A, ... file format of the audio file
103
+ mbid.# no 4e0d8649-1f89-44f3-91af-4c0dbee81f28 corresponding MusicBrainz track ID
104
+ track.# no High Hopes track title
105
+ artist.# no Pink Floyd track artist
106
+ album.# no The Division Bell album title
107
+ albumartist.# no Pink Floyd album artist
108
+ year.# no 1994 album release year
109
+ trackno.# no 11 track number
110
+ discno.# no 1 disc number
111
+
112
+ Get submission status (TODO: MIGHT HAVE TYPE IN URL!)
113
+ http://api.acoustid.org/v2/submision_status
114
+
115
+ Name Required Values Description
116
+ format no json, xml response format
117
+ client yes 8XaBELgH application's API key
118
+ clientversion no 1.0 application's version
119
+ id yes 123456789 submission ID, can be used multiple times
120
+
121
+
122
+ List AcoustIDs by MBID
123
+ http://api.acoustid.org/v2/track/list_by_mbid
124
+
125
+ Name Required Values Description
126
+ format no json, jsonp, xml response format
127
+ jsoncallback no jsonAcoustidApi JSONP callback, only applicable if you select the jsonp format
128
+ mbid yes 4e0d8649-1f89-44f3-91af-4c0dbee81f28 corresponding MusicBrainz recording ID (can be sent multiple times)
129
+ batch no 0, 1 use if you want to lookup multiple MBIDs
@@ -0,0 +1,60 @@
1
+ require 'uri'
2
+ require 'acoustid/api/request/param_attributes'
3
+ require 'acoustid/api/request/param_validations'
4
+
5
+ module Acoustid
6
+ module API
7
+ module Request
8
+
9
+ class Base
10
+
11
+ extend ParamAttributes
12
+ extend ParamValidations
13
+
14
+ class << self
15
+
16
+ def base_uri
17
+ URI.parse('http://api.acoustid.org/v2/')
18
+ end
19
+
20
+ def path(value=nil)
21
+ @path = value.to_s.strip unless value.nil?
22
+
23
+ @path
24
+ end
25
+
26
+ end
27
+
28
+ attr_reader :params
29
+
30
+ # Response format
31
+ param :format, validate: :validate_format, serialize: :serialize_string
32
+
33
+ def initialize(params={})
34
+ raise TypeError, 'params must respond to :to_hash or :to_h' unless params.respond_to?(:to_hash) || params.respond_to?(:to_h)
35
+ params = params.to_hash rescue params.to_h
36
+
37
+ params.each { |param, value| send("#{param}=", value) }
38
+ end
39
+
40
+ def uri
41
+ uri = self.class.base_uri.dup
42
+ uri.path += self.class.path
43
+
44
+ uri
45
+ end
46
+
47
+ def valid?
48
+ self.class.required_params.none? do |required_param|
49
+ param = send(required_param)
50
+
51
+ param.nil? || param.empty?# rescue true
52
+ end
53
+ end
54
+
55
+
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,47 @@
1
+ require 'acoustid/api/request/base'
2
+
3
+ module Acoustid
4
+ module API
5
+ module Request
6
+
7
+ class Lookup < Base
8
+
9
+ path 'lookup'
10
+
11
+ # JSONP callback, only applicable if you select the jsonp format
12
+ param :json_callback, name: 'jsoncallback', serialize: :serialize_string
13
+
14
+ # Application's API key
15
+ param :client, required: true, serialize: :serialize_string
16
+
17
+ # Duration of the whole audio file in seconds
18
+ # Only required if trackid is not present
19
+ param :duration, validate: :validate_duration, serialize: :serialize_integer
20
+
21
+ # Audio fingerprint data
22
+ # Only required if trackid is not present
23
+ param :fingerprint, serialize: :serialize_string
24
+
25
+ # Track ID (UUID)
26
+ # Only required if duration and fingerprint are not present
27
+ param :track_id, name: 'trackid', serialize: :serialize_string
28
+
29
+ # Returned metadata
30
+ param :meta, validate: :validate_meta, serialize: :serialize_meta
31
+
32
+ # Different logic is needed for the validation of this API method
33
+ def valid?
34
+ invalid_duration = duration.nil?
35
+ invalid_fingerprint = fingerprint.nil? || fingerprint.empty?
36
+ invalid_track_id = track_id.nil? || track_id.empty?
37
+
38
+ invalid_duration_and_fingerprint = invalid_duration && invalid_fingerprint
39
+
40
+ super && (!invalid_duration_and_fingerprint && invalid_track_id || invalid_duration_and_fingerprint && !invalid_track_id)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,61 @@
1
+ module Acoustid
2
+ module API
3
+ module Request
4
+
5
+ module ParamAttributes
6
+
7
+ def param_reader(param, options={})
8
+ raise TypeError, 'param must respond to :to_sym' unless param.respond_to?(:to_sym)
9
+ param = param.to_sym
10
+
11
+ raise TypeError, 'options must respond to :to_hash or :to_h' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h)
12
+ options = options.to_hash rescue options.to_h
13
+
14
+ name = options[:name].to_s.strip
15
+ name = name.empty? ? param.to_s : name
16
+
17
+ define_method(param) { (@params ||= {})[name] }
18
+ end
19
+
20
+ def param_writer(param, options={})
21
+ raise TypeError, 'param must respond to :to_sym' unless param.respond_to?(:to_sym)
22
+ param = param.to_sym
23
+
24
+ raise TypeError, 'options must respond to :to_hash or :to_h' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h)
25
+ options = options.to_hash rescue options.to_h
26
+
27
+ name = options[:name].to_s.strip
28
+ name = name.empty? ? param.to_s : name
29
+
30
+ required_params << param if options[:required]
31
+
32
+ raise TypeError, 'validate options must respond to :call or :to_sym' unless options[:validate].nil? || options[:validate].respond_to?(:call) || options[:validate].respond_to?(:to_sym)
33
+ validate = options[:validate]
34
+ validate = method(validate) if validate.respond_to?(:to_sym)
35
+
36
+ raise TypeError, 'serialize options must respond to :call or :to_sym' unless options[:serialize].nil? || options[:serialize].respond_to?(:call) || options[:serialize].respond_to?(:to_sym)
37
+ serialize = options[:serialize]
38
+ serialize = method(serialize) if serialize.respond_to?(:to_sym)
39
+
40
+ define_method("#{param}=") do |value|
41
+ validate.call(value) unless validate.nil?
42
+ value = serialize.call(value) unless serialize.nil?
43
+
44
+ (@params ||= {})[name] = value
45
+ end
46
+ end
47
+
48
+ def param(name, options={})
49
+ param_reader(name, options)
50
+ param_writer(name, options)
51
+ end
52
+
53
+ def required_params
54
+ @required_params ||= []
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,40 @@
1
+ module Acoustid
2
+ module API
3
+ module Request
4
+
5
+ module ParamValidations
6
+
7
+ VALID_META_VALUES = %W[recordings recordingids releases releaseids releasegroups releasegroupids tracks compress usermeta sources]
8
+
9
+ def serialize_string(value)
10
+ value.nil? ? nil : value.to_s.strip
11
+ end
12
+
13
+ def serialize_integer(value)
14
+ value.nil? ? nil : value.to_i
15
+ end
16
+
17
+ def serialize_meta(value)
18
+ value.nil? ? nil : value.to_a.collect { |value| value.to_s.strip }
19
+ end
20
+
21
+ def validate_format(value)
22
+ raise ArgumentError, '' unless %W[json jsonp xml].include?(value.to_s.strip)
23
+ end
24
+
25
+ def validate_duration(value)
26
+ raise TypeError, 'duration must respond to :to_i' unless value.respond_to?(:to_i)
27
+ end
28
+
29
+ def validate_meta(value)
30
+ raise TypeError, 'meta must respond to :to_a or be nil' unless value.nil? || value.respond_to?(:to_a)
31
+ raise TypeError, "meta must only include #{ VALID_META_VALUES.join(', ') }" unless value.nil? || serialize_meta(value).all? { |meta| VALID_META_VALUES.include?(meta) }
32
+
33
+ # TODO
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acoustid-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Scott Lewis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: version
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ description: A simple HTTP interface to the Acoustid.org API.
42
+ email: ryan@rynet.us
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - LICENSE
50
+ - Rakefile
51
+ - VERSION
52
+ - acoustid-api.gemspec
53
+ - lib/acoustid/api.rb
54
+ - lib/acoustid/api/request/base.rb
55
+ - lib/acoustid/api/request/lookup.rb
56
+ - lib/acoustid/api/request/param_attributes.rb
57
+ - lib/acoustid/api/request/param_validations.rb
58
+ - lib/acoustid/api/request/submit.rb
59
+ - lib/acoustid/api/response.rb
60
+ homepage: http://github.com/RyanScottLewis/
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A simple HTTP interface to the Acoustid.org API.
84
+ test_files: []