1

我是 Ruby 新手,正在尝试这个 API。我想构建一个简单的游戏,要求用户输入两部电影名称来猜测/比较哪一部获得了更好的收视率或任何其他比较参数。API 正在工作,我尝试用用户输入替换代码,但这就是它发生故障的地方。(我也提到了我正在调用的课程)

require_relative 'workspace/lib/select'
require_relative 'workspace/lib/brand'
require 'json'
require 'rest-client'



# puts "hello world"

def create_reviewer
    puts "What is your name?"
    name = gets.strip

    puts "So, #{name} what genre are you interested in?"
  genre = gets.strip


  Select.new(name, genre)

end

def create_brand
  puts "Enter the first brand"
  brand_a = gets.strip

  puts "Enter the second brand"
  brand_b = gets.strip

  Brand.new(brand_a, brand_b)
end

review = create_reviewer
brands = create_brand




def get_rotten_tomatoes

  response = JSON.load(RestClient.get('http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=SECRET&q=#{brand_a}&page_limit=30'))
  response["movies"].map do |entry|
    brand_a = entry["ratings"]["audience_score"]
    brand_b = entry["ratings"]["critics_score"]
    final_score = {brand_a: audience_score, brand_b: critics_score}

    final_score
end


goodies = get_rotten_tomatoes
puts goodies

----
class Brand
  attr_accessor :brand_a, :brand_b

  def initialize(name, genre)
    @brand_a = brand_a
    @brand_b = brand_b
  end

  # def to_s
  #   "Tenant: #{@name} \n Credit Score: #{@credit_score}."
  # end
end
4

0 回答 0