Class: Joplin::Notebook
- Inherits:
-
Object
- Object
- Joplin::Notebook
- Defined in:
- lib/joplin.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id = nil) ⇒ Notebook
constructor
A new instance of Notebook.
- #notes ⇒ Object
Constructor Details
Class Method Details
.all ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/joplin.rb', line 230 def self.all notebooks = [] page = 1 loop do url = "#{Joplin.uri}/folders?token=#{Joplin.token}&page=#{page}" response = HTTP.get(url) raise Error, "Failed to fetch notebooks: #{response}" if response.status != 200 data = JSON.parse(response.body) items = data['items'] break if items.empty? # Collect Notebook instances items.each { |notebook_data| notebooks << Notebook.new(notebook_data['id']) } page += 1 end notebooks end |
Instance Method Details
#notes ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/joplin.rb', line 207 def notes notes = [] page = 1 loop do url = "#{Joplin.uri}/folders/#{@id}/notes?token=#{Joplin.token}&page=#{page}" response = HTTP.get(url) raise Error, "Failed to fetch notes: #{response}" if response.status != 200 data = JSON.parse(response.body) items = data['items'] items.each { |note_data| notes << Joplin::Note.new(id: note_data['id']) } break unless data['has_more'] page += 1 end notes end |