Fetch all entries by `Hatenablog::Client`
kymmt90 opened this issue · 4 comments
An idea:
require 'hatenablog'
Hatenablog::Client.create do |blog|
blog.entries(2) #=> entries up to the 2nd page
blog.all_entries #=> all entries
end
Hi, I have an idea about the implementation, which is used in my project.
How about all_entries
method returning an enumerator?
This is my working branch.
https://github.com/kamatama41/hatenablog/tree/make-entries-enumerator
https://github.com/kamatama41/hatenablog/commit/661577b61c48dfea6b834027f4b317aeb4b53522
Actually entries
method returns the enumerator in my brach but I think the all_entries
also will do.
Good thing about this approach is that it's lazy loading.
For example, when we want to find an entry in all entries, we can stop fetching rest of entries when the target entry is found.
Hatenablog::Client.create do |blog|
# stop fetching entries when the entry that has 'foo' in its title is found.
entry = blog.all_entries.find {|e| e.title == 'foo'}
end
How do you think about it?
Thank you for your nice idea😃
For entries
and all_entries
, I'd like to introduce Entries
class includingEnumerable
from your idea.
I'm going to implement this feature with keeping current specs for convenience.
Ex. Client#entries
with no arguments returns entries on the first feed.
Thanks for considering my idea, wait for the feature 👍