이상한. coursera가 항상 동일한 응답을 반환하지 않는 것 같습니다.
require 'httparty'
class Coursera
include HTTParty
base_uri 'https://api.coursera.org/api/catalog.v1/courses'
default_params fields: "smallIcon,shortDescription", q: "search"
format :json
def self.for term
response = get("", query: {query: term})
puts response.request.last_uri.to_s
elements = response["elements"]
if elements
puts "Got Positive response!"
response
else
puts "Got Negative response!"
end
end
end
p Coursera.for 'python'
때때로 반환 : 때때로
https://api.coursera.org/api/catalog.v1/courses?fields=smallIcon%2CshortDescription&q=search&query=python
Got Negative response!
nil
과 :
https://api.coursera.org/api/catalog.v1/courses?fields=smallIcon%2CshortDescription&q=search&query=python
Got Positive response!
#<HTTParty::Response:0x2660970 parsed_response={"elements"=>[{"id"=>119, "shortName"=>"scicomp", "name"=>"High Performance Scientific Computing", "shortDescription"=>"Programming-oriented course on effectively using modern computers to solve scientific computing problems arising in the physical/engineering sciences and other fields. Provides an introduction to efficient serial and parallel computing using Fortran 90, OpenMP, MPI, and Python, and software development tools such as version control, Makefiles, and debugging.", "smallIcon"=>"https://d15cw65ipctsrr.cloudfront.net/00/621b9b2597807229ed0fa605f96cdc/HighPerformanceComputingIma.jpg", "links"=>{}}, {"id"=>87, "shortName"=>"compphoto", "name"=>"Computational Photography", "shortDescription"=>"In this course you will learn about the basics of
....
내가 기본'HTTParty.get (...)에 코드를 줄여 보시기 바랍니다 [ '요소'] '작동 한 다음 다시 깨질 때까지 앞으로 움직입니다. –