Toot toooooooot (Bluesky-Mastodon cross-poster)
1require 'minisky' 2require 'yaml' 3 4class BlueskyClient 5 include Minisky::Requests 6 7 CONFIG_FILE = File.expand_path(File.join(__dir__, '..', 'config', 'bluesky.yml')) 8 9 attr_reader :config 10 11 def initialize 12 @config = File.exist?(CONFIG_FILE) ? YAML.load(File.read(CONFIG_FILE)) : {} 13 Dir.mkdir('config') unless Dir.exist?('config') 14 end 15 16 def host 17 @config['host'] 18 end 19 20 def host=(h) 21 @config['host'] = h 22 end 23 24 def save_config 25 File.write(CONFIG_FILE, YAML.dump(@config)) 26 end 27 28 def get_blob(method, params = nil) 29 check_access 30 31 headers = authentication_header(true) 32 url = URI("#{base_url}/#{method}") 33 34 if params && !params.empty? 35 url.query = URI.encode_www_form(params) 36 end 37 38 request = Net::HTTP::Get.new(url, headers) 39 response = make_request(request) 40 41 case response 42 when Net::HTTPSuccess 43 response.body 44 else 45 handle_response(response) 46 end 47 end 48end