require 'net/https'
require 'uri'
require 'json'
uri = URI.parse("https://qiita.com/")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
QIITA_API_TOKEN = 'xxxxxxxxxxxxxxxxxx'
# https://qiita.com/YumaInaura/items/yyyyyyyyyyyyyyyyyyy のような記事URLから id が分かる
qiita_item_id = 'yyyyyyyyyyyyyyyyyyy'
patch_url = "https://qiita.com/api/v2/items/#{qiita_item_id}"
patch_request_header = {
'Content-Type' =>'application/json',
"Authorization" => "Bearer #{QIITA_API_TOKEN}"
}
patch_request = Net::HTTP::Patch.new(patch_url, patch_request_header)
# タイトルと記事本文は必須
patch_request.body = {
'title' => 'Title',
'body' => "AAA\nBBB\nUpdated at #{Time.now}"
}.to_json
patch_response = http.request(patch_request)
puts patch_response.body
更新の例
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。