Class: Determinator::Retrieve::HttpRetriever
- Inherits:
-
Object
- Object
- Determinator::Retrieve::HttpRetriever
- Defined in:
- lib/determinator/retrieve/http_retriever.rb
Instance Method Summary collapse
-
#get_name(url) ⇒ String?
Returns a feature name given a actor-tracking url.
-
#initialize(connection:) ⇒ HttpRetriever
constructor
A new instance of HttpRetriever.
- #retrieve(name) ⇒ Object
Constructor Details
#initialize(connection:) ⇒ HttpRetriever
Returns a new instance of HttpRetriever.
7 8 9 10 |
# File 'lib/determinator/retrieve/http_retriever.rb', line 7 def initialize(connection:) raise ArgumentError, "client must be a Faraday::Connection" unless connection.is_a?(Faraday::Connection) @connection = connection end |
Instance Method Details
#get_name(url) ⇒ String?
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.
30 31 32 |
# File 'lib/determinator/retrieve/http_retriever.rb', line 30 def get_name(url) (url.match('features\/(.*)\z') || [])[1] end |
#retrieve(name) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/determinator/retrieve/http_retriever.rb', line 12 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 |