class PredictionIO::Connection
This class handles Connections
Public Class Methods
new(uri) { |faraday| ... }
click to toggle source
Creates a connection to the given URI.
# File lib/predictionio/connection.rb, line 9 def initialize(uri) @connection = Faraday.new(:url => uri) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.adapter Faraday.default_adapter # make requests with Net::HTTP yield faraday if block_given? end @connection.headers['Content-Type'] = 'application/json; charset=utf-8' end
Public Instance Methods
delete(request)
click to toggle source
Create a DELETE and return the response.
# File lib/predictionio/connection.rb, line 35 def delete(request) @connection.delete request.path do |req| req.body = request.params end end
get(request)
click to toggle source
Create a GET request and return the response.
# File lib/predictionio/connection.rb, line 19 def get(request) @connection.get request.qpath end
post(request)
click to toggle source
Create a POST and return the response.
# File lib/predictionio/connection.rb, line 24 def post(request) if request.params.is_a?(Hash) @connection.post request.path, request.params else @connection.post request.path do |req| req.body = request.params end end end