Class: EightBall::Providers::Http
- Inherits:
-
Object
- Object
- EightBall::Providers::Http
- Defined in:
- lib/eight_ball/providers/http.rb
Overview
An HTTP Provider will make a GET request to a given URI, and convert the response into an array of Features using the given Parser.
The Features will be automatically kept up to date according to the given RefreshPolicy.
Constant Summary collapse
- SUPPORTED_SCHEMES =
%w[http https].freeze
Instance Method Summary collapse
-
#features ⇒ Array<{EightBall::Feature}>
Returns the current Features.
-
#initialize(uri, options = {}) ⇒ Http
constructor
A new instance of Http.
Constructor Details
#initialize(uri, options = {}) ⇒ Http
Returns a new instance of Http.
32 33 34 35 36 37 38 39 |
# File 'lib/eight_ball/providers/http.rb', line 32 def initialize(uri, = {}) raise ArgumentError, 'Invalid HTTP/HTTPS URI provided' unless uri =~ URI.regexp(SUPPORTED_SCHEMES) @uri = URI.parse uri @parser = [:parser] || EightBall::Parsers::Json.new @policy = [:refresh_policy] || EightBall::Providers::RefreshPolicies::Interval.new end |
Instance Method Details
#features ⇒ Array<{EightBall::Feature}>
Returns the current Features.
43 44 45 46 |
# File 'lib/eight_ball/providers/http.rb', line 43 def features @policy.refresh { fetch } @features end |