Class: Infostrada::EndpointChecker

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/infostrada/endpoints_poller.rb

Overview

EndpointChecker is an helper class that will call CallRefresh.get_latest to check which updates were made since the last request. It will then call .succeed or .fail asynchronously.

Instance Method Summary collapse

Constructor Details

#initialize(endpoints_whitelist) ⇒ EndpointChecker

Returns a new instance of EndpointChecker.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/infostrada/endpoints_poller.rb', line 68

def initialize(endpoints_whitelist)
  # The CallRefresh endpoint is the one using 'Utility' instead of 'Football'.
  Infostrada::CallRefresh.base_uri Infostrada::CallRefresh.base_uri.gsub(/Football/, 'Utility')

  begin
    updated = Infostrada::CallRefresh.get_latest
    updated = updated.select { |endpoint| endpoints_whitelist.include?(endpoint.method) }

    self.succeed(updated)
  rescue => e
    self.fail(e.message)
  end
end