Sha256: 612bc9ff12313c706f1fbd607a244492a8842991042edaa035710f475dd8b1ed

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'faraday'

module Determinator
  module Retrieve

    class HttpRetriever
      def initialize(connection:)
        raise ArgumentError, "client must be a Faraday::Connection" unless connection.is_a?(Faraday::Connection)
        @connection = connection
      end

      def retrieve(name)
        begin
          response = @connection.get("/features/#{name}")
          return Determinator::Serializers::JSON.load(response.body) if response.status == 200
        rescue => e
          Determinator.notice_error(e)
        end
        nil
      end

      # Returns a feature name given a actor-tracking url. Used so we are able
      # to expire a cache using a feature name given an event url.
      #
      # Not intended to be generic, and makes no guarantees about support for
      # alternative url schemes.
      #
      # @param url [String] a actor tracking url
      # @return [String, nil] a feature name or nil
      def get_name(url)
        (url.match('features\/(.*)\z') || [])[1]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
determinator-2.3.0 lib/determinator/retrieve/http_retriever.rb
determinator-2.2.1 lib/determinator/retrieve/http_retriever.rb
determinator-2.2.0 lib/determinator/retrieve/http_retriever.rb
determinator-2.1.0 lib/determinator/retrieve/http_retriever.rb