class RickAndMorty::Endpoint
Attributes
client[R]
Public Class Methods
new()
click to toggle source
# File lib/rick_and_morty/endpoint.rb, line 5 def initialize @client = Client.new("https://rickandmortyapi.com/api/") end
Public Instance Methods
all()
click to toggle source
# File lib/rick_and_morty/endpoint.rb, line 9 def all response = client.get(endpoint_name) range = (2..response.dig(:info, :pages)) response[:results] + AsyncStream.new(range).sum do |page| list(page) end end
find(id)
click to toggle source
# File lib/rick_and_morty/endpoint.rb, line 21 def find(id) client.get("#{endpoint_name}/#{id}") end
list(page = nil)
click to toggle source
# File lib/rick_and_morty/endpoint.rb, line 17 def list(page = nil) client.get(endpoint_name, query: { page: page })[:results] end
Private Instance Methods
endpoint_name()
click to toggle source
# File lib/rick_and_morty/endpoint.rb, line 29 def endpoint_name @endpoint_name ||= self.class.name.split("::")[-1].downcase end