freesound-ruby 0.0.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.
- data/.document +5 -0
- data/.gitignore +48 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/Rakefile +25 -0
- data/data/sample.json +45 -0
- data/data/sample.xml +46 -0
- data/data/sample.yaml +34 -0
- data/data/sample_query.json +426 -0
- data/freesound-ruby.gemspec +25 -0
- data/lib/core_ext.rb +50 -0
- data/lib/freesound.rb +58 -0
- data/lib/freesound/client.rb +27 -0
- data/lib/freesound/request.rb +27 -0
- data/lib/freesound/response.rb +27 -0
- data/lib/freesound/response_parser.rb +43 -0
- data/lib/freesound/sound.rb +10 -0
- data/lib/freesound/uri_compiler.rb +32 -0
- data/lib/freesound/version.rb +3 -0
- data/spec/core_ext_spec.rb +71 -0
- data/spec/freesound/client_spec.rb +49 -0
- data/spec/freesound/request_spec.rb +26 -0
- data/spec/freesound/response_parser_spec.rb +48 -0
- data/spec/freesound/response_spec.rb +27 -0
- data/spec/freesound/sound_spec.rb +15 -0
- data/spec/freesound/uri_compiler_spec.rb +21 -0
- data/spec/freesound_spec.rb +45 -0
- data/spec/spec_helper.rb +17 -0
- metadata +121 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ResponseParser do
|
4
|
+
it 'initializes with a format' do
|
5
|
+
ResponseParser.new(:xml).format.should == :xml
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#parse' do
|
9
|
+
before do
|
10
|
+
@json = File.read("#{Freesound.root_dir}/data/sample.json")
|
11
|
+
@xml = File.read("#{Freesound.root_dir}/data/sample.xml")
|
12
|
+
@yaml = File.read("#{Freesound.root_dir}/data/sample.yaml")
|
13
|
+
|
14
|
+
@json_parser = ResponseParser.new(:json)
|
15
|
+
@xml_parser = ResponseParser.new(:xml)
|
16
|
+
@yaml_parser = ResponseParser.new(:yaml)
|
17
|
+
|
18
|
+
@json_result = @json_parser.parse(@json)
|
19
|
+
@xml_result = @xml_parser.parse(@xml)
|
20
|
+
@yaml_result = @yaml_parser.parse(@yaml)
|
21
|
+
|
22
|
+
# these are the expected tags if the above files are parsed correctly
|
23
|
+
@tags = [ "transformation", "speech", "voice", "plane", "morph" ]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'parses json' do
|
27
|
+
@json_result[:id].should == 10
|
28
|
+
@json_result[:tags].should == @tags
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'parses xml' do
|
32
|
+
@xml_result[:id].should == 10
|
33
|
+
@xml_result[:tags].should == @tags
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'parses yaml' do
|
37
|
+
@yaml_result[:id].should == 10
|
38
|
+
@yaml_result[:tags].should == @tags
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'parses equal data into equal hashes' do
|
42
|
+
@yaml_result.each_key do |key|
|
43
|
+
@json_result[key].should == @yaml_result[key]
|
44
|
+
@xml_result[key].should == @yaml_result[key]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Response do
|
4
|
+
before do
|
5
|
+
@single = File.read("#{Freesound.root_dir}/data/sample.json")
|
6
|
+
@multiple = File.read("#{Freesound.root_dir}/data/sample_query.json")
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:single) { Response.new(@single) }
|
10
|
+
let(:multiple) { Response.new(@multiple) }
|
11
|
+
|
12
|
+
it 'takes a raw hash' do
|
13
|
+
Response.new('{"id": 3}', :json).data.should == {:id => 3}
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has sounds' do
|
17
|
+
[single, multiple].each do |res|
|
18
|
+
res.sounds.should be_a(Array)
|
19
|
+
res.sounds.first.should be_a(Sound)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has number of results' do
|
24
|
+
single.num_results.should == 1
|
25
|
+
multiple.num_results.should == 12
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Sound do
|
4
|
+
subject { Sound.new }
|
5
|
+
|
6
|
+
it 'has all them attributes' do
|
7
|
+
[ :similarity, :num_ratings, :duration, :samplerate, :preview_hq_ogg, :id,
|
8
|
+
:preview_lq_ogg, :bitdepth, :num_comments, :filesize, :preview_hq_mp3,
|
9
|
+
:type, :analysis_stats, :description, :tags, :serve, :spectral_m,
|
10
|
+
:spectral_l, :user, :bitrate, :num_downloads, :analysis_frames, :channels,
|
11
|
+
:license, :created, :url, :ref, :avg_rating, :preview_lq_mp3,
|
12
|
+
:original_filename, :waveform_l, :waveform_m, :pack
|
13
|
+
].each { |attr| subject.should respond_to(attr) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe URICompiler do
|
4
|
+
describe '#compile_uri_string' do
|
5
|
+
it 'compiles a proper sound-by-id uri' do
|
6
|
+
URICompiler.new({:sound_id => 12, :format => :json}).uri.should ==
|
7
|
+
URI.parse("http://www.freesound.org/api/sounds/12/?api_key=#{Freesound.config.api_key}&format=json")
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'compiles a proper search uri' do
|
11
|
+
URICompiler.new({:search => {:q => 'bass', :p => 2}, :format => :json}).uri.should ==
|
12
|
+
URI.parse("http://www.freesound.org/api/sounds/search/?api_key=#{Freesound.config.api_key}&format=json&q=bass&p=2")
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'adds non-default format parameter' do
|
16
|
+
URICompiler.new({:format => :xml, :sound_id => 12}).uri.should ==
|
17
|
+
URI.parse("http://www.freesound.org/api/sounds/12/?api_key=#{Freesound.config.api_key}&format=xml")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Freesound do
|
4
|
+
describe Configuration do
|
5
|
+
it 'has default configuration parameters' do
|
6
|
+
Freesound::Configuration.sounds_url.should == "http://www.freesound.org/api/sounds"
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'adds configuration parameters' do
|
10
|
+
Freesound::Configuration.api_key = '123abc'
|
11
|
+
Freesound::Configuration.api_key.should == '123abc'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.configure' do
|
16
|
+
it 'takes parameters hash' do
|
17
|
+
Freesound.configure(:api_key => 'test123')
|
18
|
+
Freesound::Configuration.api_key.should == 'test123'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'takes a block and sets parameters' do
|
22
|
+
Freesound.configure do |config|
|
23
|
+
config.api_key = '123abc'
|
24
|
+
config.base_url = 'http://www.example.com'
|
25
|
+
end
|
26
|
+
|
27
|
+
Freesound::Configuration.api_key.should == '123abc'
|
28
|
+
Freesound::Configuration.base_url.should == 'http://www.example.com'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'does both' do
|
32
|
+
Freesound.configure(:api_key => '123') do |config|
|
33
|
+
config.base_url = 'test.url.com'
|
34
|
+
end
|
35
|
+
|
36
|
+
Freesound::Configuration.api_key.should == '123'
|
37
|
+
Freesound::Configuration.base_url.should == 'test.url.com'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'fails with unknown configuration parameters' do
|
41
|
+
expect { Freesound.configure(:api_ley => '123') }.to raise_error(Freesound::InvalidConfigurationParameterError)
|
42
|
+
expect { Freesound.configure { |c| c.api_ley = '123' } }.to raise_error(Freesound::InvalidConfigurationParameterError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'freesound'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
include Freesound
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.before do
|
15
|
+
Freesound::Configuration.api_key = ENV['FREESOUND_KEY'] || fail("Register your app at freesound.org and store your key in the $FREESOUND_KEY variable.")
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: freesound-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Genco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &21019320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *21019320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &21018800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *21018800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
requirement: &21018360 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *21018360
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: crack
|
49
|
+
requirement: &21017880 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *21017880
|
58
|
+
description: Freesound.org API wrapper in Ruby.
|
59
|
+
email:
|
60
|
+
- alexgenco@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- .rspec
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- data/sample.json
|
74
|
+
- data/sample.xml
|
75
|
+
- data/sample.yaml
|
76
|
+
- data/sample_query.json
|
77
|
+
- freesound-ruby.gemspec
|
78
|
+
- lib/core_ext.rb
|
79
|
+
- lib/freesound.rb
|
80
|
+
- lib/freesound/client.rb
|
81
|
+
- lib/freesound/request.rb
|
82
|
+
- lib/freesound/response.rb
|
83
|
+
- lib/freesound/response_parser.rb
|
84
|
+
- lib/freesound/sound.rb
|
85
|
+
- lib/freesound/uri_compiler.rb
|
86
|
+
- lib/freesound/version.rb
|
87
|
+
- spec/core_ext_spec.rb
|
88
|
+
- spec/freesound/client_spec.rb
|
89
|
+
- spec/freesound/request_spec.rb
|
90
|
+
- spec/freesound/response_parser_spec.rb
|
91
|
+
- spec/freesound/response_spec.rb
|
92
|
+
- spec/freesound/sound_spec.rb
|
93
|
+
- spec/freesound/uri_compiler_spec.rb
|
94
|
+
- spec/freesound_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: ''
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project: freesound-ruby
|
116
|
+
rubygems_version: 1.8.11
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Freesound.org API wrapper in Ruby.
|
120
|
+
test_files: []
|
121
|
+
has_rdoc:
|