Sha256: 50e5ade756792499f972194b2bc00ca1dbcc8b8a6c13595f68237a609a0d1b31

Contents?: true

Size: 636 Bytes

Versions: 3

Compression:

Stored size: 636 Bytes

Contents

require 'net/http'

class Include < Iowa::Component

	attr_reader :content

	def setup
		@content = get_url(@attributes['url'].to_s)
	end

	def get_url(url)
		url = "#{application.root_url}#{url}" unless /^\w+:\/\//.match(url)
		tries = 0
		response = nil
		if /^http/.match(url)
			m = /^http:\/\/([^\/]*)(.*)/.match(url)
			site = m[1]
			path = m[2]
			begin
				http = Net::HTTP.new(site)
				http.open_timeout = 30
				http.start {|h| response = h.get(path)}
			rescue Exception
				tries += 1
				retry if tries < 5
			end
		end
		response.kind_of?(Array) ? response[1] : response.respond_to?(:body) ? response.body : ''
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
IOWA-1.0.3 components/Include/Include.iwa
IOWA-1.0.2 components/Include/Include.iwa
IOWA-1.0.0 components/Include/Include.iwa