lib/rginger/parser.rb in rginger-0.1.4 vs lib/rginger/parser.rb in rginger-0.1.5
- old
+ new
@@ -1,7 +1,8 @@
require 'net/http'
require 'uri'
+require 'cgi'
require 'json'
module RGinger
class Parser
def initialize
@@ -16,11 +17,11 @@
results["corrected" => text]
return results
end
width = text.length
- escaped = URI.escape(text)
+ escaped = CGI.escape(text)
url = "#{API_ENDPOINT}?lang=#{DEFAULT_LANG}&clientVersion=#{API_VERSION}&apiKey=#{API_KEY}&text=#{escaped}"
json_data = get_json(url)["LightGingerTheTextResult"] rescue {}
unless json_data.empty?
@@ -65,26 +66,26 @@
end
end
results
end
- def rephrase(input)
+ # def rephrase(input)
- text = input.dup
- results = {"original" => input, "alternatives" => []}
- return results if !text || text == ""
+ # text = input.dup
+ # results = {"original" => input, "alternatives" => []}
+ # return results if !text || text == ""
- width = text.length
- escaped = URI.escape(text)
- url = "#{REPHRASE_ENDPOINT}?s=#{escaped}"
+ # width = text.length
+ # escaped = CGI.escape(text)
+ # url = "#{REPHRASE_ENDPOINT}?s=#{escaped}"
- json_data = get_json(url)
+ # json_data = get_json(url)
- unless json_data.empty? || json_data["Sentences"].empty?
- results["alternatives"] = json_data["Sentences"].map{|s| s["Sentence"]}
- end
- results
- end
+ # unless json_data.empty? || json_data["Sentences"].empty?
+ # results["alternatives"] = json_data["Sentences"].map{|s| s["Sentence"]}
+ # end
+ # results
+ # end
:private
def get_json(location, limit = 10)
raise ArgumentError, 'too many HTTP redirects' if limit == 0