class Auphonic::Endpoint
Constants
- URL
Public Class Methods
new()
click to toggle source
# File lib/auphonic/endpoint.rb, line 14 def initialize @connection ||= Faraday.new(:url => URL) do |faraday| faraday.request :multipart #faraday.response :logger faraday.adapter Faraday.default_adapter end config = OpenStruct.new(YAML.load(File.read(File.expand_path("~/.auphonic")))) credentials = [ config.login, config.passwd ] @connection.basic_auth(*credentials) end
Public Instance Methods
create_production(data)
click to toggle source
# File lib/auphonic/endpoint.rb, line 57 def create_production(data) url = '/api/productions.json' response = @connection.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = data.to_json end JSON.parse(response.body)['data'] end
download(url)
click to toggle source
# File lib/auphonic/endpoint.rb, line 84 def download(url) url.sub!(URL, '') filename = File.basename(url) response = @connection.get(url) File.open(filename, 'w') { |f| f.print(response.body) } filename end
info_algorithms()
click to toggle source
# File lib/auphonic/endpoint.rb, line 41 def info_algorithms get('/api/info/algorithms.json')['data'] end
info_outputfiles()
click to toggle source
# File lib/auphonic/endpoint.rb, line 45 def info_outputfiles get('/api/info/output_files.json')['data'] end
info_productionsstatuss()
click to toggle source
# File lib/auphonic/endpoint.rb, line 49 def info_productionsstatuss # sic get('/api/info/production_status.json')['data'] end
info_servicetypes()
click to toggle source
# File lib/auphonic/endpoint.rb, line 37 def info_servicetypes get('/api/info/service_types.json')['data'] end
load_production(uuid)
click to toggle source
# File lib/auphonic/endpoint.rb, line 53 def load_production(uuid) get("/api/production/#{uuid}.json")['data'] end
presets()
click to toggle source
# File lib/auphonic/endpoint.rb, line 29 def presets get('/api/presets.json')['data'] end
productions()
click to toggle source
# File lib/auphonic/endpoint.rb, line 25 def productions get('/api/productions.json')['data'] end
services()
click to toggle source
# File lib/auphonic/endpoint.rb, line 33 def services get('/api/services.json')['data'] end
start_production(uuid)
click to toggle source
# File lib/auphonic/endpoint.rb, line 75 def start_production(uuid) url = "/api/production/#{uuid}/start.json" response = @connection.post do |req| req.url url req.headers['Content-Type'] = 'application/json' end JSON.parse(response.body)['data'] end
upload_to_production(uuid, path)
click to toggle source
# File lib/auphonic/endpoint.rb, line 67 def upload_to_production(uuid, path) raise 'Error: uuid missing' if uuid.nil? url = "/api/production/#{uuid}/upload.json" payload = { input_file: Faraday::UploadIO.new(path, 'audio/basic') } response = @connection.post(url, payload) JSON.parse(response.body)['data'] end
Private Instance Methods
get(url)
click to toggle source
def post(url, &bloc)
puts '=' * 80 puts "POST #{url}" puts '=' * 80 response = @connection.post url, bloc result = JSON.parse(response.body) return result['data'] if result['status_code'] == 200 # error result['data'] = nil pp result exit
end
# File lib/auphonic/endpoint.rb, line 107 def get(url) response = @connection.get(url) JSON.parse(response.body) end