Class: QiitaBase

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita_org/base.rb

Instance Method Summary collapse

Constructor Details

#initializeQiitaBase

Returns a new instance of QiitaBase.



5
6
7
# File 'lib/qiita_org/base.rb', line 5

def initialize()

end

Instance Method Details

#check_pc_osObject



9
10
11
12
13
14
15
16
17
# File 'lib/qiita_org/base.rb', line 9

def check_pc_os()
  if system "sw_vers"
    return os = "mac"
  elsif system "wmic.exe os get caption"
    return os = "windows"
  else
    return nil
  end
end

#file_open(os, order) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/qiita_org/base.rb', line 79

def file_open(os, order)
  if os == "mac"
    system "open #{order}"
  elsif os == "windows"
    system "explorer.exe #{order}"
  else
    system "xdg-open #{order}"
  end
end

#get_report_id(src, option) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/qiita_org/base.rb', line 89

def get_report_id(src, option)
  conts = File.read(src)
  if conts.match?(/^\#\+qiita_#{option}:\s(.+)/)
    id = conts.match(/\#\+qiita_#{option}: (.+)/)[1]
  else
    id = nil
  end
  return id
end

#pick_up_option(src) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/qiita_org/base.rb', line 19

def pick_up_option(src)
  lines = File.readlines(src)

  lines.each do |line|
    m = []
    if m = line.match(/\#\+qiita_(.+): (.+)/)
      option = m[1]
      unless option == "public" || option == "teams" || option == "private"
        next
      end
      return option
    end
  end
  return option = "private"
end

#search_conf_path(dir, home) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/qiita_org/base.rb', line 35

def search_conf_path(dir, home)
  while dir != home
    if File.exists?(File.join(dir, ".qiita.conf"))
      return dir
    else
      dir = dir.match(/(.+)\//)[1]
    end
  end
  return dir
end

#select_access_path(mode, teams_url) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/qiita_org/base.rb', line 46

def select_access_path(mode, teams_url)
  case mode
  when "teams"
    qiita = teams_url
    path = "api/v2/items?page=1&per_page=100"
  else
    qiita = "https://qiita.com/"
    path = "api/v2/authenticated_user/items?page=1&per_page=100"
  end
  return qiita, path
end

#set_configObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/qiita_org/base.rb', line 58

def set_config()
  conf_dir = search_conf_path(Dir.pwd, Dir.home)
  lib = File.expand_path("../../../lib", __FILE__)
  if conf_dir != Dir.home
    puts "config file path: #{conf_dir.gsub(Dir.home, "~")}".green
  else
    puts "config file path: #{conf_dir}".green
  end

  conf_path = File.join(conf_dir, ".qiita.conf")
  conf = JSON.load(File.read(conf_path))
  access_token = conf["access_token"]
  teams_url = conf["teams_url"]
  display = conf["display"]
  ox_qmd_load_path = File.join(lib, "qiita_org", "ox-qmd", "ox-qmd")

  ErrorMessage.new().access_token_error(access_token)

  return access_token, teams_url, display, ox_qmd_load_path
end