Sha256: 1a2a38686fd1f742a1a5ce9332e33f3f183fd15e83d9f23f4f244dfe2c78219b
Contents?: true
Size: 1.07 KB
Versions: 6
Compression:
Stored size: 1.07 KB
Contents
module Almodovar module HttpAccessor def xml @xml ||= begin response = http.get(url_with_params) check_errors(response) Nokogiri::XML.parse(response.body).root end end def url_with_params @options[:expand] = @options[:expand].join(",") if @options[:expand].is_a?(Array) params = @options.map { |k, v| "#{k}=#{v}" }.join("&") params = "?#{params}" unless params.empty? @url + params end def http @http ||= Patron::Session.new.tap do |session| session.timeout = Almodovar::default_options[:timeout] session.connect_timeout = Almodovar::default_options[:connect_timeout] session.headers['User-Agent'] = Almodovar::default_options[:user_agent] if @auth session.username = @auth.username session.password = @auth.password session.auth_type = :digest end end end def check_errors(response) raise(Almodovar::HttpError, "Status code: #{response.status}") if response.status >= 400 end end end
Version data entries
6 entries across 6 versions & 1 rubygems