Simple_get.rb

This content was produced by an LLM and could include errors.

This script fetches detailed book metadata from an API using an ISBN. It connects via HTTP and parses the resulting JSON data into a usable Ruby structure, displaying comprehensive publication details.

require "net/http"
#=> true
require "json"
#=> true

url = "https://api.openbd.jp/v1/get?isbn=9784791765553"
#=> "https://api.openbd.jp/v1/get?isbn=9784791765553"
uri = URI(url)
#=> #<URI::HTTPS https://api.openbd.jp/v1/get?isbn=9784791765553>
response = Net::HTTP.get(uri)
#=> "[{\"onix\":{\"CollateralDetail\":{},\"RecordReference\":\"9784791765553\",\"Not...
JSON.parse(response)
#=> [{"onix" =>
   {"CollateralDetail" => {},
    "RecordReference" => "9784791765553",
    "NotificationType" => "03",
    "ProductIdentifier" =>
     {"ProductIDType" => "15", "IDValue" => "9784791765553"},
    "DescriptiveDetail" =>
     {"TitleDetail" =>
       {"TitleType" => "01",
        "TitleElement" =>
         {"TitleElementLevel" => "01",
          "TitleText" =>
           {"collationkey" => "ネット バカ : インターネット ガ ワタシタチ ノ ノウ ニ シテイル コト",
            "content" => "ネット・バカ : インターネットがわたしたちの脳にしていること"}}},
      "Contributor" =>
       [{"SequenceNumber" => "1",
         "ContributorRole" => [],
         "PersonName" =>
          {"content" => "Carr, Nicholas G, 1959-", "collationkey" => ""}},
        {"SequenceNumber" => "2",
         "ContributorRole" => [],
         "PersonName" =>
          {"content" => "篠儀, 直子", "collationkey" => "シノギ, ナオコ"}}]},
    "PublishingDetail" =>
     {"Imprint" => {"ImprintName" => "青土社"},
      "PublishingDate" => [{"PublishingDateRole" => "11", "Date" => "201007"}]},
    "ProductSupply" =>
     {"SupplyDetail" =>
       {"ProductAvailability" => "99",
        "Price" =>
         [{"PriceType" => "01",
           "CurrencyCode" => "JPY",
           "PriceAmount" => "2200"}]}}},
  "hanmoto" =>
   {"datecreated" => "2015-08-20 03:41:02",
    "reviews" =>
     [{"post_user" => "genkina",
       "reviewer" => "養老孟司(解剖学者)",
       "source_id" => 29,
       "kubun_id" => 1,
       "source" => "毎日新聞",
       "choyukan" => "",
       "han" => "",
       "link" => "",
       "appearance" => "2010-08-22",
       "gou" => ""},
      {"post_user" => "genkina",
       "reviewer" => "森健(ジャーナリスト)",
       "source_id" => 18,
       "kubun_id" => 1,
       "source" => "朝日新聞",
       "choyukan" => "",
       "han" => "",
       "link" => "",
       "appearance" => "2010-09-12",
       "gou" => ""},
      {"post_user" => "genkina",
       "reviewer" => "",
       "source_id" => 23,
       "kubun_id" => 1,
       "source" => "日本経済新聞",
       "choyukan" => "",
       "han" => "",
       "link" => "",
       "appearance" => "2010-09-12",
       "gou" => ""},
      {"post_user" => "genkina",
       "reviewer" => "",
       "source_id" => 19,
       "kubun_id" => 1,
       "source" => "東京新聞/中日新聞",
       "choyukan" => "",
       "han" => "",
       "link" => "",
       "appearance" => "2010-09-12",
       "gou" => ""},
      {"post_user" => "genkina",
       "reviewer" => "鈴木幸一(インターネットイニシアティブ会長)",
       "source_id" => 29,
       "kubun_id" => 1,
       "source" => "毎日新聞",
       "choyukan" => "朝刊",
       "han" => "",
       "link" => "",
       "appearance" => "2020-02-16",
       "gou" => ""}],
    "dateshuppan" => "2010-07",
    "datemodified" => "2015-08-20 03:41:02"},
  "summary" =>
   {"isbn" => "9784791765553",
    "title" => "ネット・バカ : インターネットがわたしたちの脳にしていること",
    "volume" => "",
    "series" => "",
    "publisher" => "青土社",
    "pubdate" => "201007",
    "cover" => "",
    "author" => "Carr,NicholasG,1959- 篠儀,直子"}}]

Ruby 4.0.3