qiita_org 0.1.30 → 0.1.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f288634b1ce2de7e2a34ddc3fd7399cdb2a1b9e63e6d4b2523ec7cf3fc84601
4
- data.tar.gz: a08fb2191f4e6cc80e3c40701df53bae8ae983cfaa225dfba57ede608d846c97
3
+ metadata.gz: 6c72fb0ca25fa98881ffa0e4f000a6d18c0ad742f7771b501d5b8cc8a7d1877f
4
+ data.tar.gz: 6e131d7a573369378f002f155900851f1b11f7fe522778c9ee637b3098596a1c
5
5
  SHA512:
6
- metadata.gz: 0d01c3f1937f7033f7e4a7e2989492251bc53e18e1717ba394a0385afefc217df08a756c61a3cb580e24139199de80ef065d34019d122f00443359879b3cc865
7
- data.tar.gz: afd6c322d5d5de441b55b5784e630ca9c401b5f028ce7636d68a8b12dfec8a3b0feb07dd8d458043077e1d3130a65a617f946784be87266a8044c26db18595b7
6
+ metadata.gz: fab87567e4e52f3f3bb74f3cd32807e7b1ef3bcfd19fbd019891a0218489373d5ec1be694389c5815be11fc5a397287d9203e3bde9e04048a6a2a28f43e3d88a
7
+ data.tar.gz: 0daa3405f652e9c79d91e02f3b88403dc86f3d6f67012cd0f8e73123b6141d8651ae01c66ed85eb6d40d6bcdd27bea10a5c67e9a1ccd33dc3cef59c77a343cb1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_org (0.1.29)
4
+ qiita_org (0.1.34)
5
5
  colorize
6
6
  command_line (> 2.0.0)
7
7
  fileutils
@@ -9,22 +9,15 @@ require "qiita_org/get"
9
9
  require "qiita_org/list"
10
10
  require "qiita_org/all"
11
11
  require "qiita_org/get_template"
12
- require "qiita_org/check_pc_os"
13
12
  require "qiita_org/upload"
14
- require "qiita_org/get_file_path"
15
- require "qiita_org/show_file_and_url"
16
- require "qiita_org/decide_option"
17
13
  require "qiita_org/get_multiple_files"
18
- #require "qiita_org/qiita_org_thor"
14
+ require "qiita_org/base"
19
15
 
20
16
  module QiitaOrg
21
17
  class CLI < Thor
22
- # def initialize(*argv)
23
- # super(*argv)
24
- # end
25
- #
26
18
  def initialize(*argv)
27
19
  super(*argv)
20
+ @base = QiitaBase.new()
28
21
  end
29
22
 
30
23
  desc "say_hello", "say_hello"
@@ -37,24 +30,25 @@ module QiitaOrg
37
30
  desc "post [FILE] [private/public/teams]", "post to qiita from org"
38
31
 
39
32
  def post(*argv)
40
- checkos = CheckPcOs.new
41
- os = checkos.return_os()
33
+ os = @base.check_pc_os()
42
34
 
43
35
  if argv.size > 2
44
36
  GetMultipleFiles.new(argv, os, "post").run()
45
- elsif argv[-1].match(/(.+).org/) && argv.size != 1
46
- GetMultipleFiles.new(argv, os, "post").run()
47
- else
48
- p ["in qiita_org.rb", argv]
49
- p file = argv[0] || "README.org"
50
- p mode = argv[1] || DecideOption.new(file).decide_option()
51
- qiita = QiitaPost.new(file, mode, os)
52
- begin
53
- qiita.select_option(mode)
54
- rescue RuntimeError => e
55
- puts $!
37
+ else #if argv.size > 1
38
+ if argv[-1].match(/(.+).org/)
39
+ GetMultipleFiles.new(argv, os, "post").run()
56
40
  else
57
- qiita.run
41
+ p ["in qiita_org.rb", argv]
42
+ p file = argv[0] || "README.org"
43
+ p mode = argv[1] || @base.pick_up_option(file)
44
+ qiita = QiitaPost.new(file, mode, os)
45
+ begin
46
+ qiita.select_option(mode)
47
+ rescue RuntimeError => e
48
+ puts $!
49
+ else
50
+ qiita.run
51
+ end
58
52
  end
59
53
  end
60
54
  end
@@ -62,35 +56,20 @@ module QiitaOrg
62
56
  desc "upload [FILE] [teams/public/private]", "upload about image to qiita"
63
57
 
64
58
  def upload(*argv)
65
- checkos = CheckPcOs.new
66
- os = checkos.return_os()
59
+ os = @base.check_pc_os()
67
60
 
68
61
  if argv.size > 2
69
62
  GetMultipleFiles.new(argv, os, "upload").run()
70
- elsif argv[-1].match(/(.+).org/) && argv.size != 1
71
- GetMultipleFiles.new(argv, os, "upload").run()
72
- else
73
- p file = argv[0] || "README.org"
74
- p mode = argv[1] || DecideOption.new(file).decide_option()
63
+ else #if argv.size > 1
64
+ if argv[-1].match(/(.+).org/)
65
+ GetMultipleFiles.new(argv, os, "upload").run()
66
+ else
67
+ p file = argv[0] || "README.org"
68
+ p mode = argv[1] || @base.pick_up_option(file)
75
69
 
76
- qiita = QiitaUpLoad.new(file, mode, os).upload()
77
- end
78
- =begin
79
- getpath = GetFilePath.new(file)
80
- paths = getpath.get_file_path()
81
- unless paths.empty?
82
- showfile = ShowFile.new(paths, file, mode, os)
83
- showfile.open_file_dir()
84
- showfile.open_qiita()
85
-
86
- puts "Input file URL's on #{file}? (y/n)".green
87
- ans = STDIN.getch
88
-
89
- if ans == "y"
90
- showfile.input_url_to_org()
70
+ qiita = QiitaFileUpLoad.new(file, mode, os).upload()
91
71
  end
92
72
  end
93
- =end
94
73
  end
95
74
 
96
75
  desc "config [global/local] [option] [input]", "set config"
@@ -115,16 +94,16 @@ module QiitaOrg
115
94
  desc "template", "make template.org"
116
95
 
117
96
  def template(*argv)
118
- checkos = CheckPcOs.new
119
- os = checkos.return_os()
97
+ os = @base.check_pc_os()
98
+ filename = argv[0] || "template.org"
99
+ filename = (filename.include?(".org"))? filename : "#{filename}.org"
120
100
 
121
- template = QiitaGetTemplate.new(os).run()
101
+ template = QiitaGetTemplate.new(os, filename).run()
122
102
  end
123
103
 
124
104
  desc "all [teams/public/private] [options]", "post all org files in the directory"
125
105
 
126
106
  def all(*argv)
127
- #mode = argv[0] || false
128
107
  QiitaAll.new(argv).run()
129
108
  end
130
109
 
@@ -20,8 +20,6 @@ class AccessQiita
20
20
  "Authorization" => "#{headers["Authorization"]}",
21
21
  )
22
22
  rescue => e
23
- #puts "#{$!}".red
24
- #exit
25
23
  ErrorMessage.new().qiita_access_error(e)
26
24
  else
27
25
  items = JSON.parse(response.read)
@@ -2,7 +2,6 @@ require "colorize"
2
2
 
3
3
  class QiitaAll
4
4
  def initialize(argv)
5
- # @mode = mode
6
5
  check_options(argv)
7
6
  @files = Dir.glob("*.org")
8
7
  p @files
@@ -11,9 +10,10 @@ class QiitaAll
11
10
  def run()
12
11
  @files.each do |file|
13
12
  unless @exclude_files.empty?
14
- if @exclude_files.include?(file)
15
- next
16
- end
13
+ next if @exclude_files.include?(file)
14
+ #if @exclude_files.include?(file)
15
+ # next
16
+ #end
17
17
  end
18
18
 
19
19
  unless @mode
@@ -0,0 +1,98 @@
1
+ require "colorize"
2
+ require "qiita_org/error_message.rb"
3
+
4
+ class QiitaBase
5
+ def initialize()
6
+
7
+ end
8
+
9
+ def check_pc_os()
10
+ if system "sw_vers"
11
+ return os = "mac"
12
+ elsif system "wmic.exe os get caption"
13
+ return os = "windows"
14
+ else
15
+ return nil
16
+ end
17
+ end
18
+
19
+ def pick_up_option(src)
20
+ lines = File.readlines(src)
21
+
22
+ lines.each do |line|
23
+ m = []
24
+ if m = line.match(/\#\+qiita_(.+): (.+)/)
25
+ option = m[1]
26
+ unless option == "public" || option == "teams" || option == "private"
27
+ next
28
+ end
29
+ return option
30
+ end
31
+ end
32
+ return option = "private"
33
+ end
34
+
35
+ def search_conf_path(dir, home)
36
+ while dir != home
37
+ if File.exists?(File.join(dir, ".qiita.conf"))
38
+ return dir
39
+ else
40
+ dir = dir.match(/(.+)\//)[1]
41
+ end
42
+ end
43
+ return dir
44
+ end
45
+
46
+ def select_access_path(mode, teams_url)
47
+ case mode
48
+ when "teams"
49
+ qiita = teams_url
50
+ path = "api/v2/items?page=1&per_page=100"
51
+ else
52
+ qiita = "https://qiita.com/"
53
+ path = "api/v2/authenticated_user/items?page=1&per_page=100"
54
+ end
55
+ return qiita, path
56
+ end
57
+
58
+ def set_config()
59
+ conf_dir = search_conf_path(Dir.pwd, Dir.home)
60
+ lib = File.expand_path("../../../lib", __FILE__)
61
+ if conf_dir != Dir.home
62
+ puts "config file path: #{conf_dir.gsub(Dir.home, "~")}".green
63
+ else
64
+ puts "config file path: #{conf_dir}".green
65
+ end
66
+
67
+ conf_path = File.join(conf_dir, ".qiita.conf")
68
+ conf = JSON.load(File.read(conf_path))
69
+ access_token = conf["access_token"]
70
+ teams_url = conf["teams_url"]
71
+ display = conf["display"]
72
+ ox_qmd_load_path = File.join(lib, "qiita_org", "ox-qmd", "ox-qmd")
73
+
74
+ ErrorMessage.new().access_token_error(access_token)
75
+
76
+ return access_token, teams_url, display, ox_qmd_load_path
77
+ end
78
+
79
+ def file_open(os, order)
80
+ if os == "mac"
81
+ system "open #{order}"
82
+ elsif os == "windows"
83
+ system "explorer.exe #{order}"
84
+ else
85
+ system "xdg-open #{order}"
86
+ end
87
+ end
88
+
89
+ def get_report_id(src, option)
90
+ conts = File.read(src)
91
+ if conts.match?(/^\#\+qiita_#{option}:\s(.+)/)
92
+ id = conts.match(/\#\+qiita_#{option}: (.+)/)[1]
93
+ else
94
+ id = nil
95
+ end
96
+ return id
97
+ end
98
+ end
@@ -7,8 +7,7 @@ class QiitaConfig
7
7
  @option = option
8
8
  @input = input
9
9
  if status == "local"
10
- search = SearchConfPath.new(Dir.pwd, Dir.home)
11
- conf_dir = search.search_conf_path()
10
+ conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
12
11
  if @option == "set"
13
12
  @setup = File.join(Dir.pwd, ".qiita.conf")
14
13
  else
@@ -7,14 +7,18 @@ class ErrorMessage
7
7
 
8
8
  def access_token_error(access_token)
9
9
  if access_token == ""
10
- puts "Please setting ACCESS_TOKEN".red
10
+ puts "Please setting ACCESS_TOKEN.".red
11
+ puts "Hint: qiita config global access_token 'your access_token'.".red
12
+ puts "Hint: qiita config local access_token 'your access_token'.".red
11
13
  exit
12
14
  end
13
15
  end
14
16
 
15
17
  def teams_url_error(teams_url)
16
18
  if teams_url == ""
17
- puts "Please setting teams_url".red
19
+ puts "Please setting teams_url.".red
20
+ puts "Hint: qiita config global teams_url 'https://foge.qiita.com/'.".red
21
+ puts "Hint: qiita config local teams_url 'https://foge.qiita.com/'.".red
18
22
  exit
19
23
  end
20
24
  end
@@ -57,17 +61,17 @@ class ErrorMessage
57
61
  check = true
58
62
 
59
63
  if conf["name"] == ""
60
- puts "Please set your name in config".red
61
- puts "Hint: qiita config global name 'YOUR NAME'".red
62
- puts "Hint: qiita config local name 'YOUR NAME'".red
64
+ puts "Please set your name in config.".red
65
+ puts "Hint: qiita config global name 'YOUR NAME'.".red
66
+ puts "Hint: qiita config local name 'YOUR NAME'.".red
63
67
  # system "rm template.org"
64
68
  check = false
65
69
  end
66
70
 
67
71
  if conf["email"] == ""
68
- puts "Please set your email in config".red
69
- puts "Hint: qiita config global email 'youremail@example.com'".red
70
- puts "Hint: qiita config local name 'youremail@example.com'".red
72
+ puts "Please set your email in config.".red
73
+ puts "Hint: qiita config global email 'your_email@example.com'.".red
74
+ puts "Hint: qiita config local name 'your_email@example.com'.".red
71
75
  check = false
72
76
  end
73
77
  unless check
@@ -77,8 +81,9 @@ class ErrorMessage
77
81
 
78
82
  def md_file_exists?(src, res)
79
83
  unless File.exists?(src.gsub(".org", ".md"))
80
- puts "Can not make #{src.gsub(".org", ".md")}".red
81
- puts "Please confirm emacs version.".red
84
+ puts "Can not convert org doc to markdown.".red
85
+ puts 'Please confirm emacs version above 26.'.red
86
+ puts "Next, check links in the org doc, as converting in emacs by 'ctrl+c, ctrl+e, h, o'.".red
82
87
  exit
83
88
  else
84
89
  p res
@@ -3,8 +3,6 @@ require "json"
3
3
  require "open-uri"
4
4
  require "io/console"
5
5
  require "colorize"
6
- require "qiita_org/select_path.rb"
7
- require "qiita_org/set_config.rb"
8
6
  require "qiita_org/error_message.rb"
9
7
  require "qiita_org/access_qiita.rb"
10
8
 
@@ -12,47 +10,9 @@ class QiitaGet
12
10
  def initialize(mode, id)
13
11
  @mode = mode
14
12
  @get_id = id
15
- @selectpath = SelectPath.new()
13
+ @base = QiitaBase.new()
16
14
  end
17
15
 
18
- # select path
19
- =begin
20
- def select_path(mode)
21
- case mode
22
- when "teams"
23
- qiita = @teams_url
24
- path = "api/v2/items?page=1&per_page=100"
25
- else
26
- qiita = "https://qiita.com/"
27
- path = "api/v2/authenticated_user/items?page=1&per_page=100"
28
- end
29
- return qiita, path
30
- end
31
- =end
32
-
33
- # access qiita
34
- =begin
35
- def access_qiita()
36
- uri = URI.parse(@qiita + @path)
37
-
38
- headers = { "Authorization" => "Bearer # {@access_token}",
39
- "Content-Type" => "application/json" }
40
-
41
- begin
42
- response = URI.open(
43
- "# {uri}",
44
- "Authorization" => "# {headers["Authorization"]}",
45
- )
46
- #raise "NOT FOUND: # {@get_id} report".red
47
- rescue => e
48
- puts "# {$!}".red
49
- exit
50
- else
51
- @items = JSON.parse(response.read)
52
- end
53
- end
54
- =end
55
-
56
16
  # select report
57
17
  def select_report()
58
18
  @items.each do |item|
@@ -141,7 +101,6 @@ EOS
141
101
  @path = "api/v2/items/#{@get_id}"
142
102
 
143
103
  @items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
144
- #access_qiita()
145
104
 
146
105
  @title = @items["title"]
147
106
  @id = @items["id"]
@@ -159,13 +118,13 @@ EOS
159
118
  end
160
119
 
161
120
  def run()
162
- @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
121
+ @access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
163
122
  if @mode == "teams"
164
123
  ErrorMessage.new().teams_url_error(@teams_url)
165
124
  end
166
125
 
167
126
  if @get_id == nil
168
- @qiita, @path = @selectpath.select_path(@mode, @teams_url)
127
+ @qiita, @path = @base.select_access_path(@mode, @teams_url)
169
128
  @items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
170
129
  select_report()
171
130
  else
@@ -1,8 +1,6 @@
1
1
  require "colorize"
2
- #require "../qiita_org/qiita_org.rb"
3
2
  require "qiita_org/post.rb"
4
3
  require "qiita_org/upload.rb"
5
- require "qiita_org/decide_option.rb"
6
4
 
7
5
  class GetMultipleFiles
8
6
  def initialize(files, os, type)
@@ -17,9 +15,9 @@ class GetMultipleFiles
17
15
  end
18
16
 
19
17
  def run()
20
- puts "post files: #{@files}".green
18
+ puts "#{@type} files: #{@files}".green
21
19
  @files.each do |file|
22
- mode = @option || DecideOption.new(file).decide_option()
20
+ mode = @option || QiitaBase.new().pick_up_option(file)
23
21
  puts "qiita #{@type} #{file} #{mode}".green
24
22
  if @type == "post"
25
23
  qiita = QiitaPost.new(file, mode, @os)
@@ -31,7 +29,7 @@ class GetMultipleFiles
31
29
  qiita.run
32
30
  end
33
31
  elsif @type == "upload"
34
- UpLoad.new(file, mode, @os).upload()
32
+ QiitaFileUpLoad.new(file, mode, @os).upload()
35
33
  end
36
34
  end
37
35
  end
@@ -1,15 +1,13 @@
1
1
  require "fileutils"
2
2
  require "colorize"
3
3
  require "kconv"
4
- require "qiita_org/search_conf_path"
5
4
  require "qiita_org/error_message.rb"
6
5
 
7
6
  class QiitaGetTemplate
8
- def initialize(os)
7
+ def initialize(os, filename)
9
8
  @os = os
10
- search = SearchConfPath.new(Dir.pwd, Dir.home)
11
- @conf_dir = search.search_conf_path()
12
- # check_write_header()
9
+ @filename = filename
10
+ @conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
13
11
  end
14
12
 
15
13
  def get_macos_version()
@@ -18,9 +16,9 @@ class QiitaGetTemplate
18
16
  m = []
19
17
  m = version.match(/ProductName:\t(.+)\nProductVersion:\t(.+)\nBuildVersion:\t(.+)\n/)
20
18
  system 'rm hoge.txt'
21
- conts = File.read("template.org")
19
+ conts = File.read(@filename)
22
20
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1].gsub(" ", "")}-#{m[2]}-brightgreen) "
23
- File.write("template.org", conts) # + "# {m[1]}: # {m[2]}\n")
21
+ File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
24
22
  end
25
23
 
26
24
  def get_windowsos_version()
@@ -33,9 +31,9 @@ class QiitaGetTemplate
33
31
  m2 = version2.match(/OSArchitecture\n(.+)-bit/)
34
32
  system 'rm hoge1.txt'
35
33
  system 'rm hoge2.txt'
36
- conts = File.read("template.org")
34
+ conts = File.read(@filename)
37
35
  conts << "![#{m1[1]}-#{m1[2]}](https://img.shields.io/badge/#{m1[1].gsub(" ", "")}#{m1[2]}-#{m2[1]}bit-brightgreen) "
38
- File.write("template.org", conts) # + "# {m[1]}: # {m[2]}\n")
36
+ File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
39
37
  end
40
38
 
41
39
  def get_ubuntu_version()
@@ -44,9 +42,9 @@ class QiitaGetTemplate
44
42
  m = []
45
43
  m = version.match(/(.+) (.+) LTS /)
46
44
  system 'rm hoge.txt'
47
- conts = File.read("template.org")
45
+ conts = File.read(@filename)
48
46
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1]}-#{m[2]}-brightgreen) "
49
- File.write("template.org", conts)
47
+ File.write(@filename, conts)
50
48
  end
51
49
 
52
50
  def get_ruby_version()
@@ -55,9 +53,9 @@ class QiitaGetTemplate
55
53
  m = []
56
54
  m = version.match(/ruby (.+) \((.+)/)
57
55
  system 'rm hoge.txt'
58
- conts = File.read("template.org")
56
+ conts = File.read(@filename)
59
57
  conts << "![ruby-#{m[1]}](https://img.shields.io/badge/ruby-#{m[1].gsub(" ", "")}-brightgreen) "
60
- File.write("template.org", conts) # + "ruby: # {m[1]}\n")
58
+ File.write(@filename, conts) # + "ruby: # {m[1]}\n")
61
59
  end
62
60
 
63
61
  # cp template.org
@@ -65,11 +63,11 @@ class QiitaGetTemplate
65
63
  lib = File.expand_path("../../../lib", __FILE__)
66
64
  cp_file = File.join(lib, "qiita_org", "template.org")
67
65
 
68
- if File.exists?("./template.org")
69
- puts "template.org exists.".red
66
+ if File.exists?("./#{@filename}")
67
+ puts "#{@filename} exists.".red
70
68
  exit
71
69
  else
72
- FileUtils.cp(cp_file, ".", verbose: true)
70
+ FileUtils.cp(cp_file, @filename, verbose: true)
73
71
  end
74
72
  end
75
73
 
@@ -104,42 +102,15 @@ class QiitaGetTemplate
104
102
  end
105
103
  end
106
104
 
107
- def check_write_header()
108
- ["name", "email"].each do |src|
109
- print "Write your #{src}?(y/n) "
110
- ans = STDIN.gets.chomp
111
- next if ans == "n"
112
- if ans == "y"
113
- send("get_#{src}")
114
- end
115
- end
116
- end
117
-
118
- def get_name()
119
- conts = File.readlines("template.org")
120
- p "Type your name"
121
- name = STDIN.gets
122
- conts[3] = "#+AUTHOR: #{name}"
123
- File.write("template.org", conts.join)
124
- end
125
-
126
- def get_email()
127
- conts = File.readlines("template.org")
128
- p "Type your email"
129
- email = STDIN.gets
130
- conts[4] = "#+EMAIL: (concat \"#{email.chomp}\")\n"
131
- File.write("template.org", conts.join)
132
- end
133
-
134
105
  def set_name_and_email()
135
106
  conf_path = File.join(@conf_dir, ".qiita.conf")
136
107
  conf = JSON.load(File.read(conf_path))
137
108
  name = conf["name"]
138
109
  email = conf["email"]
139
- conts = File.readlines("template.org")
110
+ conts = File.readlines(@filename)
140
111
  conts[3] = "#+AUTHOR: #{name}\n"
141
112
  conts[4] = "#+EMAIL: (concat \"#{email}\")\n"
142
- File.write("template.org", conts.join)
113
+ File.write(@filename, conts.join)
143
114
  end
144
115
 
145
116
  def run()
@@ -2,54 +2,23 @@ require "net/https"
2
2
  require "json"
3
3
  require "open-uri"
4
4
  require "colorize"
5
- require "qiita_org/select_path.rb"
6
- require "qiita_org/set_config.rb"
7
5
  require "qiita_org/error_message.rb"
8
6
  require "qiita_org/access_qiita.rb"
9
7
 
10
8
  class QiitaList
11
9
  def initialize(mode)
12
10
  @mode = mode
13
- @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
11
+ @base = QiitaBase.new
12
+ @access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
14
13
  if @mode == "teams"
15
14
  ErrorMessage.new().teams_url_error(@teams_url)
16
15
  end
17
16
 
18
- @qiita, @path = SelectPath.new().select_path(@mode, @teams_url)
17
+ @qiita, @path = @base.select_access_path(@mode, @teams_url)
19
18
  @items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
20
19
  view_list()
21
20
  end
22
21
 
23
- # select path
24
- =begin
25
- def select_path()
26
- case @mode
27
- when "teams"
28
- @qiita = @teams_url
29
- @path = "api/v2/items?page=1&per_page=100"
30
- else
31
- @qiita = "https://qiita.com/"
32
- @path = "api/v2/authenticated_user/items?page=1&per_page=100"
33
- end
34
- end
35
- =end
36
-
37
- # access qiita
38
- =begin
39
- def access_qiita()
40
- uri = URI.parse(@qiita + @path)
41
-
42
- headers = { "Authorization" => "Bearer # {@access_token}",
43
- "Content-Type" => "application/json" }
44
-
45
- response = URI.open(
46
- "# {uri}",
47
- "Authorization" => "# {headers["Authorization"]}",
48
- )
49
- @items = JSON.parse(response.read)
50
- end
51
- =end
52
-
53
22
  def view_list()
54
23
  @items.each do |item|
55
24
  puts "title: #{item["title"]}"
@@ -62,6 +31,5 @@ class QiitaList
62
31
  end
63
32
  puts ""
64
33
  end
65
- # p @items[0]["user"]["id"]
66
34
  end
67
35
  end
@@ -1,6 +1,6 @@
1
1
  class MdConverter
2
2
  def initialize()
3
- # @lines = lines
3
+
4
4
  end
5
5
 
6
6
  def convert_for_image(lines)
@@ -5,15 +5,15 @@ require "json"
5
5
  require "command_line/global"
6
6
  require "colorize"
7
7
  require "qiita_org/md_converter_for_image"
8
- require "qiita_org/set_config.rb"
9
8
  require "qiita_org/error_message"
10
- require "qiita_org/file_open.rb"
9
+ require "qiita_org/access_qiita.rb"
11
10
 
12
11
  class QiitaPost
13
12
  def initialize(file, option, os)
14
13
  @src = file
15
14
  @option = (option == "qiita" || option == "open")? "public" : option
16
15
  @os = os
16
+ @base = QiitaBase.new
17
17
  end
18
18
 
19
19
  public
@@ -21,10 +21,6 @@ class QiitaPost
21
21
  m = conts.match(/\#\+(TITLE|title|Title): (.+)/)
22
22
  @title = m ? m[2] : "テスト"
23
23
  @tags = if m = conts.match(/\#\+(TAG|tag|Tag|tags|TAGS|Tags): (.+)/)
24
- #if m[2].count(",") >= 5
25
- # puts "The maximum number of tag is five. Please delete some tags.".red
26
- #exit
27
- #end
28
24
  ErrorMessage.new().many_tags_error(m[2])
29
25
  m[2].split(",").inject([]) do |l, c|
30
26
  l << { name: c.strip } #, versions: []}
@@ -40,7 +36,6 @@ class QiitaPost
40
36
  def convert_org_to_md()
41
37
  command = "emacs #{@src} --batch -l #{@ox_qmd_load_path} -f org-qmd-export-to-markdown --kill"
42
38
  res = command_line command
43
- #p res
44
39
  ErrorMessage.new().md_file_exists?(@src, res)
45
40
  end
46
41
 
@@ -52,16 +47,38 @@ class QiitaPost
52
47
  end
53
48
 
54
49
  # patch or post selector by qiita_id
55
- def select_patch_or_post(conts, option)
56
- m = []
50
+ def select_patch_or_post(src, option)
51
+ #m = []
57
52
  patch = false
58
- if m = conts.match(/\#\+qiita_#{option}: (.+)/)
59
- qiita_id = m[1]
60
- patch = true
53
+ qiita_id = @base.get_report_id(src, option)
54
+ patch = true if qiita_id != nil
55
+ #if m = conts.match(/\#\+qiita_#{option}: (.+)/)
56
+ # qiita_id = m[1]
57
+ #patch = true
58
+ #else
59
+ # qiita_id = ""
60
+ #end
61
+ return qiita_id, patch
62
+ end
63
+
64
+ def check_change_public(conts, option, id)
65
+ qiita = "https://qiita.com/"
66
+ path = "api/v2/items/#{id}"
67
+ items = AccessQiita.new(@access_token, qiita, path).access_qiita()
68
+
69
+ if items["private"]
70
+ return conts, option
61
71
  else
62
- qiita_id = ""
72
+ option = "public"
73
+ lines = File.readlines(@src)
74
+ file = File.open(@src, "w")
75
+ lines.each_with_index do |line, i|
76
+ lines[i] = "#+qiita_#{option}: #{id}\n" if line.match(/\#\+qiita_private: (.+)/)
77
+ file.print(lines[i])
78
+ end
79
+ conts = File.read(@src)
80
+ return conts, option
63
81
  end
64
- return qiita_id, patch
65
82
  end
66
83
 
67
84
  # check twitter post
@@ -71,8 +88,6 @@ class QiitaPost
71
88
 
72
89
  def select_option(option)
73
90
  qiita = (option == "teams")? @teams_url : "https://qiita.com/"
74
- #qiita = (option == "teams")? "https://nishitani.qiita.com/" :
75
- # "https://qiita.com/"
76
91
  case option
77
92
  when "teams", "qiita", "public", "open"
78
93
  private = false
@@ -146,24 +161,10 @@ class QiitaPost
146
161
  end
147
162
  end
148
163
 
149
- # open qiita
150
- =begin
151
- def open_qiita()
152
- if @os == "mac"
153
- system "open # {@res_body["url"]}"
154
- elsif @os == "windows"
155
- system "explorer.exe # {@res_body["url"]}"
156
- else
157
- system "open # {@res_body["url"]}"
158
- system "xdg-open # {@res_body["url"]}"
159
- end
160
- end
161
- =end
162
-
163
164
  def run()
164
165
  @conts = File.read(@src)
165
166
  @title, @tags = get_title_tags(@conts)
166
- @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
167
+ @access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
167
168
 
168
169
  if @option == "teams"
169
170
  ErrorMessage.new().teams_url_error(@teams_url)
@@ -172,14 +173,14 @@ class QiitaPost
172
173
  convert_org_to_md()
173
174
  add_source_path_in_md()
174
175
  @lines = MdConverter.new().convert_for_image(@lines)
175
- @qiita_id, @patch = select_patch_or_post(@conts, @option)
176
+ @qiita_id, @patch = select_patch_or_post(@src, @option)
177
+ @conts, @option = check_change_public(@conts, @option, @qiita_id) if (@patch and @option == "private")
176
178
  @twitter = select_twitter(@conts, @option)
177
179
  @qiita, @private = select_option(@option)
178
180
  @res = qiita_post()
179
181
  get_and_print_qiita_return()
180
182
 
181
- #open_qiita()
182
- FileOpen.new(@os).file_open(@res_body["url"]) if @display != "suppress"
183
+ @base.file_open(@os, @res_body["url"]) if @display != "suppress"
183
184
 
184
185
  add_qiita_id_on_org()
185
186
 
@@ -1,33 +1,27 @@
1
1
  require "colorize"
2
2
  require "io/console"
3
- require "qiita_org/get_file_path.rb"
4
- require "qiita_org/show_file_and_url.rb"
5
- require "qiita_org/file_open.rb"
6
- require "qiita_org/set_config.rb"
7
3
  require "qiita_org/access_qiita.rb"
8
4
 
9
- class QiitaUpLoad
5
+ class QiitaFileUpLoad
10
6
  def initialize(src, option, os)
11
7
  @src = src
12
8
  @option = (option == "qiita" || option == "open")? "public" : option
13
9
  @os = os
14
- @fileopen = FileOpen.new(@os)
10
+ @base = QiitaBase.new()
11
+ @access_token, @teams_url, @display, @ox_qmd_load_path = QiitaBase.new().set_config()
12
+ ErrorMessage.new().teams_url_error(@teams_url) if @option == "teams"
15
13
  end
16
14
 
17
15
  def upload()
18
- paths = GetFilePath.new(@src).get_file_path()
19
- #paths = get_file_path(@src)
16
+ paths = get_file_path(@src)
20
17
  unless paths.empty?
21
- showfile = ShowFile.new(paths, @src, @option, @os)
22
- showfile.open_file_dir() #open_file_dir(paths)
23
- showfile.open_qiita() #open_qiita()
18
+ open_file_dir(paths)
19
+ open_qiita()
24
20
 
25
21
  puts "Overwrite file URL's on #{@src}? (y/n)".green
26
22
  ans = STDIN.getch
27
23
 
28
- if ans == "y"
29
- showfile.input_url_to_org()
30
- end
24
+ input_url_to_org(paths) if ans == "y"
31
25
  else
32
26
  puts "file path is empty.".red
33
27
  end
@@ -52,32 +46,27 @@ class QiitaUpLoad
52
46
  def open_file_dir(paths)
53
47
  previous_paths = []
54
48
  previous_paths << File.join(paths[0].split("/")[0..-2])
55
- @fileopen.file_open(File.join(paths[0].split("/")[0..-2]))
49
+ @base.file_open(@os, File.join(paths[0].split("/")[0..-2]))
56
50
 
57
51
  paths.each do |path|
58
52
  dir_path = File.join(path.split("/")[0..-2])
59
53
  unless previous_paths.include?(dir_path)
60
54
  previous_paths << dir_path
61
- @fileopen.file_open(dir_path)
55
+ @base.file_open(@os, dir_path)
62
56
  end
63
57
  end
64
58
  end
65
59
 
66
60
  def open_qiita()
67
- conts = File.read(@src)
68
- id = conts.match(/\#\+qiita_#{option}: (.+)/)[1]
69
-
70
- @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
71
- if @option == "teams"
72
- ErrorMassage.new().teams_url_error(@teams_url)
73
- end
61
+ id = QiitaBase.new().get_report_id(@src, @option)
74
62
 
75
63
  qiita = (@option == "teams") ? @teams_url : "https://qiita.com/"
76
64
  path = "api/v2/items/#{id}"
77
65
 
78
- items = AccessQiita.new(@access_token, qiita, path).access_qiita()
66
+ @access = AccessQiita.new(@access_token, qiita, path)
67
+ items = @access.access_qiita()
79
68
 
80
- @fileopen.file_open(items["url"])
69
+ @base.file_open(@os, items["url"])
81
70
  end
82
71
 
83
72
  def input_url_to_org(paths)
@@ -87,7 +76,12 @@ class QiitaUpLoad
87
76
 
88
77
  paths.each do |path|
89
78
  file_name = File.basename(path).strip
90
- url = get_file_url(id, file_name)
79
+ #url = (get_file_url(id, file_name)) ? @file_url : next
80
+ if get_file_url(id, file_name)
81
+ url = @file_url
82
+ else
83
+ next
84
+ end
91
85
  lines.each_with_index do |line, i|
92
86
  if line.match(/\[\[file:#{path}\]\]/)
93
87
  lines[i] = "[[#{url}][file:#{path}]]\n"
@@ -97,4 +91,20 @@ class QiitaUpLoad
97
91
 
98
92
  File.write(@src, lines.join)
99
93
  end
94
+
95
+ def get_file_url(id, file_name)
96
+ qiita = (@option == "teams")? @teams_url : "https://qiita.com/"
97
+ path = "api/v2/items/#{@id}"
98
+
99
+ items = @access.access_qiita()
100
+
101
+ if items["body"].match?(/\!\[#{file_name}\]\(((.+))\)/)
102
+ @file_url = items["body"].match(/\!\[#{file_name}\]\(((.+))\)/)[2]
103
+ puts "Wrote #{file_name}'s URL".green
104
+ return true
105
+ else
106
+ puts "Can not find #{file_name}'s URL".red
107
+ return false
108
+ end
109
+ end
100
110
  end
@@ -1,3 +1,3 @@
1
1
  module QiitaOrg
2
- VERSION = "0.1.30"
2
+ VERSION = "0.1.35"
3
3
  end
@@ -1,4 +1,5 @@
1
- #+qiita_private: e87e38157a72b4c2e839
1
+ #+qiita_private: 4a238f55b2014ae6494e
2
+ # +qiita_private: e87e38157a72b4c2e839
2
3
  # +qiita_private: 5f8c73e8007e52ef3f40
3
4
  # +qiita_private: 4decbf7a81ef2327643f
4
5
  #+OPTIONS: ^:{}
@@ -1,4 +1,3 @@
1
- #+qiita_teams: 7e95d62ebdbedd022256
2
1
  #+qiita_private: 6ce39fa8ae7f7a472cf2
3
2
  #+OPTIONS: ^:{}
4
3
  #+STARTUP: indent nolineimages
@@ -19,6 +18,6 @@ fogefoge
19
18
  #+ATTR_LATEX: :width 8cm
20
19
  [[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png][file:../figs/fig1.png]]
21
20
 
22
- [[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png][file:../figs/fig1.png]]
21
+ [[file:../figs/fig2.png]]
23
22
 
24
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita_org
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Yamamoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-26 00:00:00.000000000 Z
11
+ date: 2020-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -562,10 +562,7 @@ files:
562
562
  - gems/ruby/2.7.0/cache/yard-activesupport-concern-0.0.1.gem
563
563
  - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/ffi-1.13.1/ffi_c.bundle
564
564
  - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/ffi-1.13.1/gem.build_complete
565
- - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/ffi-1.13.1/gem_make.out
566
- - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/ffi-1.13.1/mkmf.log
567
565
  - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/redcarpet-3.5.0/gem.build_complete
568
- - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/redcarpet-3.5.0/gem_make.out
569
566
  - gems/ruby/2.7.0/extensions/x86_64-darwin-17/2.7.0/redcarpet-3.5.0/redcarpet.bundle
570
567
  - gems/ruby/2.7.0/gems/coderay-1.1.3/MIT-LICENSE
571
568
  - gems/ruby/2.7.0/gems/coderay-1.1.3/README_INDEX.rdoc
@@ -784,7 +781,6 @@ files:
784
781
  - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/.libs/libffi.lai
785
782
  - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/.libs/libffi_convenience.la
786
783
  - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/Makefile
787
- - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/config.log
788
784
  - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/config.status
789
785
  - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/fficonfig.h
790
786
  - gems/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c/libffi-x86_64-darwin17/include/Makefile
@@ -2558,32 +2554,31 @@ files:
2558
2554
  - lib/qiita_org/.qiita.conf
2559
2555
  - lib/qiita_org/access_qiita.rb
2560
2556
  - lib/qiita_org/all.rb
2561
- - lib/qiita_org/check_pc_os.rb
2557
+ - lib/qiita_org/base.rb
2562
2558
  - lib/qiita_org/config.json
2563
2559
  - lib/qiita_org/config.rb
2564
- - lib/qiita_org/decide_option.rb
2565
2560
  - lib/qiita_org/error_message.rb
2566
- - lib/qiita_org/file_open.rb
2567
2561
  - lib/qiita_org/get.rb
2568
- - lib/qiita_org/get_file_path.rb
2569
- - lib/qiita_org/get_file_url.rb
2570
2562
  - lib/qiita_org/get_multiple_files.rb
2571
2563
  - lib/qiita_org/get_template.rb
2572
- - lib/qiita_org/hoge.txt
2573
2564
  - lib/qiita_org/list.rb
2574
2565
  - lib/qiita_org/md_converter_for_image.rb
2566
+ - lib/qiita_org/old_programs/check_pc_os.rb
2567
+ - lib/qiita_org/old_programs/decide_option.rb
2568
+ - lib/qiita_org/old_programs/file_open.rb
2569
+ - lib/qiita_org/old_programs/get_file_path.rb
2570
+ - lib/qiita_org/old_programs/get_file_url.rb
2571
+ - lib/qiita_org/old_programs/search_conf_path.rb
2572
+ - lib/qiita_org/old_programs/select_path.rb
2573
+ - lib/qiita_org/old_programs/set_config.rb
2574
+ - lib/qiita_org/old_programs/show_file_and_url.rb
2575
2575
  - lib/qiita_org/ox-qmd/ox-qmd.el
2576
2576
  - lib/qiita_org/post.rb
2577
- - lib/qiita_org/search_conf_path.rb
2578
- - lib/qiita_org/select_path.rb
2579
- - lib/qiita_org/set_config.rb
2580
- - lib/qiita_org/show_file_and_url.rb
2581
2577
  - lib/qiita_org/template.org
2582
2578
  - lib/qiita_org/upload.rb
2583
2579
  - lib/qiita_org/version.rb
2584
2580
  - qiita_org.gemspec
2585
2581
  - tests/hoge.rb
2586
- - tests/template.org
2587
2582
  - tests/test.html
2588
2583
  - tests/test.org
2589
2584
  - tests/test2.org
@@ -1,3 +0,0 @@
1
- ProductName: Mac OS X
2
- ProductVersion: 10.13.3
3
- BuildVersion: 17D102
@@ -1,14 +0,0 @@
1
- #+qiita_private: baededc5aa906407da33
2
- #+OPTIONS: ^:{}
3
- #+STARTUP: indent nolineimages
4
- #+TITLE: title
5
- #+AUTHOR: Kenta Yamamoto
6
- #+EMAIL: (concat "doi35077@kwansei.ac.jp")
7
- #+LANGUAGE: jp
8
- # +OPTIONS: H:4 toc:t num:2
9
- #+OPTIONS: toc:nil
10
- #+TAG: tag1, tag2
11
- #+TWITTER: off
12
- # +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
13
-
14
- ![Mac OS X-10.13.3](https://img.shields.io/badge/MacOSX-10.13.3-brightgreen) ![ruby-2.7.0p0](https://img.shields.io/badge/ruby-2.7.0p0-brightgreen)