avit / stockboy

A helpful gem to receive and unpack data into your organization from anywhere
MIT License
40 stars 7 forks source link

Fetch multiple pages of data #7

Closed avit closed 10 years ago

avit commented 10 years ago

Provider needs a way to iterate over data that is provided in paginated web requests, or separate files by date.

There are too many variables to define a universal DSL for how to iterate:

So, we'll define a "repeat" block that lets the user yield each instance of the provider with changed parameters:


provider :soap do
  # ... same
end

reader :xml do
  # ... same
end

# NEW!

repeat do |soap|
  total_pages = /<Data totalPages="(\d+)"/.match( soap.data )[1].to_i # e.g.

  1.upto total_pages do |next_page|
    yield soap
    soap.message["getPage"] = next_page
  end
end

The job can fetch these in turn and parse them into the list of records. It should automatically clear the data after each yield to force a re-fetch on each iteration.

avit commented 10 years ago

Added in 0.8