Sha256: 7074954bd4220fed182207e4bcb1858004c0dbab5ae92b26bdc011516ff07cc6

Contents?: true

Size: 1.31 KB

Versions: 37

Compression:

Stored size: 1.31 KB

Contents

require 'precheck/rule'
require 'addressable'

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

37 entries across 37 versions & 1 rubygems

Version Path
fastlane-2.74.0.beta.20180106010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.73.0 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.73.0.beta.20180105010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.73.0.beta.20180104010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.73.0.beta.20180103010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0.beta.20180102010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0.beta.20180101010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0.beta.20171231010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.1 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0.beta.20171230010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0.beta.20171229010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.72.0.beta.20171228010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0.beta.20171227010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0.beta.20171226010004 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0.beta.20171225010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0.beta.20171224010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0.beta.20171223010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.71.0.beta.20171222010003 precheck/lib/precheck/rules/unreachable_urls_rule.rb