gouf
1/15/2017 - 5:45 AM

Code School のユーザ情報をリクエストしてJSON 形式で取得

Code School のユーザ情報をリクエストしてJSON 形式で取得

require 'open-uri'
require 'json'
require 'pp'

user_name = 'gouf'
uri = URI.parse("https://www.codeschool.com/users/#{user_name}.json")
pp json = JSON.parse(uri.open.read)

=begin
pp completed_course_links =
  json.dig('courses', 'completed')
  &.map { |course| "  <img src=\"#{course['badge']}\"/>\n  <br/>\n  <a href=\"#{course['url']}\">#{course['title']}</a>\n" }

css_style = <<EOF
<style>
div {
  border: thin solid gray;
  width: 132px;
  float: right;
}
div img {
  width: 100px;
  height: 100px;
}
</style>
EOF

File.open(File.expand_path('~/completed_course_links.html'), 'w') do |f|
  f.write css_style
  f.write completed_course_links.map { |element| "<div>\n#{element}</div>" }.join("\n")
end
=end