SDKRUBY-6 Replace unused API version with HTTP timeout configuration
diff --git a/lib/predictionio/client.rb b/lib/predictionio/client.rb
index 72fe3bf..c661c08 100644
--- a/lib/predictionio/client.rb
+++ b/lib/predictionio/client.rb
@@ -124,9 +124,6 @@
# Appkey can be changed on-the-fly after creation of the client.
attr_accessor :appkey
- # API version can be changed on-the-fly after creation of the client.
- attr_accessor :apiversion
-
# Only JSON is currently supported as API response format.
attr_accessor :apiformat
@@ -164,11 +161,10 @@
# - API entry point at http://localhost:8000
# - API return data format of json
# - 10 concurrent HTTP(S) connections
- def initialize(appkey, threads = 10, apiurl = "http://localhost:8000", apiversion = "")
+ def initialize(appkey, threads = 10, apiurl = "http://localhost:8000", thread_timeout = 60)
@appkey = appkey
- @apiversion = apiversion
@apiformat = "json"
- @http = PredictionIO::Connection.new(URI(apiurl), threads)
+ @http = PredictionIO::Connection.new(URI(apiurl), threads, thread_timeout)
end
# Returns the number of pending requests within the current client.
@@ -200,7 +196,7 @@
rparams["pio_latlng"] = "#{params["pio_latitude"]},#{params["pio_longitude"]}"
end
- @http.apost(PredictionIO::AsyncRequest.new(versioned_path("/users.#{@apiformat}"), rparams))
+ @http.apost(PredictionIO::AsyncRequest.new("/users.#{@apiformat}", rparams))
end
# :category: Synchronous Methods
@@ -240,7 +236,7 @@
#
# See also #get_user.
def aget_user(uid)
- @http.aget(PredictionIO::AsyncRequest.new(versioned_path("/users/#{uid}.#{@apiformat}"),
+ @http.aget(PredictionIO::AsyncRequest.new("/users/#{uid}.#{@apiformat}",
"pio_appkey" => @appkey,
"pio_uid" => uid))
end
@@ -288,7 +284,7 @@
#
# See also #delete_user.
def adelete_user(uid)
- @http.adelete(PredictionIO::AsyncRequest.new(versioned_path("/users/#{uid}.#{@apiformat}"),
+ @http.adelete(PredictionIO::AsyncRequest.new("/users/#{uid}.#{@apiformat}",
"pio_appkey" => @appkey,
"pio_uid" => uid))
end
@@ -338,7 +334,7 @@
rparams["pio_startT"] = ((params["pio_startT"].to_r) * 1000).round(0).to_s if params["pio_startT"]
rparams["pio_endT"] = ((params["pio_endT"].to_r) * 1000).round(0).to_s if params["pio_endT"]
- @http.apost(PredictionIO::AsyncRequest.new(versioned_path("/items.#{@apiformat}"), rparams))
+ @http.apost(PredictionIO::AsyncRequest.new("/items.#{@apiformat}", rparams))
end
# :category: Synchronous Methods
@@ -377,7 +373,7 @@
#
# See also #get_item.
def aget_item(iid)
- @http.aget(PredictionIO::AsyncRequest.new(versioned_path("/items/#{iid}.#{@apiformat}"),
+ @http.aget(PredictionIO::AsyncRequest.new("/items/#{iid}.#{@apiformat}",
"pio_appkey" => @appkey,
"pio_iid" => iid))
end
@@ -433,7 +429,7 @@
#
# See also #delete_item.
def adelete_item(iid)
- @http.adelete(PredictionIO::AsyncRequest.new(versioned_path("/items/#{iid}.#{@apiformat}"),
+ @http.adelete(PredictionIO::AsyncRequest.new("/items/#{iid}.#{@apiformat}",
"pio_appkey" => @appkey,
"pio_iid" => iid))
end
@@ -488,7 +484,7 @@
end
rparams["pio_within"] = params["pio_within"] if params["pio_within"]
rparams["pio_unit"] = params["pio_unit"] if params["pio_unit"]
- @http.aget(PredictionIO::AsyncRequest.new(versioned_path("/engines/itemrec/#{engine}/topn.#{@apiformat}"), rparams))
+ @http.aget(PredictionIO::AsyncRequest.new("/engines/itemrec/#{engine}/topn.#{@apiformat}", rparams))
end
# :category: Synchronous Methods
@@ -540,7 +536,7 @@
end
rparams["pio_within"] = params["pio_within"] if params["pio_within"]
rparams["pio_unit"] = params["pio_unit"] if params["pio_unit"]
- @http.aget(PredictionIO::AsyncRequest.new(versioned_path("/engines/itemsim/#{engine}/topn.#{@apiformat}"), rparams))
+ @http.aget(PredictionIO::AsyncRequest.new("/engines/itemsim/#{engine}/topn.#{@apiformat}", rparams))
end
# :category: Synchronous Methods
@@ -587,7 +583,7 @@
if params["pio_latitude"] && params["pio_longitude"]
rparams["pio_latlng"] = "#{params["pio_latitude"]},#{params["pio_longitude"]}"
end
- @http.apost(PredictionIO::AsyncRequest.new(versioned_path("/actions/u2i.#{@apiformat}"), rparams))
+ @http.apost(PredictionIO::AsyncRequest.new("/actions/u2i.#{@apiformat}", rparams))
end
# :category: Synchronous Methods
@@ -614,14 +610,5 @@
raise U2IActionNotCreatedError, msg
end
end
-
- # :nodoc: all
- private
-
- def versioned_path(path)
- # disabled for now
- # "/#{@apiversion}#{path}"
- path
- end
end
end
diff --git a/lib/predictionio/connection.rb b/lib/predictionio/connection.rb
index e0c642c..9823aff 100644
--- a/lib/predictionio/connection.rb
+++ b/lib/predictionio/connection.rb
@@ -14,7 +14,7 @@
# Spawns a number of threads with persistent HTTP connection to the specified URI.
# Sets a default timeout of 5 seconds.
- def initialize(uri, threads = 1, timeout = 5)
+ def initialize(uri, threads = 1, timeout = 60)
@packages = Queue.new
@counter_lock = Mutex.new
@connections = 0