class DocodocoJp::CLI
Public Instance Methods
config()
click to toggle source
# File lib/docodoco_jp/cli.rb, line 19 def config buf = {"apikey1" => options[:key1], "apikey2" => options[:key2]}.to_yaml FileUtils.mkdir_p(File.expand_path("~/.docodoco_jp/")) File.open(File.expand_path("~/.docodoco_jp/apikey.yml"), "w") { |f| f.print(buf) } $stdout.puts "config ok." self.invoke(:show_key, [], {}) end
config_check()
click to toggle source
# File lib/docodoco_jp/cli.rb, line 34 def config_check result, json = client.check_user() $stdout.puts JSON.pretty_generate(json) end
search(ipaddr = nil)
click to toggle source
# File lib/docodoco_jp/cli.rb, line 12 def search(ipaddr = nil) $stdout.puts JSON.pretty_generate(client.search(ipaddr)) end
show_key()
click to toggle source
# File lib/docodoco_jp/cli.rb, line 28 def show_key key1, key2 = get_apikeys() $stdout.puts JSON.pretty_generate({apikey1: key1, apikey2: key2}) end
Private Instance Methods
client()
click to toggle source
# File lib/docodoco_jp/cli.rb, line 40 def client return @instance ||= DocodocoJp.new(*get_apikeys()) end
get_apikeys()
click to toggle source
# File lib/docodoco_jp/cli.rb, line 44 def get_apikeys if File.exist?(File.expand_path("~/.docodoco_jp/apikey.yml")) docodoco_jp_conf = YAML.load_file(File.expand_path("~/.docodoco_jp/apikey.yml", File.dirname(__FILE__))) key1 = docodoco_jp_conf["apikey1"] key2 = docodoco_jp_conf["apikey2"] return key1, key2 else print_setup_help end end
print_setup_help()
click to toggle source
# File lib/docodoco_jp/cli.rb, line 55 def print_setup_help $stderr.puts <<-HELP API key not found.. Gets the API key in the following URL, please execute `docodoco_jp config --key1=KEY1 --key2=KEY2` or edit ~/.docodoco_jp/apikey.yml `http://www.docodoco.jp` `https://admin.docodoco.jp/signup/` HELP exit 1 end