class NytCli::Api
Attributes
date[RW]
Public Class Methods
new(date)
click to toggle source
# File lib/nyt_cli/api.rb, line 5 def initialize(date) @date = date create_book end
Public Instance Methods
create_book()
click to toggle source
Creates a book using a hash of relevant attributes
# File lib/nyt_cli/api.rb, line 21 def create_book get.each do |book| new_book = NytCli::Book.new(book) end end
get()
click to toggle source
Calls on the API with the date initialized
# File lib/nyt_cli/api.rb, line 11 def get url = "https://api.nytimes.com/svc/books/v3/lists/#{@date}/combined-print-and-e-book-fiction.json?api-key=#{ENV["API_KEY"]}" uri = URI.parse(url) response = Net::HTTP.get_response(uri) response_hash = JSON.parse(response.body) response_hash["results"]["books"] end