lib/calais/client.rb in calais-0.0.3 vs lib/calais/client.rb in calais-0.0.5
- old
+ new
@@ -9,40 +9,26 @@
def initialize(options={}, &block)
options.each {|k,v| send("#{k}=", v)}
yield(self) if block_given?
end
- def call(method, times=1)
+ def call(method)
method = method.intern unless method.is_a?(Symbol)
raise ArgumentError.new("Unknown method: #{method}") unless AVAILABLE_METHODS.keys.include? method
post_args = {
"licenseID" => @license_id,
- "content" => @content,
+ "content" => Iconv.iconv('UTF-8//IGNORE', 'UTF-8', "#{@content} ").first[0..-2],
"paramsXML" => params_xml
}
url = URI.parse(POST_URL + AVAILABLE_METHODS[method])
resp, data = Net::HTTP.post_form(url, post_args)
- handle_response(resp, data, method, times)
+ return resp.is_a?(Net::HTTPOK) ? data : [data, "API Error: #{resp}"]
end
- def self.process_data(data, error=nil)
- Calais::Response.new(data, error)
- end
-
private
- def handle_response(resp, data, method, times)
- if resp.is_a? Net::HTTPOK
- [data, nil]
- elsif times >= MAX_RETRIES
- [data, "Too many retries: #{times}"]
- else
- call(method, times+1)
- end
- end
-
def params_xml
content_type = @content_type && AVAILABLE_CONTENT_TYPES.keys.include?(@content_type) ? AVAILABLE_CONTENT_TYPES[@content_type] : AVAILABLE_CONTENT_TYPES[DEFAULT_CONTENT_TYPE]
output_format = @output_format && AVAILABLE_OUTPUT_FORMATS.keys.include?(@output_format) ? AVAILABLE_OUTPUT_FORMATS[@output_format] : AVAILABLE_OUTPUT_FORMATS[DEFAULT_OUTPUT_FORMAT]
allow_distribution = @allow_distribution ? "true" : "false"
allow_search = @allow_search ? "true" : "false"
\ No newline at end of file