Class: EightBall::Providers::Http

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Http

Returns a new instance of Http.

Examples:

provider = EightBall::Providers::Http.new(
  'http://www.rewind.io',
  refresh_policy: EightBall::Providers::RefreshPolicies::Interval.new 120
)

Parameters:

  • uri (String)

    The URI to GET the Features from.

  • options (Hash) (defaults to: {})

    The options to create the Provider with.

Options Hash (options):

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
# File 'lib/eight_ball/providers/http.rb', line 36

def initialize(uri, options = {})
  raise ArgumentError, 'Invalid HTTP/HTTPS URI provided' unless uri =~ URI.regexp(SUPPORTED_SCHEMES)

  @uri = URI.parse uri

  @marshaller = options[:marshaller] || EightBall::Marshallers::Json.new
  @policy = options[:refresh_policy] || EightBall::Providers::RefreshPolicies::Interval.new
end

Instance Attribute Details

#marshallerObject (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

#featuresArray<{EightBall::Feature}>

Returns the current Features.

Returns:



47
48
49
50
# File 'lib/eight_ball/providers/http.rb', line 47

def features
  @policy.refresh { fetch }
  @features
end