miniphonic 0.1.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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +34 -0
  5. data/LICENSE +20 -0
  6. data/README.md +145 -0
  7. data/Rakefile +19 -0
  8. data/lib/miniphonic/api_object.rb +96 -0
  9. data/lib/miniphonic/helpers.rb +51 -0
  10. data/lib/miniphonic/info.rb +68 -0
  11. data/lib/miniphonic/preset.rb +17 -0
  12. data/lib/miniphonic/preset_attributes.rb +53 -0
  13. data/lib/miniphonic/production.rb +33 -0
  14. data/lib/miniphonic/production_attributes.rb +66 -0
  15. data/lib/miniphonic/response.rb +5 -0
  16. data/lib/miniphonic/version.rb +3 -0
  17. data/lib/miniphonic.rb +40 -0
  18. data/miniphonic.gemspec +29 -0
  19. data/test/spec/api_object_spec.rb +164 -0
  20. data/test/spec/cassettes/info/algorithms.yml +170 -0
  21. data/test/spec/cassettes/info/info.yml +740 -0
  22. data/test/spec/cassettes/info/output_files.yml +343 -0
  23. data/test/spec/cassettes/info/service_types.yml +263 -0
  24. data/test/spec/cassettes/info/services.yml +125 -0
  25. data/test/spec/cassettes/info/status_codes.yml +70 -0
  26. data/test/spec/cassettes/info/user_info.yml +63 -0
  27. data/test/spec/cassettes/preset/all.yml +795 -0
  28. data/test/spec/cassettes/preset/create.yml +97 -0
  29. data/test/spec/cassettes/preset/delete.yml +142 -0
  30. data/test/spec/cassettes/preset/upload_cover.yml +484 -0
  31. data/test/spec/cassettes/production/all.yml +6764 -0
  32. data/test/spec/cassettes/production/create.yml +118 -0
  33. data/test/spec/cassettes/production/delete.yml +163 -0
  34. data/test/spec/cassettes/production/start.yml +164 -0
  35. data/test/spec/cassettes/production/upload_audio.yml +20047 -0
  36. data/test/spec/cassettes/production/upload_audio_from_service.yml +233 -0
  37. data/test/spec/cassettes/production/upload_cover.yml +526 -0
  38. data/test/spec/data/test.jpg +0 -0
  39. data/test/spec/data/test.m4a +0 -0
  40. data/test/spec/helper.rb +32 -0
  41. data/test/spec/info_spec.rb +137 -0
  42. data/test/spec/preset_spec.rb +115 -0
  43. data/test/spec/production_spec.rb +181 -0
  44. metadata +223 -0
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'miniphonic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "miniphonic"
8
+ spec.version = Miniphonic::VERSION
9
+ spec.authors = ["sirmarcel"]
10
+ spec.email = ["me@lumenlog.com"]
11
+ spec.description = %q{Miniphonic is a wrapper for the Auphonic.com API}
12
+ spec.summary = %q{Wraps the Auphonic API in delicious Ruby, for audio processing bliss.}
13
+ spec.homepage = "https://github.com/sirmarcel/miniphonic"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "mocha"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_runtime_dependency "multi_json"
26
+ spec.add_runtime_dependency "faraday"
27
+ spec.add_runtime_dependency "faraday_middleware"
28
+ spec.add_runtime_dependency "mime-types"
29
+ end
@@ -0,0 +1,164 @@
1
+ require_relative 'helper'
2
+ require 'multi_json'
3
+
4
+ module Miniphonic
5
+
6
+ describe ApiObject do
7
+
8
+ describe '#endpoint' do
9
+ it 'must raise an error if no endpoint is defined' do
10
+ lambda do
11
+ ApiObject.new.endpoint
12
+ end.must_raise(NotImplementedError)
13
+ end
14
+ end
15
+
16
+ describe '#attributes_to_payload' do
17
+
18
+ it 'must raise an error if no attributes_to_payload method is defined' do
19
+ lambda do
20
+ ApiObject.new.attributes_to_payload
21
+ end.must_raise(NotImplementedError)
22
+
23
+ end
24
+ end
25
+
26
+ describe '#payload_to_attributes' do
27
+
28
+ it 'must raise an error if no payload_to_attributes method is defined' do
29
+ lambda do
30
+ ApiObject.new.payload_to_attributes({})
31
+ end.must_raise(NotImplementedError)
32
+
33
+ end
34
+
35
+ end
36
+
37
+ describe '#initialize' do
38
+
39
+ it 'must initialize object with uuid' do
40
+ ApiObject.new("test").uuid.must_equal("test")
41
+ end
42
+
43
+ end
44
+
45
+ describe '#create' do
46
+
47
+ before do
48
+ @test_object = ApiObject.new
49
+ @test_object.stubs(:collection_url).returns("test")
50
+ @payload = { "test" => "bar" }
51
+ @collection_url = "/api/test"
52
+ @good_response_body = {
53
+ "data" => {
54
+ "uuid" => "test"
55
+ }
56
+ }
57
+ @good_response = stub_response(200, {}, @good_response_body)
58
+
59
+ # Stub to_server interna (not very elegantly)
60
+ @connection = stub
61
+ Miniphonic.stubs(:connect).returns(@connection)
62
+ @connection.stubs(:post).returns(@good_response)
63
+ end
64
+
65
+ it 'must run to_server with the right arguments' do
66
+ @test_object.stubs(:collection_url).returns(@collection_url)
67
+ @test_object.stubs(:attributes_to_payload).returns(@payload)
68
+ @test_object.expects(:to_server).with(@collection_url,@payload)
69
+ @test_object.create
70
+ end
71
+
72
+ it 'must set self.uuid on success' do
73
+ @test_object.stubs(:collection_url).returns(@collection_url)
74
+ @test_object.stubs(:attributes_to_payload).returns(@payload)
75
+ @test_object.create
76
+ @test_object.uuid.must_equal("test")
77
+ end
78
+
79
+ end
80
+
81
+ describe '#update' do
82
+
83
+ before do
84
+ @test_object = ApiObject.new
85
+ @payload = {test: "foo"}
86
+ @url = "/test"
87
+ @test_object.stubs(:attributes_to_payload).returns(@payload)
88
+ @test_object.stubs(:single_url).returns(@url)
89
+ end
90
+
91
+ it 'must call to_server with the right data' do
92
+ @test_object.expects(:to_server).with(@url, @payload)
93
+ @test_object.update
94
+ end
95
+
96
+ end
97
+
98
+ describe '#command' do
99
+
100
+ before do
101
+ @payload = { "test" => "bar" }
102
+ @test_object = ApiObject.new
103
+ @test_object.stubs(:endpoint).returns("test_endpoint")
104
+ @test_object.stubs(:uuid).returns("test_uuid")
105
+ @command = "test_command"
106
+ end
107
+
108
+ it 'must run to_server with the right data' do
109
+ @test_object.expects(:to_server).with("/api/test_endpoint/test_uuid/test_command.json", @payload)
110
+ @test_object.command( @command, @payload )
111
+ end
112
+
113
+ end
114
+
115
+ describe '#get_attributes' do
116
+
117
+ before do
118
+ @single_url = "/api/test"
119
+ @data_on_server = {test: "toast"}
120
+ @response_body = {
121
+ "data" => @data_on_server
122
+ }
123
+
124
+ @test_object = ApiObject.new
125
+ @test_object.stubs(:single_url).returns(@single_url)
126
+
127
+
128
+ @response = stub_response(200, {}, @response_body)
129
+
130
+ # Stub from_server interna (not very elegantly)
131
+ @connection = stub
132
+ Miniphonic.stubs(:connect).returns(@connection)
133
+ @connection.stubs(:get).returns(@response)
134
+ end
135
+
136
+ it 'must pass data from server to attributes_to_payload' do
137
+ @test_object.expects(:payload_to_attributes).with(@data_on_server)
138
+ @test_object.get_attributes
139
+ end
140
+
141
+ end
142
+
143
+ describe '#single_url' do
144
+
145
+ it 'must raise error if no uuid is present' do
146
+ lambda do
147
+ Production.new.single_url
148
+ end.must_raise(UuidError)
149
+ end
150
+
151
+ end
152
+
153
+ describe '#command_url' do
154
+
155
+ it 'must raise error if no uuid is present' do
156
+ lambda do
157
+ Production.new.command_url("")
158
+ end.must_raise(UuidError)
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+ end
@@ -0,0 +1,170 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://auphonic.com/api/info/algorithms.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Authorization:
13
+ - Basic c2lybWFyY2VsOm5hYy1kaWQtY2lkLXlvZC1qYS1zaGxlai15dWwteQ==
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ server:
20
+ - nginx/1.2.0
21
+ date:
22
+ - Fri, 18 Oct 2013 22:58:42 GMT
23
+ content-type:
24
+ - application/json; charset=utf-8
25
+ transfer-encoding:
26
+ - chunked
27
+ connection:
28
+ - close
29
+ cache-control:
30
+ - max-age=600
31
+ vary:
32
+ - Authorization
33
+ expires:
34
+ - Fri, 18 Oct 2013 23:08:42 GMT
35
+ last-modified:
36
+ - Fri, 18 Oct 2013 22:58:42 GMT
37
+ access-control-allow-origin:
38
+ - '*'
39
+ access-control-allow-credentials:
40
+ - 'true'
41
+ access-control-allow-headers:
42
+ - Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
43
+ body:
44
+ encoding: UTF-8
45
+ string: |-
46
+ {
47
+ "status_code": 200,
48
+ "form_errors": {},
49
+ "error_code": null,
50
+ "error_message": "",
51
+ "data": {
52
+ "normloudness": {
53
+ "default_value": true,
54
+ "type": "checkbox",
55
+ "display_name": "Global Loudness Normalization",
56
+ "description": "Adjusts the global, overall loudness to the specified Loudness Target, so that all processed files have a similar average loudness."
57
+ },
58
+ "loudnesstarget": {
59
+ "default_value": -16,
60
+ "display_name": "Loudness Target",
61
+ "description": "Select the loudness target in LUFS for Global Loudness Normalization, higher values result in louder audio outputs.",
62
+ "belongs_to": "normloudness",
63
+ "type": "select",
64
+ "options": [
65
+ {
66
+ "display_name": "-13 LUFS (very loud)",
67
+ "value": -13
68
+ },
69
+ {
70
+ "display_name": "-15 LUFS",
71
+ "value": -15
72
+ },
73
+ {
74
+ "display_name": "-16 LUFS (mobile)",
75
+ "value": -16
76
+ },
77
+ {
78
+ "display_name": "-18 LUFS (ReplayGain similarity)",
79
+ "value": -18
80
+ },
81
+ {
82
+ "display_name": "-20 LUFS",
83
+ "value": -20
84
+ },
85
+ {
86
+ "display_name": "-23 LUFS, EBU R128 (TV, Europe)",
87
+ "value": -23
88
+ },
89
+ {
90
+ "display_name": "-24 LUFS, ATSC A/85, no gate (TV, US)",
91
+ "value": -24
92
+ },
93
+ {
94
+ "display_name": "-31 LUFS (very quiet)",
95
+ "value": -31
96
+ }
97
+ ]
98
+ },
99
+ "denoise": {
100
+ "default_value": false,
101
+ "type": "checkbox",
102
+ "display_name": "Noise Reduction ",
103
+ "description": "Classifies regions with different backgrounds and automatically removes noise and hum."
104
+ },
105
+ "denoiseamount": {
106
+ "default_value": 0,
107
+ "display_name": "Noise Reduction Amount",
108
+ "description": "Maximum noise reduction amount, higher values remove more noise. Use Automatic if you are no expert!",
109
+ "belongs_to": "denoise",
110
+ "type": "select",
111
+ "options": [
112
+ {
113
+ "display_name": "Auto",
114
+ "value": 0
115
+ },
116
+ {
117
+ "display_name": "3 dB",
118
+ "value": 3
119
+ },
120
+ {
121
+ "display_name": "6 dB (low)",
122
+ "value": 6
123
+ },
124
+ {
125
+ "display_name": "9 dB",
126
+ "value": 9
127
+ },
128
+ {
129
+ "display_name": "12 dB (medium)",
130
+ "value": 12
131
+ },
132
+ {
133
+ "display_name": "15 dB",
134
+ "value": 15
135
+ },
136
+ {
137
+ "display_name": "18 dB",
138
+ "value": 18
139
+ },
140
+ {
141
+ "display_name": "24 dB (high)",
142
+ "value": 24
143
+ },
144
+ {
145
+ "display_name": "30 dB",
146
+ "value": 30
147
+ },
148
+ {
149
+ "display_name": "100 dB (complete)",
150
+ "value": 100
151
+ }
152
+ ]
153
+ },
154
+ "hipfilter": {
155
+ "default_value": true,
156
+ "type": "checkbox",
157
+ "display_name": "Filtering",
158
+ "description": "Filters unnecessary and disturbing low frequencies depending on the context (speech, music, noise)."
159
+ },
160
+ "leveler": {
161
+ "default_value": true,
162
+ "type": "checkbox",
163
+ "display_name": "Adaptive Leveler",
164
+ "description": "Corrects level differences between speakers, music and speech, etc. to achieve a balanced overall loudness."
165
+ }
166
+ }
167
+ }
168
+ http_version:
169
+ recorded_at: Fri, 18 Oct 2013 22:58:51 GMT
170
+ recorded_with: VCR 2.6.0