Sha256: c6f30b5cfd668dce79d2e6862f2b23570aa53605600aa59046757349b9448040

Contents?: true

Size: 678 Bytes

Versions: 10

Compression:

Stored size: 678 Bytes

Contents

# frozen_string_literal: true

require "uri"
require "net/http"
require "json"

module Icarus
  module Mod
    module Tools
      module Sync
        class RequestFailed < StandardError; end

        # Sync helper methods
        module Helpers
          def retrieve_from_url(url)
            raise RequestFailed, "Invalid URI: '#{url}'" unless url && url =~ URI::DEFAULT_PARSER.make_regexp

            res = Net::HTTP.get_response(URI(url))

            raise RequestFailed, "HTTP Request failed for #{url} (#{res.code}): #{res.message}" unless res&.code == "200"

            JSON.parse(res.body, symbolize_names: true)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
Icarus-Mod-Tools-2.1.4 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.1.3 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.1.2 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.1.1 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.1.0 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.0.4 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.0.3 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.0.1 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-2.0 lib/icarus/mod/tools/sync/helpers.rb
Icarus-Mod-Tools-1.9.0 lib/icarus/mod/tools/sync/helpers.rb