Class: Turbovax::DataFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/turbovax/data_fetcher.rb

Overview

This class, given a portal and a twitter handler:

1) executes request for data
2) passes structured appointment data to twitter handler
3) returns appointment data

Instance Method Summary collapse

Constructor Details

#initialize(portal, twitter_handler: nil, date: nil, extra_params: {}) ⇒ DataFetcher

Returns a new instance of DataFetcher.

Parameters:

  • portal (Turbovax::Portal)
  • twitter_handler (TurboVax::Twitter::Handler) (defaults to: nil)

    a class handles if appointments are found

  • date (DateTime) (defaults to: nil)

    sets request to specific date when specified

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

    other info that can be provided to portal when executing blocks



16
17
18
19
20
21
# File 'lib/turbovax/data_fetcher.rb', line 16

def initialize(portal, twitter_handler: nil, date: nil, extra_params: {})
  portal.data_fetcher_params = { date: date || DateTime.now }.merge(extra_params)
  @portal = portal
  @conn = create_request_connection
  @twitter_handler = twitter_handler
end

Instance Method Details

#execute!Array<Turbovax::Location>

Returns List of locations and appointments.

Returns:



24
25
26
27
28
29
30
31
32
33
# File 'lib/turbovax/data_fetcher.rb', line 24

def execute!
  response = make_request
  log("make request [DONE]")
  locations = @portal.parse_response_with_portal(response.body)
  log("parse response [DONE]")

  send_to_twitter_handler(locations)

  locations
end