lib/share_checker/provider.rb in share_checker-0.1.1 vs lib/share_checker/provider.rb in share_checker-0.1.2
- old
+ new
@@ -1,6 +1,7 @@
require 'curb'
+require 'crack'
module ShareChecker
class Provider
attr_reader :name
@@ -21,9 +22,31 @@
raise NotImplementedError, "Must be overwritten in subclasses"
end
def url
raise NotImplementedError, "Must be overwritten in subclasses"
+ end
+
+ def parse_xml(body)
+ begin
+ content = Crack::XML.parse(body)
+ rescue Exception => e
+ puts "#{@name} error parse xml: #{body}, #{e.message}, #{@link}"
+ content = nil
+ end
+
+ return content
+ end
+
+ def parse_json(body)
+ begin
+ content = Crack::JSON.parse(body)
+ rescue Exception => e
+ puts "#{@name} error parse xml: #{body}, #{e.message}, #{@link}"
+ content = nil
+ end
+
+ return content
end
def method_missing(method_name, *args, &block)
if @options.key?(method_name.to_sym)
@options[method_name.to_sym]