Sha256: bb2af8714376dd9954062938efe0897678641305e1bafbd588e81c04973c3431

Contents?: true

Size: 1.28 KB

Versions: 36

Compression:

Stored size: 1.28 KB

Contents

require 'precheck/rule'

module Precheck
  class UnreachableURLRule < URLRule
    def self.key
      :unreachable_urls
    end

    def self.env_name
      "RULE_UNREACHABLE_URLS"
    end

    def self.friendly_name
      "No broken urls"
    end

    def self.description
      "unreachable URLs in app metadata"
    end

    def rule_block
      return lambda { |url|
        url = url.to_s.strip
        return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: "empty url") if url.empty?

        begin
          uri = Addressable::URI.parse(url)
          uri.fragment = nil
          request = Faraday.new(URI.encode(uri.to_s)) do |connection|
            connection.use FaradayMiddleware::FollowRedirects
            connection.adapter :net_http
          end
          return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: url) unless request.head.status == 200
        rescue
          UI.verbose "URL #{url} not reachable 😵"
          # I can only return :fail here, but I also want to return #{url}
          return RuleReturn.new(validation_state: VALIDATION_STATES[:failed], failure_data: "unreachable: #{url}")
        end

        return RuleReturn.new(validation_state: VALIDATION_STATES[:passed])
      }
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
fastlane-2.69.0.beta.20171211010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171210010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171209010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171208010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171207010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171206010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.68.2 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171205010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.68.1 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171204010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171203010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171202010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.69.0.beta.20171201010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.68.0 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.68.0.beta.20171130010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.68.0.beta.20171129010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.67.0 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.67.0.beta.20171128010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.67.0.beta.20171127010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.67.0.beta.20171126010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb