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 Marshaller.
The Features will be automatically kept up to date according to the given RefreshPolicy.
Constant Summary collapse
- SUPPORTED_SCHEMES =
%w[http https].freeze
Instance Attribute Summary collapse
-
#marshaller ⇒ Object
readonly
Returns the value of attribute marshaller.
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.
36 37 38 39 40 41 42 43 |
# File 'lib/eight_ball/providers/http.rb', line 36 def initialize(uri, = {}) raise ArgumentError, 'Invalid HTTP/HTTPS URI provided' unless uri =~ URI.regexp(SUPPORTED_SCHEMES) @uri = URI.parse uri @marshaller = [:marshaller] || EightBall::Marshallers::Json.new @policy = [:refresh_policy] || EightBall::Providers::RefreshPolicies::Interval.new end |
Instance Attribute Details
#marshaller ⇒ Object (readonly)
Returns the value of attribute marshaller.
15 16 17 |
# File 'lib/eight_ball/providers/http.rb', line 15 def marshaller @marshaller end |
Instance Method Details
#features ⇒ Array<{EightBall::Feature}>
Returns the current Features.
47 48 49 50 |
# File 'lib/eight_ball/providers/http.rb', line 47 def features @policy.refresh { fetch } @features end |