Class: JsonApiReader::Reader
- Inherits:
-
Object
- Object
- JsonApiReader::Reader
- Defined in:
- lib/json_api_reader/reader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_pages ⇒ Object
- #fetch ⇒ Object
-
#initialize(options = {}, block) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(options = {}, block) ⇒ Reader
Returns a new instance of Reader.
3 4 5 6 7 8 |
# File 'lib/json_api_reader/reader.rb', line 3 def initialize(={}, block) raise ArgumentError.new("'endpoint' option is required") if [:endpoint].nil? @url = [:endpoint] @options = .clone @block = block end |
Class Method Details
.all_pages(options = {}, &block) ⇒ Object
23 24 25 |
# File 'lib/json_api_reader/reader.rb', line 23 def all_pages(={}, &block) new(, block).all_pages end |
.first_page(options = {}, &block) ⇒ Object
27 28 29 |
# File 'lib/json_api_reader/reader.rb', line 27 def first_page(={}, &block) new(, block).fetch end |
Instance Method Details
#all_pages ⇒ Object
10 11 12 13 14 |
# File 'lib/json_api_reader/reader.rb', line 10 def all_pages while !@url.nil? @url = fetch.next_url end end |
#fetch ⇒ Object
16 17 18 19 20 |
# File 'lib/json_api_reader/reader.rb', line 16 def fetch result = JsonApiReader::Fetcher.fetch_all(@url, @options) @block.call(result) result end |