Created
February 2, 2017 08:54
-
-
Save ggtmtmgg/94003e238a160c8a15bd01cc5c61470f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
require 'optparse' | |
################## | |
# READHERE | |
################## | |
# 使い方: | |
# % ruby url_testing_tools_sample.rb --api=<YOUR API KEY> --url=<URL> | |
# Google API Manager(https://console.developers.google.com)で | |
# Google Search Console URL Testing Tools APIを有効にして | |
# 認証情報を作成してAPIキーを取得し、<YOUR API KEY>の部分を置き換えてください。 | |
################## | |
# Initialize | |
################## | |
URL_TESTING_TOOLS_URL = 'https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = 'Usage: url_testing_tools.rb [options]' | |
opts.on('-u', '--url=VALUE', 'Url you want to test.') do |v| | |
options[:url] = v | |
end | |
opts.on('-a', '--api=VALUE', 'Your API key.') do |v| | |
options[:api_key] = v | |
end | |
end.parse! | |
if options[:url].nil? || options[:api_key].nil? | |
puts 'error: Please pass options. See --help.' | |
exit 1 | |
end | |
################## | |
# Execution | |
################## | |
api_uri = URI(URL_TESTING_TOOLS_URL) | |
res = Net::HTTP.post_form(api_uri, url: options[:url], key: options[:api_key]) | |
puts res.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment