Sha256: ac2060aa892964697de8a7e322e86049ecd9be88f86e18bd64b812a0864653e0

Contents?: true

Size: 1004 Bytes

Versions: 29

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

require 'addressable'
require 'curb'

module Aranha
  module Parsers
    class SourceAddress
      class HttpGet
        class << self
          def location_uri(source_uri, location)
            ::Addressable::URI.join(source_uri, location).to_s
          end

          def valid_source?(source)
            source.to_s =~ %r{\Ahttps?://}
          end
        end

        attr_reader :source

        def initialize(source)
          @source = source.to_s
        end

        def ==(other)
          self.class == other.class && source == other.source
        end

        def url
          source
        end

        def content
          c = ::Curl::Easy.new(url)
          c.follow_location = true
          raise "Curl perform failed (URL: #{url})" unless c.perform
          return c.body_str if c.status.to_i == 200

          raise "Get #{url} returned #{c.status.to_i}"
        end

        def serialize
          url
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
aranha-parsers-0.8.4 lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.25.1 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.25.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
aranha-parsers-0.8.3 lib/aranha/parsers/source_address/http_get.rb
aranha-parsers-0.8.2 lib/aranha/parsers/source_address/http_get.rb
aranha-parsers-0.8.1 lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.24.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
aranha-parsers-0.8.0 lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.23.1 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.23.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
aranha-parsers-0.7.2 lib/aranha/parsers/source_address/http_get.rb
aranha-parsers-0.7.1 lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.22.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.21.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.20.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.19.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.18.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.17.0 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.16.5 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb
ehbrs-tools-0.16.4 vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb