class Parsable::Remote
Attributes
secure[RW]
uses the response from a remote location
Public Class Methods
new(options={})
click to toggle source
# File lib/parsable/remote.rb, line 10 def initialize options={} self.secure = options.fetch(:secure, false) end
Public Instance Methods
method_missing(method_sym, *arguments, &block)
click to toggle source
# File lib/parsable/remote.rb, line 14 def method_missing(method_sym, *arguments, &block) if uri = uri?(method_sym) get_response(uri) end end
Private Instance Methods
get_response(uri)
click to toggle source
# File lib/parsable/remote.rb, line 33 def get_response uri transformer = Parsable::UriHelper.new(uri) url = transformer.to_s headers = transformer.secrets 0.upto(2) do |i| perform(url, headers) break if @body end @body end
perform(url, headers={})
click to toggle source
# File lib/parsable/remote.rb, line 22 def perform url, headers={} begin Curl::Easy.perform(url) do |http| headers.each { |header, value| http.headers[header] = value } http.timeout = 2 http.on_success { |easy| @body = easy.body_str } end rescue Curl::Err::CurlError end end
uri?(string)
click to toggle source
# File lib/parsable/remote.rb, line 46 def uri? string uri = URI.parse(string.to_s) if uri && uri.kind_of?(URI::HTTP) uri else false end rescue URI::InvalidURIError false end