# # gyazo.rb: gyazo plugin for tDiary # # SPDX-License-Identifier: GPL-2.0-or-later # require 'net/http' require 'json' if /^(form|edit|formplugin|showcomment)$/ =~ @mode then enable_js('gyazo.js') end def gyazo(permalink_url, alt = '[description]', style = 'photo') size = @conf['gyazo_max_size'] || 512 begin oembed = JSON.parse(Net::HTTP.get(URI("https://api.gyazo.com/api/oembed?url=#{permalink_url}")), symbolize_names: true) rescue => e @logger.error(e) return '' end url = oembed[:url].gsub(%r|/thumb/\d+/|, "/thumb/#{size}/") width = oembed[:width].to_i height = oembed[:height].to_i if width > 0 && height > 0 if width > height height = size * height / width width = size else width = size * width / height height = size end %Q[] else # no size informations in API %Q[] end end def gyazo_right(permalink_url, alt = '[description]') gyazo(permalink_url, alt, 'right') end def gyazo_left(permalink_url, alt = '[description]') gyazo(permalink_url, alt, 'left') end def gyazo_list endpoint = "https://api.gyazo.com/api/images" access_token = @conf['gyazo_token'] return [] if access_token == nil || access_token.empty? per_page = @conf['gyazo_max_images'] || 5 uri = "#{endpoint}?access_token=#{access_token};per_page=#{per_page}" begin JSON.parse(Net::HTTP.get(URI(uri)), symbolize_names: true).map{|i| [i[:permalink_url], i[:thumb_url]] }.delete_if{|is| is[1].empty? } rescue => e @logger.error(e) return [] end end add_form_proc() do |date| '
Get your token from Gyazo Applications
| r << %Q|| r << %Q|px
| r end