module Miniphonic::Helpers
Public Instance Methods
delete_from_server(url, payload = {}, &block)
click to toggle source
Deletes data from the server and executes a given block on success
# File lib/miniphonic/helpers.rb, line 20 def delete_from_server(url, payload = {}, &block) connection = Miniphonic.connect response = connection.delete url, payload if response.success? block.call(response) if block response else server_error(response) end end
from_server(url, payload = {}, &block)
click to toggle source
Gets data from the server and executes a given block on success
# File lib/miniphonic/helpers.rb, line 13 def from_server(url, payload = {}, &block) connection = Miniphonic.connect response = connection.get url, payload handle_response(response, &block) end
handle_response(response, &block)
click to toggle source
# File lib/miniphonic/helpers.rb, line 31 def handle_response(response, &block) if response.success? block.call(response) if block response else server_error(response) end end
path_to_payload(path, type)
click to toggle source
# File lib/miniphonic/helpers.rb, line 40 def path_to_payload(path, type) path = File.expand_path(path) filetype = MIME::Types.type_for(path) payload = {} payload[type] = Faraday::UploadIO.new(path, filetype) payload end
server_error(response)
click to toggle source
# File lib/miniphonic/helpers.rb, line 48 def server_error(response) raise Miniphonic::ServerSideError, "Error on server, responded #{ response.status } with message #{ response.body["error_message"]}." end
to_server(url, payload = {}, &block)
click to toggle source
Posts data to the server and executes a given block on success
# File lib/miniphonic/helpers.rb, line 6 def to_server(url, payload = {}, &block) connection = Miniphonic.connect response = connection.post url, payload handle_response(response, &block) end