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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +20 -0
- data/README.md +145 -0
- data/Rakefile +19 -0
- data/lib/miniphonic/api_object.rb +96 -0
- data/lib/miniphonic/helpers.rb +51 -0
- data/lib/miniphonic/info.rb +68 -0
- data/lib/miniphonic/preset.rb +17 -0
- data/lib/miniphonic/preset_attributes.rb +53 -0
- data/lib/miniphonic/production.rb +33 -0
- data/lib/miniphonic/production_attributes.rb +66 -0
- data/lib/miniphonic/response.rb +5 -0
- data/lib/miniphonic/version.rb +3 -0
- data/lib/miniphonic.rb +40 -0
- data/miniphonic.gemspec +29 -0
- data/test/spec/api_object_spec.rb +164 -0
- data/test/spec/cassettes/info/algorithms.yml +170 -0
- data/test/spec/cassettes/info/info.yml +740 -0
- data/test/spec/cassettes/info/output_files.yml +343 -0
- data/test/spec/cassettes/info/service_types.yml +263 -0
- data/test/spec/cassettes/info/services.yml +125 -0
- data/test/spec/cassettes/info/status_codes.yml +70 -0
- data/test/spec/cassettes/info/user_info.yml +63 -0
- data/test/spec/cassettes/preset/all.yml +795 -0
- data/test/spec/cassettes/preset/create.yml +97 -0
- data/test/spec/cassettes/preset/delete.yml +142 -0
- data/test/spec/cassettes/preset/upload_cover.yml +484 -0
- data/test/spec/cassettes/production/all.yml +6764 -0
- data/test/spec/cassettes/production/create.yml +118 -0
- data/test/spec/cassettes/production/delete.yml +163 -0
- data/test/spec/cassettes/production/start.yml +164 -0
- data/test/spec/cassettes/production/upload_audio.yml +20047 -0
- data/test/spec/cassettes/production/upload_audio_from_service.yml +233 -0
- data/test/spec/cassettes/production/upload_cover.yml +526 -0
- data/test/spec/data/test.jpg +0 -0
- data/test/spec/data/test.m4a +0 -0
- data/test/spec/helper.rb +32 -0
- data/test/spec/info_spec.rb +137 -0
- data/test/spec/preset_spec.rb +115 -0
- data/test/spec/production_spec.rb +181 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac264b83a6985c924d3599a733f5d732330c0c9e
|
4
|
+
data.tar.gz: 9fc6b7a8d0c5b49cc1450778b45dd7768f793f9d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 765613ffe96b56c50e2f52b86d6cc46a75319e0a4f02c129a61c3d3507ba3a03f840a359a9f528f122c4d59a634371b68da8c571a279350710130e763aa09181
|
7
|
+
data.tar.gz: 210d5983832baa8ac0ef21019fbc5fa2978cce0278d571d202cebb752761ac35a78373a4568f3c445a89bd859ce377898b4311559fa3a9379c3387cb017c2498
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
.ruby-version
|
15
|
+
.ruby-gemset
|
16
|
+
.DS_Store
|
17
|
+
test.rb
|
18
|
+
|
19
|
+
|
20
|
+
# YARD artifacts
|
21
|
+
.yardoc
|
22
|
+
_yardoc
|
23
|
+
doc/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
miniphonic (0.1.0)
|
5
|
+
faraday
|
6
|
+
faraday_middleware
|
7
|
+
mime-types
|
8
|
+
multi_json
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
faraday (0.8.8)
|
14
|
+
multipart-post (~> 1.2.0)
|
15
|
+
faraday_middleware (0.9.0)
|
16
|
+
faraday (>= 0.7.4, < 0.9)
|
17
|
+
metaclass (0.0.1)
|
18
|
+
mime-types (1.25)
|
19
|
+
mocha (0.14.0)
|
20
|
+
metaclass (~> 0.0.1)
|
21
|
+
multi_json (1.8.1)
|
22
|
+
multipart-post (1.2.0)
|
23
|
+
rake (10.1.0)
|
24
|
+
vcr (2.6.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.3)
|
31
|
+
miniphonic!
|
32
|
+
mocha
|
33
|
+
rake
|
34
|
+
vcr
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Marcel Langer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# Miniphonic
|
2
|
+
|
3
|
+
Wraps the [auphonic]( https://auphonic.com ) API in delicious Ruby for audio processing bliss.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'miniphonic'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install miniphonic
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
First, set up Miniphonic:
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'miniphonic'
|
25
|
+
|
26
|
+
Miniphonic.configure do |m|
|
27
|
+
m.user = "your username"
|
28
|
+
m.password = "much secret wow"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### API objects in general
|
33
|
+
|
34
|
+
Both, *productions* and *presets*, are API objects and share most methods. They are simple Ruby objects:
|
35
|
+
|
36
|
+
#### Creating
|
37
|
+
|
38
|
+
|
39
|
+
```
|
40
|
+
production = Miniphonic::Production.new
|
41
|
+
preset = Miniphonic::Preset.new
|
42
|
+
```
|
43
|
+
|
44
|
+
On the server side, those objects are identified by their ```uuid```.
|
45
|
+
|
46
|
+
You usually get one by creating your API object on the server side:
|
47
|
+
```
|
48
|
+
production.create
|
49
|
+
# => production.uuid = "SjRqGhxKhK448Gs6AgAzcZ"
|
50
|
+
```
|
51
|
+
|
52
|
+
If you already have one, you can create a new API object with a uuid:
|
53
|
+
|
54
|
+
```
|
55
|
+
production = Miniphonic::Production.new("SjRqGhxKhK448Gs6AgAzcZ")
|
56
|
+
```
|
57
|
+
|
58
|
+
#### Deleting
|
59
|
+
|
60
|
+
Run ```production.delete``` or ```preset.delete``` to delete on the server.
|
61
|
+
|
62
|
+
#### Setting/Getting Attributes
|
63
|
+
|
64
|
+
Usually, you actually want to do something useful, so you need to add some attributes to your API objects.
|
65
|
+
Miniphonic exposes the "top level" of attributes in dot notation, the rest is handled by the appropriate data structures (hashes and arrays). Take a look at [this page]( https://auphonic.com/api-docs/details.html#one-request ) or ```{preset|production}_attributes.rb``` to see what you can do.
|
66
|
+
|
67
|
+
Quick example:
|
68
|
+
```
|
69
|
+
production.metadata[:title] = "Hello there, internet"
|
70
|
+
production.output_files << {format: "mp3"}
|
71
|
+
```
|
72
|
+
|
73
|
+
If you set attributes before running ```create```, they will be sent with the creation request, otherwise, use ```object.update``` to set the attributes on the server side.
|
74
|
+
|
75
|
+
You can get attributes from the server (thus overwriting the one in your local API object!) by running ```get_attributes```, provided your object already has a ```uuid```.
|
76
|
+
|
77
|
+
If you run ```Miniphonic::Production.all``` or ```Miniphonic::Preset.all```, you get an array of all API objects on ther server, already initialized with their uuids. If you need their attributes as well, you need to run ```get_attributes``` on each of them.
|
78
|
+
|
79
|
+
#### Pretty pictures
|
80
|
+
|
81
|
+
To upload a cover image to a production or preset, use
|
82
|
+
```
|
83
|
+
production.upload_cover("/path/to/image.jpg")
|
84
|
+
preset.upload_cover("yet/another/image.png")
|
85
|
+
```
|
86
|
+
and smile.
|
87
|
+
|
88
|
+
### Productions
|
89
|
+
|
90
|
+
#### Getting audio in
|
91
|
+
|
92
|
+
You can upload an input file (to a production with a uuid) by running
|
93
|
+
|
94
|
+
```
|
95
|
+
production.upload_audio("path/to/file")
|
96
|
+
```
|
97
|
+
|
98
|
+
Or use one from an external service:
|
99
|
+
```
|
100
|
+
production.upload_audio_from_service("file.m4a","service_uuid")
|
101
|
+
```
|
102
|
+
|
103
|
+
#### Getting audio out
|
104
|
+
|
105
|
+
Add outfiles:
|
106
|
+
```
|
107
|
+
production.output_files << {format: "mp3", basename: "my_file"}
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Processing
|
111
|
+
|
112
|
+
Start and stop productions (if you have provided an input file and at least one output file):
|
113
|
+
|
114
|
+
```
|
115
|
+
production.start
|
116
|
+
production.stop
|
117
|
+
```
|
118
|
+
|
119
|
+
### Presets
|
120
|
+
|
121
|
+
Presets have a lot less fancy methods than productions, but they work pretty much the same.
|
122
|
+
One caveat: You can't create presets without setting ```preset.name``` first.
|
123
|
+
|
124
|
+
### Getting info
|
125
|
+
|
126
|
+
The auphonic API is pretty cool about returning information about itself. For example, you can get all your user data with ```Miniphonic.user_data``` or all available algorithms with ```Miniphonic.algorithms```. More info [here]( https://auphonic.com/api-docs/query.html ) or in ```info.rb```. (Heh.)
|
127
|
+
|
128
|
+
***
|
129
|
+
|
130
|
+
The auphonic API is not really complicated, but there's a lot you can do. Right now, Miniphonic should allow you to do most of the things the API does (as far as I know), but please let me know if something is missing. I'm @sirmarcel on Twitter, that's probably easiest way to get in touch.
|
131
|
+
|
132
|
+
Refer to the [API docs]( https://auphonic.com/api-docs/details.html ), the specs and the appropriate classes for further information.
|
133
|
+
|
134
|
+
Do some good now.
|
135
|
+
|
136
|
+
<3
|
137
|
+
|
138
|
+
|
139
|
+
## Contributing
|
140
|
+
|
141
|
+
1. Fork it
|
142
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
143
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
144
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
145
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new do |test|
|
5
|
+
test.name = 'spec'
|
6
|
+
test.pattern = 'test/spec/**/*_spec.rb'
|
7
|
+
test.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.name = 'test'
|
13
|
+
t.pattern = 'test/integration/test_*.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
task :wipe do
|
18
|
+
system "rm -r test/spec/cassettes/"
|
19
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Miniphonic
|
2
|
+
class ApiObject
|
3
|
+
include Miniphonic::Helpers
|
4
|
+
extend Miniphonic::Helpers
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def all
|
9
|
+
from_server self.new.collection_url do |response|
|
10
|
+
return response.data.each_with_object([]) do |hash, objects|
|
11
|
+
objects << self.new(hash["uuid"])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_accessor :uuid
|
19
|
+
attr_accessor :data
|
20
|
+
|
21
|
+
def endpoint
|
22
|
+
raise NotImplementedError, "#endpoint has to be overridden in #{ self.class.name }"
|
23
|
+
end
|
24
|
+
|
25
|
+
def attributes_to_payload
|
26
|
+
raise NotImplementedError, "#create has to be overridden in #{ self.class.name }"
|
27
|
+
end
|
28
|
+
|
29
|
+
def payload_to_attributes(payload)
|
30
|
+
raise NotImplementedError, "#attributes_to_payload has to be overridden in #{ self.class.name }"
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(uuid = nil)
|
34
|
+
@uuid = uuid
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create an API object on server, will conveniently send already set attributes
|
38
|
+
def create
|
39
|
+
to_server(collection_url, attributes_to_payload) do |response|
|
40
|
+
self.uuid = response.data["uuid"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Reset the API object on server and replaces with current attributes
|
45
|
+
# (We can do this brute-force thing because we have local state.)
|
46
|
+
def update
|
47
|
+
url = single_url
|
48
|
+
payload = attributes_to_payload
|
49
|
+
payload[:reset_data] = true
|
50
|
+
to_server url, payload
|
51
|
+
end
|
52
|
+
|
53
|
+
# Update the local API object with the data from the server
|
54
|
+
# (Mostly to be used after ApiObject.new(uuid))
|
55
|
+
def get_attributes
|
56
|
+
from_server single_url do |response|
|
57
|
+
payload_to_attributes(response.data)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def upload_cover(path)
|
62
|
+
command :upload, path_to_payload(path, :image)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Delete API object from server
|
66
|
+
def delete
|
67
|
+
delete_from_server single_url
|
68
|
+
end
|
69
|
+
|
70
|
+
def command(command, payload = nil)
|
71
|
+
url = command_url(command)
|
72
|
+
to_server url, payload
|
73
|
+
end
|
74
|
+
|
75
|
+
def collection_endpoint
|
76
|
+
endpoint + "s"
|
77
|
+
end
|
78
|
+
|
79
|
+
# URLs
|
80
|
+
|
81
|
+
def collection_url
|
82
|
+
"/api/#{ collection_endpoint }.json"
|
83
|
+
end
|
84
|
+
|
85
|
+
def single_url
|
86
|
+
raise UuidError unless self.uuid
|
87
|
+
"/api/#{ endpoint }/#{ self.uuid }.json"
|
88
|
+
end
|
89
|
+
|
90
|
+
def command_url(command)
|
91
|
+
raise UuidError unless self.uuid
|
92
|
+
"/api/#{ endpoint }/#{ self.uuid }/#{ command }.json"
|
93
|
+
end
|
94
|
+
|
95
|
+
end # class
|
96
|
+
end # module
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
|
3
|
+
module Miniphonic::Helpers
|
4
|
+
|
5
|
+
# Posts data to the server and executes a given block on success
|
6
|
+
def to_server(url, payload = {}, &block)
|
7
|
+
connection = Miniphonic.connect
|
8
|
+
response = connection.post url, payload
|
9
|
+
handle_response(response, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Gets data from the server and executes a given block on success
|
13
|
+
def from_server(url, payload = {}, &block)
|
14
|
+
connection = Miniphonic.connect
|
15
|
+
response = connection.get url, payload
|
16
|
+
handle_response(response, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Deletes data from the server and executes a given block on success
|
20
|
+
def delete_from_server(url, payload = {}, &block)
|
21
|
+
connection = Miniphonic.connect
|
22
|
+
response = connection.delete url, payload
|
23
|
+
if response.success?
|
24
|
+
block.call(response) if block
|
25
|
+
response
|
26
|
+
else
|
27
|
+
server_error(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_response(response, &block)
|
32
|
+
if response.success?
|
33
|
+
block.call(response) if block
|
34
|
+
response
|
35
|
+
else
|
36
|
+
server_error(response)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def path_to_payload(path, type)
|
41
|
+
path = File.expand_path(path)
|
42
|
+
filetype = MIME::Types.type_for(path)
|
43
|
+
payload = {}
|
44
|
+
payload[type] = Faraday::UploadIO.new(path, filetype)
|
45
|
+
payload
|
46
|
+
end
|
47
|
+
|
48
|
+
def server_error(response)
|
49
|
+
raise Miniphonic::ServerSideError, "Error on server, responded #{ response.status } with message #{ response.body["error_message"]}."
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Miniphonic
|
2
|
+
module Info
|
3
|
+
# Methods to retrieve general information from auphonic
|
4
|
+
|
5
|
+
include Miniphonic::Helpers
|
6
|
+
|
7
|
+
# Returns an array of hashes like this:
|
8
|
+
# {
|
9
|
+
# "outgoing": true,
|
10
|
+
# "display_name": "Mr. Derpson",
|
11
|
+
# "uuid": "h8DesucEK6mepmyxtW83MY",
|
12
|
+
# "incoming": true,
|
13
|
+
# "type": "dropbox",
|
14
|
+
# "email": "me@derp.com"
|
15
|
+
# }
|
16
|
+
def services
|
17
|
+
response = from_server "/api/services.json"
|
18
|
+
response.data
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns a hash where the keys are outgoing services
|
22
|
+
def service_types
|
23
|
+
get_info :service_types
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a hash where the keys are audio processing
|
27
|
+
# algorithms and the values option/info hashes
|
28
|
+
def algorithms
|
29
|
+
get_info :algorithms
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns a hash of all available output formats (keys)
|
33
|
+
# and their metadata (values)
|
34
|
+
def output_files
|
35
|
+
get_info :output_files
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a dictionary of production status codes
|
39
|
+
def status_codes
|
40
|
+
get_info :production_status
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns a hash of user information
|
44
|
+
def user_info
|
45
|
+
response = from_server "api/user.json"
|
46
|
+
response.data
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns a hash with the combined data of
|
50
|
+
# output_files, service_types, status_codes, algorithms
|
51
|
+
# as well as all known file endings (those are all keys)
|
52
|
+
def info
|
53
|
+
response = from_server "api/info.json"
|
54
|
+
response.data
|
55
|
+
end
|
56
|
+
|
57
|
+
def files_on(uuid)
|
58
|
+
response = from_server "api/service/#{ uuid }/ls.json"
|
59
|
+
response.data
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_info(name)
|
63
|
+
response = from_server "/api/info/#{ name }.json"
|
64
|
+
response.data
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'preset_attributes'
|
2
|
+
|
3
|
+
module Miniphonic
|
4
|
+
class Preset < ApiObject
|
5
|
+
include Attributes::Preset
|
6
|
+
|
7
|
+
def endpoint
|
8
|
+
"preset"
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
raise PresetNameError, "You can't create a preset without setting preset.name first." unless name
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Miniphonic
|
2
|
+
module Attributes
|
3
|
+
module Preset
|
4
|
+
# Slightly tedious, but very non-magic way of defining the API
|
5
|
+
|
6
|
+
attr_accessor :name
|
7
|
+
|
8
|
+
def metadata
|
9
|
+
@metadata ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :output_basename
|
13
|
+
|
14
|
+
def output_files
|
15
|
+
@output_files ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def outgoing_services
|
19
|
+
@outgoing_services ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def algorithms
|
23
|
+
@algorithms ||= {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def multi_input_files
|
27
|
+
@multi_input_files ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def attributes_to_payload
|
31
|
+
payload = {}
|
32
|
+
payload[:preset_name] = name if name
|
33
|
+
payload[:metadata] = metadata unless metadata.empty?
|
34
|
+
payload[:output_basename] = output_basename if output_basename
|
35
|
+
payload[:output_files] = output_files unless output_files.empty?
|
36
|
+
payload[:outgoing_services] = outgoing_services unless outgoing_services.empty?
|
37
|
+
payload[:algorithms] = algorithms unless algorithms.empty?
|
38
|
+
payload[:multi_input_files] = multi_input_files unless multi_input_files.empty?
|
39
|
+
payload
|
40
|
+
end
|
41
|
+
|
42
|
+
def payload_to_attributes(payload)
|
43
|
+
@metadata = payload["metadata"]
|
44
|
+
@name = payload["preset_name"]
|
45
|
+
@output_basename = payload["output_basename"]
|
46
|
+
@output_files = payload["output_files"]
|
47
|
+
@outgoing_services = payload["outgoing_services"]
|
48
|
+
@algorithms = payload["algorithms"]
|
49
|
+
@multi_input_files = payload["multi_input_files"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'production_attributes'
|
2
|
+
|
3
|
+
module Miniphonic
|
4
|
+
class Production < ApiObject
|
5
|
+
include Attributes::Production
|
6
|
+
|
7
|
+
def endpoint
|
8
|
+
"production"
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload_audio(path)
|
12
|
+
command :upload, path_to_payload(path, :input_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
# If your file is on a service registered with Auphonic,
|
16
|
+
# use this to not have to upload by hand.
|
17
|
+
|
18
|
+
def upload_audio_from_service(filename, service)
|
19
|
+
self.input_file = filename
|
20
|
+
self.upload_service = service
|
21
|
+
update
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
command :start
|
26
|
+
end
|
27
|
+
|
28
|
+
def stop
|
29
|
+
command :stop
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Miniphonic
|
2
|
+
module Attributes
|
3
|
+
module Production
|
4
|
+
# Slightly tedious, but very non-magic way of defining the API
|
5
|
+
|
6
|
+
def metadata
|
7
|
+
@metadata ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :preset
|
11
|
+
|
12
|
+
attr_accessor :output_basename
|
13
|
+
|
14
|
+
def output_files
|
15
|
+
@output_files ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def outgoing_services
|
19
|
+
@outgoing_services ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def algorithms
|
23
|
+
@algorithms ||= {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def chapters
|
27
|
+
@chapters ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_accessor :input_file
|
31
|
+
attr_accessor :upload_service
|
32
|
+
|
33
|
+
def multi_input_files
|
34
|
+
@multi_input_files ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
def attributes_to_payload
|
38
|
+
payload = {}
|
39
|
+
payload[:metadata] = metadata unless metadata.empty?
|
40
|
+
payload[:preset] = preset if preset
|
41
|
+
payload[:output_basename] = output_basename if output_basename
|
42
|
+
payload[:output_files] = output_files unless output_files.empty?
|
43
|
+
payload[:outgoing_services] = outgoing_services unless outgoing_services.empty?
|
44
|
+
payload[:algorithms] = algorithms unless algorithms.empty?
|
45
|
+
payload[:chapters] = chapters unless chapters.empty?
|
46
|
+
payload[:input_file] = input_file if input_file
|
47
|
+
payload[:service] = upload_service if upload_service
|
48
|
+
payload[:multi_input_files] = multi_input_files unless multi_input_files.empty?
|
49
|
+
payload
|
50
|
+
end
|
51
|
+
|
52
|
+
def payload_to_attributes(payload)
|
53
|
+
@metadata = payload["metadata"]
|
54
|
+
@preset = payload["preset"]
|
55
|
+
@output_basename = payload["output_basename"]
|
56
|
+
@output_files = payload["output_files"]
|
57
|
+
@outgoing_services = payload["outgoing_services"]
|
58
|
+
@algorithms = payload["algorithms"]
|
59
|
+
@chapters = payload["chapters"]
|
60
|
+
@input_file = payload["input_file"]
|
61
|
+
@upload_service = payload["service"]
|
62
|
+
@multi_input_files = payload["multi_input_files"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/miniphonic.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
4
|
+
require "miniphonic/version"
|
5
|
+
require "miniphonic/helpers"
|
6
|
+
require "miniphonic/response"
|
7
|
+
require "miniphonic/api_object"
|
8
|
+
require "miniphonic/production"
|
9
|
+
require "miniphonic/preset"
|
10
|
+
require "miniphonic/info"
|
11
|
+
|
12
|
+
module Miniphonic
|
13
|
+
extend Miniphonic::Info
|
14
|
+
|
15
|
+
class UuidError < StandardError
|
16
|
+
end
|
17
|
+
class ServerSideError < StandardError
|
18
|
+
end
|
19
|
+
class PresetNameError < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
attr_accessor :user, :password
|
24
|
+
|
25
|
+
def configure
|
26
|
+
yield self
|
27
|
+
end
|
28
|
+
|
29
|
+
def connect
|
30
|
+
connection = Faraday.new(url: 'https://auphonic.com') do |con|
|
31
|
+
con.request :multipart
|
32
|
+
con.use FaradayMiddleware::ParseJson
|
33
|
+
con.use FaradayMiddleware::EncodeJson
|
34
|
+
con.adapter :net_http
|
35
|
+
end
|
36
|
+
connection.basic_auth user, password
|
37
|
+
connection
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|