qiita_org 0.1.28 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/qiita_org.rb +34 -37
- data/lib/qiita_org/access_qiita.rb +0 -2
- data/lib/qiita_org/all.rb +22 -4
- data/lib/qiita_org/base.rb +88 -0
- data/lib/qiita_org/config.rb +3 -2
- data/lib/qiita_org/get.rb +6 -43
- data/lib/qiita_org/get_multiple_files.rb +4 -3
- data/lib/qiita_org/get_template.rb +19 -33
- data/lib/qiita_org/list.rb +7 -34
- data/lib/qiita_org/{check_pc_os.rb → old_programs/check_pc_os.rb} +0 -0
- data/lib/qiita_org/{decide_option.rb → old_programs/decide_option.rb} +0 -0
- data/lib/qiita_org/{get_file_path.rb → old_programs/get_file_path.rb} +0 -0
- data/lib/qiita_org/{get_file_url.rb → old_programs/get_file_url.rb} +0 -0
- data/lib/qiita_org/{search_conf_path.rb → old_programs/search_conf_path.rb} +0 -0
- data/lib/qiita_org/{select_path.rb → old_programs/select_path.rb} +0 -0
- data/lib/qiita_org/{set_config.rb → old_programs/set_config.rb} +0 -0
- data/lib/qiita_org/{show_file_and_url.rb → old_programs/show_file_and_url.rb} +2 -1
- data/lib/qiita_org/post.rb +26 -16
- data/lib/qiita_org/upload.rb +45 -13
- data/lib/qiita_org/version.rb +1 -1
- data/tests/test.org +2 -1
- data/tests/test2.org +1 -1
- metadata +11 -11
- data/tests/template.org +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c62db4cbaa124181ee7ac6a7051ee752f5ba1a11ea4bdc3b949880b859de183b
|
4
|
+
data.tar.gz: 0400a11c712f89e91977560e659505306e8b366a25ff57fc0f06f1a3b4db6dad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae78c2320afc2a1a0efe7ec593a3c074a3dfc256460388105ff969b69ea0a213c418d025e55bf2556a7b0927691234fd485eaed3d839d5c93a1e477a969090e
|
7
|
+
data.tar.gz: 8b4517c1aebd8150c00b956703958d4fb2a72fb00b7307b7aceefc19c188bed90e3b187d06f9b0f04c439e2bfda785bcb5a31ce221d78a5546d60dd9175f6551
|
data/Gemfile.lock
CHANGED
data/lib/qiita_org.rb
CHANGED
@@ -9,12 +9,13 @@ 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"
|
12
|
+
#require "qiita_org/check_pc_os"
|
13
13
|
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"
|
14
|
+
#require "qiita_org/get_file_path"
|
15
|
+
#require "qiita_org/show_file_and_url"
|
16
|
+
#require "qiita_org/decide_option"
|
17
17
|
require "qiita_org/get_multiple_files"
|
18
|
+
require "qiita_org/base"
|
18
19
|
#require "qiita_org/qiita_org_thor"
|
19
20
|
|
20
21
|
module QiitaOrg
|
@@ -25,6 +26,7 @@ module QiitaOrg
|
|
25
26
|
#
|
26
27
|
def initialize(*argv)
|
27
28
|
super(*argv)
|
29
|
+
@base = QiitaBase.new()
|
28
30
|
end
|
29
31
|
|
30
32
|
desc "say_hello", "say_hello"
|
@@ -37,17 +39,21 @@ module QiitaOrg
|
|
37
39
|
desc "post [FILE] [private/public/teams]", "post to qiita from org"
|
38
40
|
|
39
41
|
def post(*argv)
|
40
|
-
checkos = CheckPcOs.new
|
41
|
-
os = checkos.return_os()
|
42
|
+
#checkos = CheckPcOs.new
|
43
|
+
#os = checkos.return_os()
|
44
|
+
os = @base.check_pc_os()
|
42
45
|
|
43
46
|
if argv.size > 2
|
44
47
|
GetMultipleFiles.new(argv, os, "post").run()
|
45
|
-
elsif argv
|
46
|
-
|
48
|
+
elsif argv.size > 1
|
49
|
+
if argv[-1].match(/(.+).org/)
|
50
|
+
GetMultipleFiles.new(argv, os, "post").run()
|
51
|
+
end
|
47
52
|
else
|
48
53
|
p ["in qiita_org.rb", argv]
|
49
54
|
p file = argv[0] || "README.org"
|
50
|
-
p mode = argv[1] || DecideOption.new(file).decide_option()
|
55
|
+
#p mode = argv[1] || DecideOption.new(file).decide_option()
|
56
|
+
p mode = argv[1] || @base.pick_up_option(file)
|
51
57
|
qiita = QiitaPost.new(file, mode, os)
|
52
58
|
begin
|
53
59
|
qiita.select_option(mode)
|
@@ -62,35 +68,23 @@ module QiitaOrg
|
|
62
68
|
desc "upload [FILE] [teams/public/private]", "upload about image to qiita"
|
63
69
|
|
64
70
|
def upload(*argv)
|
65
|
-
checkos = CheckPcOs.new
|
66
|
-
os = checkos.return_os()
|
71
|
+
#checkos = CheckPcOs.new
|
72
|
+
#os = checkos.return_os()
|
73
|
+
os = @base.check_pc_os()
|
67
74
|
|
68
75
|
if argv.size > 2
|
69
76
|
GetMultipleFiles.new(argv, os, "upload").run()
|
70
|
-
elsif argv
|
71
|
-
|
77
|
+
elsif argv.size > 1
|
78
|
+
if argv[-1].match(/(.+).org/)
|
79
|
+
GetMultipleFiles.new(argv, os, "upload").run()
|
80
|
+
end
|
72
81
|
else
|
73
82
|
p file = argv[0] || "README.org"
|
74
|
-
p mode = argv[1] || DecideOption.new(file).decide_option()
|
83
|
+
#p mode = argv[1] || DecideOption.new(file).decide_option()
|
84
|
+
p mode = argv[1] || @base.pick_up_option(file)
|
75
85
|
|
76
|
-
qiita =
|
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()
|
91
|
-
end
|
86
|
+
qiita = QiitaFileUpLoad.new(file, mode, os).upload()
|
92
87
|
end
|
93
|
-
=end
|
94
88
|
end
|
95
89
|
|
96
90
|
desc "config [global/local] [option] [input]", "set config"
|
@@ -115,17 +109,20 @@ module QiitaOrg
|
|
115
109
|
desc "template", "make template.org"
|
116
110
|
|
117
111
|
def template(*argv)
|
118
|
-
checkos = CheckPcOs.new
|
119
|
-
os = checkos.return_os()
|
112
|
+
#checkos = CheckPcOs.new
|
113
|
+
#os = checkos.return_os()
|
114
|
+
os = @base.check_pc_os()
|
115
|
+
filename = argv[0] || "template.org"
|
116
|
+
filename = (filename.include?(".org"))? filename : "#{filename}.org"
|
120
117
|
|
121
|
-
template = QiitaGetTemplate.new(os).run()
|
118
|
+
template = QiitaGetTemplate.new(os, filename).run()
|
122
119
|
end
|
123
120
|
|
124
|
-
desc "all", "post all org files in the directory"
|
121
|
+
desc "all [teams/public/private] [options]", "post all org files in the directory"
|
125
122
|
|
126
123
|
def all(*argv)
|
127
|
-
mode = argv[0] || false
|
128
|
-
QiitaAll.new(
|
124
|
+
#mode = argv[0] || false
|
125
|
+
QiitaAll.new(argv).run()
|
129
126
|
end
|
130
127
|
|
131
128
|
desc "list [qiita/teams]", "view qiita report list"
|
data/lib/qiita_org/all.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require "colorize"
|
2
2
|
|
3
3
|
class QiitaAll
|
4
|
-
def initialize(
|
5
|
-
|
4
|
+
def initialize(argv)
|
5
|
+
check_options(argv)
|
6
6
|
@files = Dir.glob("*.org")
|
7
7
|
p @files
|
8
8
|
end
|
9
9
|
|
10
10
|
def run()
|
11
11
|
@files.each do |file|
|
12
|
-
|
13
|
-
|
12
|
+
unless @exclude_files.empty?
|
13
|
+
if @exclude_files.include?(file)
|
14
|
+
next
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
unless @mode
|
@@ -28,4 +30,20 @@ class QiitaAll
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
33
|
+
|
34
|
+
def check_options(string)
|
35
|
+
["teams", "private", "public"].each do |i|
|
36
|
+
if string.include?(i)
|
37
|
+
@mode = i
|
38
|
+
break
|
39
|
+
else
|
40
|
+
@mode = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@exclude_files = []
|
45
|
+
if string.include?("--exclude")
|
46
|
+
@exclude_files = string.grep(/.org/)
|
47
|
+
end
|
48
|
+
end
|
31
49
|
end
|
@@ -0,0 +1,88 @@
|
|
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
|
+
end
|
data/lib/qiita_org/config.rb
CHANGED
@@ -7,8 +7,9 @@ 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
|
+
#search = SearchConfPath.new(Dir.pwd, Dir.home)
|
11
|
+
#conf_dir = search.search_conf_path()
|
12
|
+
conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
|
12
13
|
if @option == "set"
|
13
14
|
@setup = File.join(Dir.pwd, ".qiita.conf")
|
14
15
|
else
|
data/lib/qiita_org/get.rb
CHANGED
@@ -3,8 +3,8 @@ 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"
|
6
|
+
#require "qiita_org/select_path.rb"
|
7
|
+
#require "qiita_org/set_config.rb"
|
8
8
|
require "qiita_org/error_message.rb"
|
9
9
|
require "qiita_org/access_qiita.rb"
|
10
10
|
|
@@ -12,47 +12,10 @@ class QiitaGet
|
|
12
12
|
def initialize(mode, id)
|
13
13
|
@mode = mode
|
14
14
|
@get_id = id
|
15
|
-
@
|
15
|
+
@base = QiitaBase.new()
|
16
|
+
# @selectpath = SelectPath.new()
|
16
17
|
end
|
17
18
|
|
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
19
|
# select report
|
57
20
|
def select_report()
|
58
21
|
@items.each do |item|
|
@@ -159,13 +122,13 @@ EOS
|
|
159
122
|
end
|
160
123
|
|
161
124
|
def run()
|
162
|
-
@access_token, @teams_url, @display, @ox_qmd_load_path =
|
125
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
|
163
126
|
if @mode == "teams"
|
164
127
|
ErrorMessage.new().teams_url_error(@teams_url)
|
165
128
|
end
|
166
129
|
|
167
130
|
if @get_id == nil
|
168
|
-
@qiita, @path = @
|
131
|
+
@qiita, @path = @base.select_access_path(@mode, @teams_url)
|
169
132
|
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
170
133
|
select_report()
|
171
134
|
else
|
@@ -2,7 +2,7 @@ require "colorize"
|
|
2
2
|
#require "../qiita_org/qiita_org.rb"
|
3
3
|
require "qiita_org/post.rb"
|
4
4
|
require "qiita_org/upload.rb"
|
5
|
-
require "qiita_org/decide_option.rb"
|
5
|
+
#require "qiita_org/decide_option.rb"
|
6
6
|
|
7
7
|
class GetMultipleFiles
|
8
8
|
def initialize(files, os, type)
|
@@ -19,7 +19,8 @@ class GetMultipleFiles
|
|
19
19
|
def run()
|
20
20
|
puts "post files: #{@files}".green
|
21
21
|
@files.each do |file|
|
22
|
-
mode = @option || DecideOption.new(file).decide_option()
|
22
|
+
#mode = @option || DecideOption.new(file).decide_option()
|
23
|
+
mode = @option || QiitaBase.new().pick_up_option(file)
|
23
24
|
puts "qiita #{@type} #{file} #{mode}".green
|
24
25
|
if @type == "post"
|
25
26
|
qiita = QiitaPost.new(file, mode, @os)
|
@@ -31,7 +32,7 @@ class GetMultipleFiles
|
|
31
32
|
qiita.run
|
32
33
|
end
|
33
34
|
elsif @type == "upload"
|
34
|
-
|
35
|
+
QiitaFileUpLoad.new(file, mode, @os).upload()
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "colorize"
|
3
3
|
require "kconv"
|
4
|
-
require "qiita_org/search_conf_path"
|
4
|
+
#require "qiita_org/search_conf_path"
|
5
5
|
require "qiita_org/error_message.rb"
|
6
6
|
|
7
7
|
class QiitaGetTemplate
|
8
|
-
def initialize(os)
|
8
|
+
def initialize(os, filename)
|
9
9
|
@os = os
|
10
|
-
|
11
|
-
|
10
|
+
@filename = filename
|
11
|
+
#search = SearchConfPath.new(Dir.pwd, Dir.home)
|
12
|
+
# @conf_dir = search.search_conf_path()
|
13
|
+
@conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
|
12
14
|
# check_write_header()
|
13
15
|
end
|
14
16
|
|
@@ -18,9 +20,9 @@ class QiitaGetTemplate
|
|
18
20
|
m = []
|
19
21
|
m = version.match(/ProductName:\t(.+)\nProductVersion:\t(.+)\nBuildVersion:\t(.+)\n/)
|
20
22
|
system 'rm hoge.txt'
|
21
|
-
conts = File.read(
|
23
|
+
conts = File.read(@filename)
|
22
24
|
conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1].gsub(" ", "")}-#{m[2]}-brightgreen) "
|
23
|
-
File.write(
|
25
|
+
File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
|
24
26
|
end
|
25
27
|
|
26
28
|
def get_windowsos_version()
|
@@ -33,9 +35,9 @@ class QiitaGetTemplate
|
|
33
35
|
m2 = version2.match(/OSArchitecture\n(.+)-bit/)
|
34
36
|
system 'rm hoge1.txt'
|
35
37
|
system 'rm hoge2.txt'
|
36
|
-
conts = File.read(
|
38
|
+
conts = File.read(@filename)
|
37
39
|
conts << "![#{m1[1]}-#{m1[2]}](https://img.shields.io/badge/#{m1[1].gsub(" ", "")}#{m1[2]}-#{m2[1]}bit-brightgreen) "
|
38
|
-
File.write(
|
40
|
+
File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
|
39
41
|
end
|
40
42
|
|
41
43
|
def get_ubuntu_version()
|
@@ -44,9 +46,9 @@ class QiitaGetTemplate
|
|
44
46
|
m = []
|
45
47
|
m = version.match(/(.+) (.+) LTS /)
|
46
48
|
system 'rm hoge.txt'
|
47
|
-
conts = File.read(
|
49
|
+
conts = File.read(@filename)
|
48
50
|
conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1]}-#{m[2]}-brightgreen) "
|
49
|
-
File.write(
|
51
|
+
File.write(@filename, conts)
|
50
52
|
end
|
51
53
|
|
52
54
|
def get_ruby_version()
|
@@ -55,9 +57,9 @@ class QiitaGetTemplate
|
|
55
57
|
m = []
|
56
58
|
m = version.match(/ruby (.+) \((.+)/)
|
57
59
|
system 'rm hoge.txt'
|
58
|
-
conts = File.read(
|
60
|
+
conts = File.read(@filename)
|
59
61
|
conts << "![ruby-#{m[1]}](https://img.shields.io/badge/ruby-#{m[1].gsub(" ", "")}-brightgreen) "
|
60
|
-
File.write(
|
62
|
+
File.write(@filename, conts) # + "ruby: # {m[1]}\n")
|
61
63
|
end
|
62
64
|
|
63
65
|
# cp template.org
|
@@ -65,11 +67,11 @@ class QiitaGetTemplate
|
|
65
67
|
lib = File.expand_path("../../../lib", __FILE__)
|
66
68
|
cp_file = File.join(lib, "qiita_org", "template.org")
|
67
69
|
|
68
|
-
if File.exists?("
|
69
|
-
puts "
|
70
|
+
if File.exists?("./#{@filename}")
|
71
|
+
puts "#{@filename} exists.".red
|
70
72
|
exit
|
71
73
|
else
|
72
|
-
FileUtils.cp(cp_file,
|
74
|
+
FileUtils.cp(cp_file, @filename, verbose: true)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -115,31 +117,15 @@ class QiitaGetTemplate
|
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
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
120
|
def set_name_and_email()
|
135
121
|
conf_path = File.join(@conf_dir, ".qiita.conf")
|
136
122
|
conf = JSON.load(File.read(conf_path))
|
137
123
|
name = conf["name"]
|
138
124
|
email = conf["email"]
|
139
|
-
conts = File.readlines(
|
125
|
+
conts = File.readlines(@filename)
|
140
126
|
conts[3] = "#+AUTHOR: #{name}\n"
|
141
127
|
conts[4] = "#+EMAIL: (concat \"#{email}\")\n"
|
142
|
-
File.write(
|
128
|
+
File.write(@filename, conts.join)
|
143
129
|
end
|
144
130
|
|
145
131
|
def run()
|
data/lib/qiita_org/list.rb
CHANGED
@@ -2,54 +2,27 @@ 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"
|
5
|
+
#require "qiita_org/select_path.rb"
|
6
|
+
#require "qiita_org/set_config.rb"
|
7
7
|
require "qiita_org/error_message.rb"
|
8
8
|
require "qiita_org/access_qiita.rb"
|
9
9
|
|
10
10
|
class QiitaList
|
11
11
|
def initialize(mode)
|
12
12
|
@mode = mode
|
13
|
-
@
|
13
|
+
@base = QiitaBase.new
|
14
|
+
# @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
15
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
|
14
16
|
if @mode == "teams"
|
15
17
|
ErrorMessage.new().teams_url_error(@teams_url)
|
16
18
|
end
|
17
19
|
|
18
|
-
@qiita, @path = SelectPath.new().select_path(@mode, @teams_url)
|
20
|
+
# @qiita, @path = SelectPath.new().select_path(@mode, @teams_url)
|
21
|
+
@qiita, @path = @base.select_access_path(@mode, @teams_url)
|
19
22
|
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
20
23
|
view_list()
|
21
24
|
end
|
22
25
|
|
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
26
|
def view_list()
|
54
27
|
@items.each do |item|
|
55
28
|
puts "title: #{item["title"]}"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -3,6 +3,7 @@ require "qiita_org/get_file_url.rb"
|
|
3
3
|
require "qiita_org/set_config.rb"
|
4
4
|
require "qiita_org/access_qiita.rb"
|
5
5
|
require "qiita_org/file_open.rb"
|
6
|
+
require "qiita_org/error_message.rb"
|
6
7
|
|
7
8
|
class ShowFile
|
8
9
|
def initialize(paths, src, mode, os)
|
@@ -52,7 +53,7 @@ class ShowFile
|
|
52
53
|
|
53
54
|
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
54
55
|
if @mode == "teams"
|
55
|
-
|
56
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
56
57
|
end
|
57
58
|
|
58
59
|
qiita = (@mode == "teams") ? @teams_url : "https://qiita.com/"
|
data/lib/qiita_org/post.rb
CHANGED
@@ -5,15 +5,17 @@ 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"
|
8
|
+
#require "qiita_org/set_config.rb"
|
9
9
|
require "qiita_org/error_message"
|
10
10
|
require "qiita_org/file_open.rb"
|
11
|
+
require "qiita_org/access_qiita.rb"
|
11
12
|
|
12
13
|
class QiitaPost
|
13
14
|
def initialize(file, option, os)
|
14
15
|
@src = file
|
15
16
|
@option = (option == "qiita" || option == "open")? "public" : option
|
16
17
|
@os = os
|
18
|
+
@base = QiitaBase.new
|
17
19
|
end
|
18
20
|
|
19
21
|
public
|
@@ -64,6 +66,26 @@ class QiitaPost
|
|
64
66
|
return qiita_id, patch
|
65
67
|
end
|
66
68
|
|
69
|
+
def check_change_public(conts, option, id)
|
70
|
+
qiita = "https://qiita.com/"
|
71
|
+
path = "api/v2/items/#{id}"
|
72
|
+
items = AccessQiita.new(@access_token, qiita, path).access_qiita()
|
73
|
+
|
74
|
+
if items["private"]
|
75
|
+
return conts, option
|
76
|
+
else
|
77
|
+
option = "public"
|
78
|
+
lines = File.readlines(@src)
|
79
|
+
file = File.open(@src, "w")
|
80
|
+
lines.each_with_index do |line, i|
|
81
|
+
lines[i] = "#+qiita_#{option}: #{id}\n" if line.match(/\#\+qiita_private: (.+)/)
|
82
|
+
file.print(lines[i])
|
83
|
+
end
|
84
|
+
conts = File.read(@src)
|
85
|
+
return conts, option
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
67
89
|
# check twitter post
|
68
90
|
def select_twitter(conts, option)
|
69
91
|
option == "public" && conts.match?(/^\#\+twitter:\s*on$/i)
|
@@ -146,24 +168,11 @@ class QiitaPost
|
|
146
168
|
end
|
147
169
|
end
|
148
170
|
|
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
171
|
def run()
|
164
172
|
@conts = File.read(@src)
|
165
173
|
@title, @tags = get_title_tags(@conts)
|
166
|
-
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
174
|
+
# @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
175
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
|
167
176
|
|
168
177
|
if @option == "teams"
|
169
178
|
ErrorMessage.new().teams_url_error(@teams_url)
|
@@ -173,6 +182,7 @@ class QiitaPost
|
|
173
182
|
add_source_path_in_md()
|
174
183
|
@lines = MdConverter.new().convert_for_image(@lines)
|
175
184
|
@qiita_id, @patch = select_patch_or_post(@conts, @option)
|
185
|
+
@conts, @option = check_change_public(@conts, @option, @qiita_id) if (@patch and @option == "private")
|
176
186
|
@twitter = select_twitter(@conts, @option)
|
177
187
|
@qiita, @private = select_option(@option)
|
178
188
|
@res = qiita_post()
|
data/lib/qiita_org/upload.rb
CHANGED
@@ -1,32 +1,40 @@
|
|
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"
|
3
|
+
#require "qiita_org/get_file_path.rb"
|
4
|
+
#require "qiita_org/show_file_and_url.rb"
|
5
5
|
require "qiita_org/file_open.rb"
|
6
|
-
require "qiita_org/set_config.rb"
|
6
|
+
#require "qiita_org/set_config.rb"
|
7
7
|
require "qiita_org/access_qiita.rb"
|
8
8
|
|
9
|
-
class
|
9
|
+
class QiitaFileUpLoad
|
10
10
|
def initialize(src, option, os)
|
11
11
|
@src = src
|
12
12
|
@option = (option == "qiita" || option == "open")? "public" : option
|
13
13
|
@os = os
|
14
14
|
@fileopen = FileOpen.new(@os)
|
15
|
+
# @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
16
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = QiitaBase.new().set_config()
|
17
|
+
if @option == "teams"
|
18
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def upload()
|
18
|
-
paths = GetFilePath.new(@src).get_file_path()
|
19
|
-
|
23
|
+
#paths = GetFilePath.new(@src).get_file_path()
|
24
|
+
paths = get_file_path(@src)
|
20
25
|
unless paths.empty?
|
21
|
-
showfile = ShowFile.new(paths, @src, @option, @os)
|
22
|
-
showfile.open_file_dir()
|
23
|
-
|
26
|
+
#showfile = ShowFile.new(paths, @src, @option, @os)
|
27
|
+
#showfile.open_file_dir()
|
28
|
+
open_file_dir(paths)
|
29
|
+
#showfile.open_qiita()
|
30
|
+
open_qiita()
|
24
31
|
|
25
32
|
puts "Overwrite file URL's on #{@src}? (y/n)".green
|
26
33
|
ans = STDIN.getch
|
27
34
|
|
28
35
|
if ans == "y"
|
29
|
-
showfile.input_url_to_org()
|
36
|
+
#showfile.input_url_to_org()
|
37
|
+
input_url_to_org(paths)
|
30
38
|
end
|
31
39
|
else
|
32
40
|
puts "file path is empty.".red
|
@@ -65,17 +73,20 @@ class QiitaUpLoad
|
|
65
73
|
|
66
74
|
def open_qiita()
|
67
75
|
conts = File.read(@src)
|
68
|
-
id = conts.match(/\#\+qiita_#{option}: (.+)/)[1]
|
76
|
+
id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1]
|
69
77
|
|
78
|
+
=begin
|
70
79
|
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
71
80
|
if @option == "teams"
|
72
81
|
ErrorMassage.new().teams_url_error(@teams_url)
|
73
82
|
end
|
83
|
+
=end
|
74
84
|
|
75
85
|
qiita = (@option == "teams") ? @teams_url : "https://qiita.com/"
|
76
86
|
path = "api/v2/items/#{id}"
|
77
87
|
|
78
|
-
|
88
|
+
@access = AccessQiita.new(@access_token, qiita, path)
|
89
|
+
items = @access.access_qiita()
|
79
90
|
|
80
91
|
@fileopen.file_open(items["url"])
|
81
92
|
end
|
@@ -87,7 +98,12 @@ class QiitaUpLoad
|
|
87
98
|
|
88
99
|
paths.each do |path|
|
89
100
|
file_name = File.basename(path).strip
|
90
|
-
url = get_file_url(id, file_name)
|
101
|
+
#url = (get_file_url(id, file_name)) ? @file_url : next
|
102
|
+
if get_file_url(id, file_name)
|
103
|
+
url = @file_url
|
104
|
+
else
|
105
|
+
next
|
106
|
+
end
|
91
107
|
lines.each_with_index do |line, i|
|
92
108
|
if line.match(/\[\[file:#{path}\]\]/)
|
93
109
|
lines[i] = "[[#{url}][file:#{path}]]\n"
|
@@ -97,4 +113,20 @@ class QiitaUpLoad
|
|
97
113
|
|
98
114
|
File.write(@src, lines.join)
|
99
115
|
end
|
116
|
+
|
117
|
+
def get_file_url(id, file_name)
|
118
|
+
qiita = (@option == "teams")? @teams_url : "https://qiita.com/"
|
119
|
+
path = "api/v2/items/#{@id}"
|
120
|
+
|
121
|
+
items = @access.access_qiita()
|
122
|
+
|
123
|
+
if items["body"].match?(/\!\[#{file_name}\]\(((.+))\)/)
|
124
|
+
@file_url = items["body"].match(/\!\[#{file_name}\]\(((.+))\)/)[2]
|
125
|
+
puts "Wrote #{file_name}'s URL".green
|
126
|
+
return true
|
127
|
+
else
|
128
|
+
puts "Can not find #{file_name}'s URL".red
|
129
|
+
return false
|
130
|
+
end
|
131
|
+
end
|
100
132
|
end
|
data/lib/qiita_org/version.rb
CHANGED
data/tests/test.org
CHANGED
data/tests/test2.org
CHANGED
@@ -18,6 +18,6 @@ fogefoge
|
|
18
18
|
#+ATTR_LATEX: :width 8cm
|
19
19
|
[[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png][file:../figs/fig1.png]]
|
20
20
|
|
21
|
-
[[
|
21
|
+
[[file:../figs/fig2.png]]
|
22
22
|
|
23
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.
|
4
|
+
version: 0.1.33
|
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
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -2558,32 +2558,32 @@ files:
|
|
2558
2558
|
- lib/qiita_org/.qiita.conf
|
2559
2559
|
- lib/qiita_org/access_qiita.rb
|
2560
2560
|
- lib/qiita_org/all.rb
|
2561
|
-
- lib/qiita_org/
|
2561
|
+
- lib/qiita_org/base.rb
|
2562
2562
|
- lib/qiita_org/config.json
|
2563
2563
|
- lib/qiita_org/config.rb
|
2564
|
-
- lib/qiita_org/decide_option.rb
|
2565
2564
|
- lib/qiita_org/error_message.rb
|
2566
2565
|
- lib/qiita_org/file_open.rb
|
2567
2566
|
- lib/qiita_org/get.rb
|
2568
|
-
- lib/qiita_org/get_file_path.rb
|
2569
|
-
- lib/qiita_org/get_file_url.rb
|
2570
2567
|
- lib/qiita_org/get_multiple_files.rb
|
2571
2568
|
- lib/qiita_org/get_template.rb
|
2572
2569
|
- lib/qiita_org/hoge.txt
|
2573
2570
|
- lib/qiita_org/list.rb
|
2574
2571
|
- lib/qiita_org/md_converter_for_image.rb
|
2572
|
+
- lib/qiita_org/old_programs/check_pc_os.rb
|
2573
|
+
- lib/qiita_org/old_programs/decide_option.rb
|
2574
|
+
- lib/qiita_org/old_programs/get_file_path.rb
|
2575
|
+
- lib/qiita_org/old_programs/get_file_url.rb
|
2576
|
+
- lib/qiita_org/old_programs/search_conf_path.rb
|
2577
|
+
- lib/qiita_org/old_programs/select_path.rb
|
2578
|
+
- lib/qiita_org/old_programs/set_config.rb
|
2579
|
+
- lib/qiita_org/old_programs/show_file_and_url.rb
|
2575
2580
|
- lib/qiita_org/ox-qmd/ox-qmd.el
|
2576
2581
|
- 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
2582
|
- lib/qiita_org/template.org
|
2582
2583
|
- lib/qiita_org/upload.rb
|
2583
2584
|
- lib/qiita_org/version.rb
|
2584
2585
|
- qiita_org.gemspec
|
2585
2586
|
- tests/hoge.rb
|
2586
|
-
- tests/template.org
|
2587
2587
|
- tests/test.html
|
2588
2588
|
- tests/test.org
|
2589
2589
|
- tests/test2.org
|
data/tests/template.org
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#+OPTIONS: ^:{}
|
2
|
-
#+STARTUP: indent nolineimages
|
3
|
-
#+TITLE: title
|
4
|
-
#+AUTHOR: Kenta Yamamoto
|
5
|
-
#+EMAIL: (concat "doi35077@kwansei.ac.jp")
|
6
|
-
#+LANGUAGE: jp
|
7
|
-
# +OPTIONS: H:4 toc:t num:2
|
8
|
-
#+OPTIONS: toc:nil
|
9
|
-
#+TAG: tag1, tag2
|
10
|
-
#+TWITTER: off
|
11
|
-
# +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
|
12
|
-
|
13
|
-
 
|