qiita_org 0.1.22 → 0.1.23
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 +7 -3
- data/lib/qiita_org/.qiita.conf +6 -6
- data/lib/qiita_org/access_qiita.rb +31 -0
- data/lib/qiita_org/decide_option.rb +6 -2
- data/lib/qiita_org/error_message.rb +90 -0
- data/lib/qiita_org/file_open.rb +15 -0
- data/lib/qiita_org/get.rb +29 -25
- data/lib/qiita_org/get_file_url.rb +12 -14
- data/lib/qiita_org/get_template.rb +8 -3
- data/lib/qiita_org/list.rb +18 -16
- data/lib/qiita_org/md_converter_for_image.rb +7 -7
- data/lib/qiita_org/post.rb +47 -40
- data/lib/qiita_org/search_conf_path.rb +1 -1
- data/lib/qiita_org/select_path.rb +16 -0
- data/lib/qiita_org/set_config.rb +29 -0
- data/lib/qiita_org/show_file_and_url.rb +44 -36
- data/lib/qiita_org/upload.rb +28 -0
- data/lib/qiita_org/version.rb +1 -1
- data/tests/test.org +8 -3
- data/tests/test2.org +2 -0
- data/tests/test4.org +15 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beffdb8ca4472a742773b3f18ef4358be70621d887be94f0cc4d7db4bf703f4e
|
4
|
+
data.tar.gz: a9f1c37a7511ec9ed355c39f587511e96dac790b3be07198b54182f8ad94782b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b5a5ae877e5c0329f15285cc5de0e9382b485204825e4ecdd3a2c6234e9ee9c9b3bc108f867743ee8795672e8ae302085073e32455f600aee9be71b0c627195
|
7
|
+
data.tar.gz: cdba09e7aee71b7c21b6897e6131bad6013213abc91a407a5a6f0ce2d34125e1331755d7c7935fa5de11168c97e2674200370bb7bb0dfb99b9601052001ed690
|
data/Gemfile.lock
CHANGED
data/lib/qiita_org.rb
CHANGED
@@ -9,6 +9,7 @@ require "qiita_org/get"
|
|
9
9
|
require "qiita_org/list"
|
10
10
|
require "qiita_org/get_template"
|
11
11
|
require "qiita_org/check_pc_os"
|
12
|
+
require "qiita_org/upload"
|
12
13
|
require "qiita_org/get_file_path"
|
13
14
|
require "qiita_org/show_file_and_url"
|
14
15
|
require "qiita_org/decide_option"
|
@@ -57,8 +58,10 @@ module QiitaOrg
|
|
57
58
|
os = checkos.return_os()
|
58
59
|
|
59
60
|
p file = argv[0] || "README.org"
|
60
|
-
p mode = argv[1] ||
|
61
|
+
p mode = argv[1] || DecideOption.new(file).decide_option()
|
61
62
|
|
63
|
+
UpLoad.new(file, mode, os).upload()
|
64
|
+
=begin
|
62
65
|
getpath = GetFilePath.new(file)
|
63
66
|
paths = getpath.get_file_path()
|
64
67
|
unless paths.empty?
|
@@ -73,6 +76,7 @@ module QiitaOrg
|
|
73
76
|
showfile.input_url_to_org()
|
74
77
|
end
|
75
78
|
end
|
79
|
+
=end
|
76
80
|
end
|
77
81
|
|
78
82
|
desc "config [global/local] [option] [input]", "set config"
|
@@ -100,10 +104,10 @@ module QiitaOrg
|
|
100
104
|
checkos = CheckPcOs.new
|
101
105
|
os = checkos.return_os()
|
102
106
|
|
103
|
-
template = QiitaGetTemplate.new(os)
|
107
|
+
template = QiitaGetTemplate.new(os).run()
|
104
108
|
end
|
105
109
|
|
106
|
-
desc "all", "post all org
|
110
|
+
desc "all", "post all org files in the directory"
|
107
111
|
|
108
112
|
def all(*argv)
|
109
113
|
Dir.glob("*.org").each do |org|
|
data/lib/qiita_org/.qiita.conf
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
2
|
+
"name": "",
|
3
|
+
"email": "",
|
4
|
+
"access_token": "",
|
5
|
+
"teams_url": "",
|
6
|
+
"ox_qmd_load_path": "~/.emacs.d/site_lisp/ox-qmd"
|
7
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "qiita_org/error_message.rb"
|
3
|
+
|
4
|
+
class AccessQiita
|
5
|
+
def initialize(access_token, qiita, path)
|
6
|
+
@access_token = access_token
|
7
|
+
@qiita = qiita
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def access_qiita()
|
12
|
+
uri = URI.parse(@qiita + @path)
|
13
|
+
|
14
|
+
headers = { "Authorization" => "Bearer #{@access_token}",
|
15
|
+
"Content-Type" => "application/json" }
|
16
|
+
|
17
|
+
begin
|
18
|
+
response = URI.open(
|
19
|
+
"#{uri}",
|
20
|
+
"Authorization" => "#{headers["Authorization"]}",
|
21
|
+
)
|
22
|
+
rescue => e
|
23
|
+
#puts "#{$!}".red
|
24
|
+
#exit
|
25
|
+
ErrorMessage.new().qiita_access_error(e)
|
26
|
+
else
|
27
|
+
items = JSON.parse(response.read)
|
28
|
+
return items
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -7,8 +7,12 @@ class DecideOption
|
|
7
7
|
lines = File.readlines(@src)
|
8
8
|
|
9
9
|
lines.each do |line|
|
10
|
-
|
11
|
-
|
10
|
+
m = []
|
11
|
+
if m = line.match(/\#\+qiita_(.+): (.+)/)
|
12
|
+
option = m[1] #line.match(/\#\+qiita_(.+): (.+)/)[1]
|
13
|
+
unless option == "public" || option == "teams" || option == "private"
|
14
|
+
next
|
15
|
+
end
|
12
16
|
return option
|
13
17
|
end
|
14
18
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
class ErrorMessage
|
5
|
+
def initialize()
|
6
|
+
end
|
7
|
+
|
8
|
+
def access_token_error(access_token)
|
9
|
+
if access_token == ""
|
10
|
+
puts "Please setting ACCESS_TOKEN".red
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def teams_url_error(teams_url)
|
16
|
+
if teams_url == ""
|
17
|
+
puts "Please setting teams_url".red
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def qiita_access_error(e)
|
23
|
+
puts "#{$!}".red
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
def qiita_post_error(response)
|
28
|
+
message = response.message
|
29
|
+
if message != "Created"
|
30
|
+
if message != "OK"
|
31
|
+
if message == "Unauthorized"
|
32
|
+
puts "#{message}".red
|
33
|
+
puts "Please check your access_token.".red
|
34
|
+
exit
|
35
|
+
elsif message == "Forbidden"
|
36
|
+
puts "#{message}".red
|
37
|
+
puts "You are not authorized to access this page. please check qiita_id.".red
|
38
|
+
exit
|
39
|
+
elsif message == "Not Found"
|
40
|
+
puts "#{message}".red
|
41
|
+
exit
|
42
|
+
else
|
43
|
+
puts "#{message}".red
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def config_set_error(conf_dir)
|
51
|
+
conf_path = File.join(conf_dir, ".qiita.conf")
|
52
|
+
conf = JSON.load(File.read(conf_path))
|
53
|
+
check = true
|
54
|
+
|
55
|
+
if conf["name"] == ""
|
56
|
+
puts "Please set your name in config".red
|
57
|
+
puts "Hint: qiita config global name 'YOUR NAME'".red
|
58
|
+
puts "Hint: qiita config local name 'YOUR NAME'".red
|
59
|
+
# system "rm template.org"
|
60
|
+
check = false
|
61
|
+
end
|
62
|
+
|
63
|
+
if conf["email"] == ""
|
64
|
+
puts "Please set your email in config".red
|
65
|
+
puts "Hint: qiita config global email 'youremail@example.com'".red
|
66
|
+
puts "Hint: qiita config local name 'youremail@example.com'".red
|
67
|
+
check = false
|
68
|
+
end
|
69
|
+
unless check
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def md_file_exists?(src, res)
|
75
|
+
unless File.exists?(src.gsub(".org", ".md"))
|
76
|
+
puts "Can not make #{src.gsub(".org", ".md")}".red
|
77
|
+
puts "Please confirm emacs version.".red
|
78
|
+
exit
|
79
|
+
else
|
80
|
+
p res
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def many_tags_error(tags)
|
85
|
+
if tags.count(",") >= 5
|
86
|
+
puts "The maximum number of tag is five. Please delete some tags.".red
|
87
|
+
exit
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/qiita_org/get.rb
CHANGED
@@ -3,56 +3,55 @@ require "json"
|
|
3
3
|
require "open-uri"
|
4
4
|
require "io/console"
|
5
5
|
require "colorize"
|
6
|
-
require "qiita_org/
|
6
|
+
require "qiita_org/select_path.rb"
|
7
|
+
require "qiita_org/set_config.rb"
|
8
|
+
require "qiita_org/error_message.rb"
|
9
|
+
require "qiita_org/access_qiita.rb"
|
7
10
|
|
8
11
|
class QiitaGet
|
9
12
|
def initialize(mode, id)
|
10
13
|
@mode = mode
|
11
14
|
@get_id = id
|
12
|
-
|
13
|
-
@conf_dir = search.search_conf_path()
|
14
|
-
end
|
15
|
-
|
16
|
-
# set config
|
17
|
-
def set_config()
|
18
|
-
conf_path = File.join(@conf_dir, ".qiita.conf")
|
19
|
-
conf = JSON.load(File.read(conf_path))
|
20
|
-
@access_token = conf["access_token"]
|
21
|
-
@teams_url = conf["teams_url"]
|
15
|
+
@selectpath = SelectPath.new()
|
22
16
|
end
|
23
17
|
|
24
18
|
# select path
|
25
|
-
|
26
|
-
|
19
|
+
=begin
|
20
|
+
def select_path(mode)
|
21
|
+
case mode
|
27
22
|
when "teams"
|
28
|
-
|
29
|
-
|
23
|
+
qiita = @teams_url
|
24
|
+
path = "api/v2/items?page=1&per_page=100"
|
30
25
|
else
|
31
|
-
|
32
|
-
|
26
|
+
qiita = "https://qiita.com/"
|
27
|
+
path = "api/v2/authenticated_user/items?page=1&per_page=100"
|
33
28
|
end
|
29
|
+
return qiita, path
|
34
30
|
end
|
31
|
+
=end
|
35
32
|
|
36
33
|
# access qiita
|
34
|
+
=begin
|
37
35
|
def access_qiita()
|
38
36
|
uri = URI.parse(@qiita + @path)
|
39
37
|
|
40
|
-
headers = { "Authorization" => "Bearer #{@access_token}",
|
38
|
+
headers = { "Authorization" => "Bearer # {@access_token}",
|
41
39
|
"Content-Type" => "application/json" }
|
42
40
|
|
43
41
|
begin
|
44
42
|
response = URI.open(
|
45
|
-
"#{uri}",
|
46
|
-
"Authorization" => "#{headers["Authorization"]}",
|
43
|
+
"# {uri}",
|
44
|
+
"Authorization" => "# {headers["Authorization"]}",
|
47
45
|
)
|
48
46
|
#raise "NOT FOUND: # {@get_id} report".red
|
49
47
|
rescue => e
|
50
|
-
puts "#{$!}".red
|
48
|
+
puts "# {$!}".red
|
51
49
|
exit
|
52
50
|
else
|
53
51
|
@items = JSON.parse(response.read)
|
54
52
|
end
|
55
53
|
end
|
54
|
+
=end
|
56
55
|
|
57
56
|
# select report
|
58
57
|
def select_report()
|
@@ -141,7 +140,8 @@ EOS
|
|
141
140
|
end
|
142
141
|
@path = "api/v2/items/#{@get_id}"
|
143
142
|
|
144
|
-
access_qiita()
|
143
|
+
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
144
|
+
#access_qiita()
|
145
145
|
|
146
146
|
@title = @items["title"]
|
147
147
|
@id = @items["id"]
|
@@ -159,10 +159,14 @@ EOS
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def run()
|
162
|
-
set_config()
|
162
|
+
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
163
|
+
if @mode == "teams"
|
164
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
165
|
+
end
|
166
|
+
|
163
167
|
if @get_id == nil
|
164
|
-
select_path()
|
165
|
-
access_qiita()
|
168
|
+
@qiita, @path = @selectpath.select_path(@mode)
|
169
|
+
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
166
170
|
select_report()
|
167
171
|
else
|
168
172
|
get_id_report()
|
@@ -3,30 +3,26 @@ require "json"
|
|
3
3
|
require "open-uri"
|
4
4
|
require "io/console"
|
5
5
|
require "colorize"
|
6
|
-
require "qiita_org/
|
6
|
+
require "qiita_org/set_config.rb"
|
7
|
+
require "qiita_org/error_message.rb"
|
8
|
+
require "qiita_org/access_qiita.rb"
|
7
9
|
|
8
10
|
class GetFileUrl
|
9
11
|
def initialize(id, file, mode)
|
10
12
|
@id = id
|
11
13
|
@file = file
|
12
14
|
@mode = (mode == "qiita" || mode == "open")? "public" : mode
|
13
|
-
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def set_config()
|
19
|
-
conf_path = File.join(@conf_dir, ".qiita.conf")
|
20
|
-
@conf = JSON.load(File.read(conf_path))
|
21
|
-
@access_token = @conf["access_token"]
|
22
|
-
@teams_url = @conf["teams_url"]
|
15
|
+
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
16
|
+
if @mode == "teams"
|
17
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
18
|
+
end
|
23
19
|
end
|
24
20
|
|
25
21
|
def get_file_url()
|
26
22
|
qiita = (@mode == "teams")? @teams_url : "https://qiita.com/"
|
27
23
|
path = "api/v2/items/#{@id}"
|
28
24
|
|
29
|
-
items =
|
25
|
+
items = AccessQiita.new(@access_token, qiita, path).access_qiita()
|
30
26
|
|
31
27
|
file_url = items["body"].match(/\!\[#{@file}\]\(((.+))\)/)[2]
|
32
28
|
return file_url
|
@@ -34,6 +30,7 @@ class GetFileUrl
|
|
34
30
|
#File.write("url_text.md", items["body"])
|
35
31
|
end
|
36
32
|
|
33
|
+
=begin
|
37
34
|
def access_qiita(access_token, qiita, path)
|
38
35
|
uri = URI.parse(qiita + path)
|
39
36
|
|
@@ -41,10 +38,11 @@ class GetFileUrl
|
|
41
38
|
"Content-Type" => "application/json" }
|
42
39
|
|
43
40
|
response = URI.open(
|
44
|
-
"#{uri}",
|
45
|
-
"Authorization" => "#{headers["Authorization"]}",
|
41
|
+
"# {uri}",
|
42
|
+
"Authorization" => "# {headers["Authorization"]}",
|
46
43
|
)
|
47
44
|
items = JSON.parse(response.read)
|
48
45
|
return items
|
49
46
|
end
|
47
|
+
=end
|
50
48
|
end
|
@@ -2,16 +2,14 @@ require "fileutils"
|
|
2
2
|
require "colorize"
|
3
3
|
require "kconv"
|
4
4
|
require "qiita_org/search_conf_path"
|
5
|
+
require "qiita_org/error_message.rb"
|
5
6
|
|
6
7
|
class QiitaGetTemplate
|
7
8
|
def initialize(os)
|
8
9
|
@os = os
|
9
|
-
cp_template()
|
10
10
|
search = SearchConfPath.new(Dir.pwd, Dir.home)
|
11
11
|
@conf_dir = search.search_conf_path()
|
12
|
-
set_name_and_email()
|
13
12
|
# check_write_header()
|
14
|
-
check_write_contents()
|
15
13
|
end
|
16
14
|
|
17
15
|
def get_macos_version()
|
@@ -143,4 +141,11 @@ class QiitaGetTemplate
|
|
143
141
|
conts[4] = "#+EMAIL: (concat \"#{email}\")\n"
|
144
142
|
File.write("template.org", conts.join)
|
145
143
|
end
|
144
|
+
|
145
|
+
def run()
|
146
|
+
ErrorMessage.new().config_set_error(@conf_dir)
|
147
|
+
cp_template()
|
148
|
+
set_name_and_email()
|
149
|
+
check_write_contents()
|
150
|
+
end
|
146
151
|
end
|
data/lib/qiita_org/list.rb
CHANGED
@@ -2,27 +2,26 @@ require "net/https"
|
|
2
2
|
require "json"
|
3
3
|
require "open-uri"
|
4
4
|
require "colorize"
|
5
|
-
require "qiita_org/
|
5
|
+
require "qiita_org/select_path.rb"
|
6
|
+
require "qiita_org/set_config.rb"
|
7
|
+
require "qiita_org/error_message.rb"
|
8
|
+
require "qiita_org/access_qiita.rb"
|
6
9
|
|
7
10
|
class QiitaList
|
8
11
|
def initialize(mode)
|
9
12
|
@mode = mode
|
10
|
-
|
11
|
-
@
|
12
|
-
|
13
|
-
|
14
|
-
access_qiita()
|
15
|
-
view_list()
|
16
|
-
end
|
13
|
+
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
14
|
+
if @mode == "teams"
|
15
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@access_token = conf["access_token"]
|
22
|
-
@teams_url = conf["teams_url"]
|
18
|
+
@qiita, @path = SelectPath.new().select_path(@mode)
|
19
|
+
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
20
|
+
view_list()
|
23
21
|
end
|
24
22
|
|
25
23
|
# select path
|
24
|
+
=begin
|
26
25
|
def select_path()
|
27
26
|
case @mode
|
28
27
|
when "teams"
|
@@ -33,20 +32,23 @@ class QiitaList
|
|
33
32
|
@path = "api/v2/authenticated_user/items?page=1&per_page=100"
|
34
33
|
end
|
35
34
|
end
|
35
|
+
=end
|
36
36
|
|
37
37
|
# access qiita
|
38
|
+
=begin
|
38
39
|
def access_qiita()
|
39
40
|
uri = URI.parse(@qiita + @path)
|
40
41
|
|
41
|
-
headers = { "Authorization" => "Bearer #{@access_token}",
|
42
|
+
headers = { "Authorization" => "Bearer # {@access_token}",
|
42
43
|
"Content-Type" => "application/json" }
|
43
44
|
|
44
45
|
response = URI.open(
|
45
|
-
"#{uri}",
|
46
|
-
"Authorization" => "#{headers["Authorization"]}",
|
46
|
+
"# {uri}",
|
47
|
+
"Authorization" => "# {headers["Authorization"]}",
|
47
48
|
)
|
48
49
|
@items = JSON.parse(response.read)
|
49
50
|
end
|
51
|
+
=end
|
50
52
|
|
51
53
|
def view_list()
|
52
54
|
@items.each do |item|
|
@@ -1,25 +1,25 @@
|
|
1
1
|
class MdConverter
|
2
|
-
def initialize(
|
3
|
-
@lines = lines
|
2
|
+
def initialize()
|
3
|
+
# @lines = lines
|
4
4
|
end
|
5
5
|
|
6
|
-
def convert_for_image()
|
7
|
-
|
6
|
+
def convert_for_image(lines)
|
7
|
+
lines.each_with_index do |line, i|
|
8
8
|
m = []
|
9
9
|
if m = line.match(/\[\!\[img\]\((.+) "(.+)"\)\]\((.+)\)/)
|
10
10
|
path = File.basename(m[1])
|
11
11
|
url = m[3]
|
12
|
-
|
12
|
+
lines[i] = "\n"
|
13
13
|
elsif m = line.match(/\[\!\[img\]\((.+)\)\]\((.+)\)/)
|
14
14
|
path = File.basename(m[1])
|
15
15
|
url = m[2]
|
16
|
-
|
16
|
+
lines[i] = "\n"
|
17
17
|
else
|
18
18
|
next
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
return
|
22
|
+
return lines
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/qiita_org/post.rb
CHANGED
@@ -4,29 +4,28 @@ require "net/https"
|
|
4
4
|
require "json"
|
5
5
|
require "command_line/global"
|
6
6
|
require "colorize"
|
7
|
-
require "qiita_org/search_conf_path.rb"
|
8
7
|
require "qiita_org/md_converter_for_image"
|
8
|
+
require "qiita_org/set_config.rb"
|
9
|
+
require "qiita_org/error_message"
|
10
|
+
require "qiita_org/file_open.rb"
|
9
11
|
|
10
12
|
class QiitaPost
|
11
13
|
def initialize(file, option, os)
|
12
14
|
@src = file
|
13
15
|
@option = (option == "qiita" || option == "open")? "public" : option
|
14
16
|
@os = os
|
15
|
-
search = SearchConfPath.new(Dir.pwd, Dir.home)
|
16
|
-
@conf_dir = search.search_conf_path()
|
17
|
-
p @conf_dir
|
18
17
|
end
|
19
18
|
|
20
19
|
public
|
21
|
-
def get_title_tags()
|
22
|
-
|
23
|
-
m = @conts.match(/\#\+(TITLE|title|Title): (.+)/)
|
20
|
+
def get_title_tags(conts)
|
21
|
+
m = conts.match(/\#\+(TITLE|title|Title): (.+)/)
|
24
22
|
@title = m ? m[2] : "テスト"
|
25
|
-
@tags = if m =
|
26
|
-
if m[2].count(",") >= 5
|
27
|
-
|
28
|
-
exit
|
29
|
-
end
|
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
|
+
ErrorMessage.new().many_tags_error(m[2])
|
30
29
|
m[2].split(",").inject([]) do |l, c|
|
31
30
|
l << { name: c.strip } #, versions: []}
|
32
31
|
end
|
@@ -34,22 +33,15 @@ class QiitaPost
|
|
34
33
|
[{ name: "hoge" }] #, versions: [] }]
|
35
34
|
end
|
36
35
|
p @tags
|
37
|
-
|
38
|
-
|
39
|
-
def set_config()
|
40
|
-
conf_path = File.join(@conf_dir, ".qiita.conf")
|
41
|
-
@conf = JSON.load(File.read(conf_path))
|
42
|
-
@access_token = @conf["access_token"]
|
43
|
-
@teams_url = @conf["teams_url"]
|
44
|
-
lib = File.expand_path("../../../lib", __FILE__)
|
45
|
-
@ox_qmd_load_path = File.join(lib, "qiita_org", "ox-qmd", "ox-qmd") # @conf["ox_qmd_load_path"]
|
36
|
+
return @title, @tags
|
46
37
|
end
|
47
38
|
|
48
39
|
# src.org -> src.md
|
49
40
|
def convert_org_to_md()
|
50
41
|
command = "emacs #{@src} --batch -l #{@ox_qmd_load_path} -f org-qmd-export-to-markdown --kill"
|
51
42
|
res = command_line command
|
52
|
-
p res
|
43
|
+
#p res
|
44
|
+
ErrorMessage.new().md_file_exists?(@src, res)
|
53
45
|
end
|
54
46
|
|
55
47
|
# add source path in md
|
@@ -60,15 +52,16 @@ class QiitaPost
|
|
60
52
|
end
|
61
53
|
|
62
54
|
# patch or post selector by qiita_id
|
63
|
-
def select_patch_or_post()
|
55
|
+
def select_patch_or_post(conts, option)
|
64
56
|
m = []
|
65
|
-
|
66
|
-
if m =
|
67
|
-
|
68
|
-
|
57
|
+
patch = false
|
58
|
+
if m = conts.match(/\#\+qiita_#{option}: (.+)/)
|
59
|
+
qiita_id = m[1]
|
60
|
+
patch = true
|
69
61
|
else
|
70
|
-
|
62
|
+
qiita_id = ""
|
71
63
|
end
|
64
|
+
return qiita_id, patch
|
72
65
|
end
|
73
66
|
|
74
67
|
def select_option(option)
|
@@ -110,11 +103,16 @@ class QiitaPost
|
|
110
103
|
|
111
104
|
headers = { "Authorization" => "Bearer #{@access_token}",
|
112
105
|
"Content-Type" => "application/json" }
|
106
|
+
|
113
107
|
if @patch
|
114
|
-
|
108
|
+
res = http_req.patch(uri.path, params.to_json, headers)
|
115
109
|
else
|
116
|
-
|
110
|
+
res = http_req.post(uri.path, params.to_json, headers)
|
117
111
|
end
|
112
|
+
|
113
|
+
ErrorMessage.new().qiita_post_error(res)
|
114
|
+
|
115
|
+
return res
|
118
116
|
end
|
119
117
|
|
120
118
|
# qiita return
|
@@ -140,29 +138,38 @@ class QiitaPost
|
|
140
138
|
end
|
141
139
|
|
142
140
|
# open qiita
|
141
|
+
=begin
|
143
142
|
def open_qiita()
|
144
143
|
if @os == "mac"
|
145
|
-
system "open #{@res_body["url"]}"
|
144
|
+
system "open # {@res_body["url"]}"
|
146
145
|
elsif @os == "windows"
|
147
|
-
system "explorer.exe #{@res_body["url"]}"
|
146
|
+
system "explorer.exe # {@res_body["url"]}"
|
148
147
|
else
|
149
|
-
system "open #{@res_body["url"]}"
|
150
|
-
system "xdg-open #{@res_body["url"]}"
|
148
|
+
system "open # {@res_body["url"]}"
|
149
|
+
system "xdg-open # {@res_body["url"]}"
|
151
150
|
end
|
152
151
|
end
|
152
|
+
=end
|
153
153
|
|
154
154
|
def run()
|
155
|
-
|
156
|
-
|
155
|
+
@conts = File.read(@src)
|
156
|
+
@title, @tags = get_title_tags(@conts)
|
157
|
+
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
158
|
+
|
159
|
+
if @option == "teams"
|
160
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
161
|
+
end
|
162
|
+
|
157
163
|
convert_org_to_md()
|
158
164
|
add_source_path_in_md()
|
159
|
-
@lines = MdConverter.new(
|
160
|
-
select_patch_or_post()
|
165
|
+
@lines = MdConverter.new().convert_for_image(@lines)
|
166
|
+
@qiita_id, @patch = select_patch_or_post(@conts, @option)
|
161
167
|
@qiita, @private = select_option(@option)
|
162
|
-
qiita_post()
|
168
|
+
@res = qiita_post()
|
163
169
|
get_and_print_qiita_return()
|
164
170
|
|
165
|
-
open_qiita()
|
171
|
+
#open_qiita()
|
172
|
+
FileOpen.new(@os).file_open(@res_body["url"])
|
166
173
|
|
167
174
|
add_qiita_id_on_org()
|
168
175
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class SelectPath
|
2
|
+
def initialize()
|
3
|
+
end
|
4
|
+
|
5
|
+
def select_path(mode)
|
6
|
+
case mode
|
7
|
+
when "teams"
|
8
|
+
qiita = @teams_url
|
9
|
+
path = "api/v2/items?page=1&per_page=100"
|
10
|
+
else
|
11
|
+
qiita = "https://qiita.com/"
|
12
|
+
path = "api/v2/authenticated_user/items?page=1&per_page=100"
|
13
|
+
end
|
14
|
+
return qiita, path
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "qiita_org/search_conf_path.rb"
|
2
|
+
require "qiita_org/error_message.rb"
|
3
|
+
|
4
|
+
class SetConfig
|
5
|
+
def initialize()
|
6
|
+
search = SearchConfPath.new(Dir.pwd, Dir.home)
|
7
|
+
@lib = File.expand_path("../../../lib", __FILE__)
|
8
|
+
@conf_dir = search.search_conf_path()
|
9
|
+
if @conf_dir != Dir.home
|
10
|
+
puts "config file path: #{@conf_dir.gsub(Dir.home, "~")}".green
|
11
|
+
else
|
12
|
+
puts "config file path: #{@conf_dir}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_config()
|
17
|
+
conf_path = File.join(@conf_dir, ".qiita.conf")
|
18
|
+
conf = JSON.load(File.read(conf_path))
|
19
|
+
access_token = conf["access_token"]
|
20
|
+
teams_url = conf["teams_url"]
|
21
|
+
ox_qmd_load_path = File.join(@lib, "qiita_org", "ox-qmd", "ox-qmd")
|
22
|
+
|
23
|
+
ErrorMessage.new().access_token_error(access_token) #== false
|
24
|
+
# puts "Please setting ACCESS_TOKEN".red
|
25
|
+
# exit
|
26
|
+
|
27
|
+
return access_token, teams_url, ox_qmd_load_path
|
28
|
+
end
|
29
|
+
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
require "colorize"
|
2
2
|
require "qiita_org/get_file_url.rb"
|
3
|
+
require "qiita_org/set_config.rb"
|
4
|
+
require "qiita_org/access_qiita.rb"
|
5
|
+
require "qiita_org/file_open.rb"
|
3
6
|
|
4
7
|
class ShowFile
|
5
8
|
def initialize(paths, src, mode, os)
|
6
9
|
@paths = paths
|
7
10
|
@src = src
|
8
|
-
@mode = (mode == "qiita" || mode == "open")? "public" : mode
|
11
|
+
@mode = (mode == "qiita" || mode == "open") ? "public" : mode
|
9
12
|
@os = os
|
10
|
-
|
11
|
-
@conf_dir = search.search_conf_path()
|
12
|
-
end
|
13
|
-
|
14
|
-
def set_config()
|
15
|
-
conf_path = File.join(@conf_dir, ".qiita.conf")
|
16
|
-
@conf = JSON.load(File.read(conf_path))
|
17
|
-
@access_token = @conf["access_token"]
|
18
|
-
@teams_url = @conf["teams_url"]
|
13
|
+
@fileopen = FileOpen.new(@os)
|
19
14
|
end
|
20
15
|
|
21
16
|
def open_file_dir()
|
22
17
|
previous_paths = []
|
23
18
|
previous_paths << File.join(@paths[0].split("/")[0..-2])
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
system "
|
28
|
-
|
29
|
-
system "
|
30
|
-
|
31
|
-
|
19
|
+
@fileopen.file_open(File.join(@paths[0].split("/")[0..-2]))
|
20
|
+
|
21
|
+
# if @os == "mac"
|
22
|
+
# system "open # {File.join(@paths[0].split("/")[0..-2])}"
|
23
|
+
# elsif @os == "windows"
|
24
|
+
# system "explorer.exe # {File.join(@paths[0].split("/")[0..-2])}"
|
25
|
+
# else
|
26
|
+
# system "open # {File.join(@paths[0].split("/")[0..-2])}"
|
27
|
+
# system "xdg-open # {File.join(@paths[0].split("/")[0..-2])}"
|
28
|
+
# end
|
29
|
+
|
32
30
|
@paths.each do |path|
|
33
31
|
dir_path = File.join(path.split("/")[0..-2])
|
34
32
|
unless previous_paths.include?(dir_path)
|
35
33
|
previous_paths << dir_path
|
36
|
-
#system "open #{dir_path}"
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
system "
|
41
|
-
|
42
|
-
system "
|
43
|
-
|
44
|
-
|
34
|
+
#system "open # {dir_path}"
|
35
|
+
@fileopen.file_open(dir_path)
|
36
|
+
|
37
|
+
# if @os == "mac"
|
38
|
+
# system "open # {dir_path}"
|
39
|
+
# elsif @os == "windows"
|
40
|
+
# system "explorer.exe # {dir_path}"
|
41
|
+
# else
|
42
|
+
# system "open # {dir_path}"
|
43
|
+
# system "xdg-open # {dir_path}"
|
44
|
+
# end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -50,21 +50,27 @@ class ShowFile
|
|
50
50
|
conts = File.read(@src)
|
51
51
|
id = conts.match(/\#\+qiita_#{@mode}: (.+)/)[1]
|
52
52
|
|
53
|
-
set_config()
|
53
|
+
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
54
|
+
if @mode == "teams"
|
55
|
+
ErrorMassage.new().teams_url_error(@teams_url)
|
56
|
+
end
|
54
57
|
|
55
|
-
qiita = (@mode == "teams")? @teams_url : "https://qiita.com/"
|
58
|
+
qiita = (@mode == "teams") ? @teams_url : "https://qiita.com/"
|
56
59
|
path = "api/v2/items/#{id}"
|
57
60
|
|
58
|
-
items =
|
61
|
+
items = AccessQiita.new(@access_token, qiita, path).access_qiita()
|
59
62
|
|
63
|
+
@fileopen.file_open(items["url"])
|
64
|
+
=begin
|
60
65
|
if @os == "mac"
|
61
|
-
system "open #{items["url"]}"
|
66
|
+
system "open # {items["url"]}"
|
62
67
|
elsif @os == "windows"
|
63
|
-
system "explorer.exe #{items["url"]}"
|
68
|
+
system "explorer.exe # {items["url"]}"
|
64
69
|
else
|
65
|
-
system "open #{items["url"]}"
|
66
|
-
system "xdg-open #{items["url"]}"
|
70
|
+
system "open # {items["url"]}"
|
71
|
+
system "xdg-open # {items["url"]}"
|
67
72
|
end
|
73
|
+
=end
|
68
74
|
end
|
69
75
|
|
70
76
|
def show_file_url()
|
@@ -100,6 +106,7 @@ class ShowFile
|
|
100
106
|
File.write(@src, lines.join)
|
101
107
|
end
|
102
108
|
|
109
|
+
=begin
|
103
110
|
def access_qiita(access_token, qiita, path)
|
104
111
|
uri = URI.parse(qiita + path)
|
105
112
|
|
@@ -107,10 +114,11 @@ class ShowFile
|
|
107
114
|
"Content-Type" => "application/json" }
|
108
115
|
|
109
116
|
response = URI.open(
|
110
|
-
"#{uri}",
|
111
|
-
"Authorization" => "#{headers["Authorization"]}",
|
117
|
+
"# {uri}",
|
118
|
+
"Authorization" => "# {headers["Authorization"]}",
|
112
119
|
)
|
113
120
|
items = JSON.parse(response.read)
|
114
121
|
return items
|
115
122
|
end
|
123
|
+
=end
|
116
124
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "io/console"
|
3
|
+
require "qiita_org/get_file_path.rb"
|
4
|
+
require "qiita_org/show_file_and_url.rb"
|
5
|
+
|
6
|
+
class UpLoad
|
7
|
+
def initialize(src, option, os)
|
8
|
+
@src = src
|
9
|
+
@option = (option == "qiita" || option == "open")? "public" : option
|
10
|
+
@os = os
|
11
|
+
end
|
12
|
+
|
13
|
+
def upload()
|
14
|
+
paths = GetFilePath.new(@src).get_file_path()
|
15
|
+
unless paths.empty?
|
16
|
+
showfile = ShowFile.new(paths, @src, @option, @os)
|
17
|
+
showfile.open_file_dir()
|
18
|
+
showfile.open_qiita()
|
19
|
+
|
20
|
+
puts "Overwrite file URL's on #{@src}? (y/n)".green
|
21
|
+
ans = STDIN.getch
|
22
|
+
|
23
|
+
if ans == "y"
|
24
|
+
showfile.input_url_to_org()
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/qiita_org/version.rb
CHANGED
data/tests/test.org
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
|
1
|
+
# +qiita_private: 5f8c73e8007e52ef3f40
|
2
|
+
# +qiita_private: 4decbf7a81ef2327643f
|
2
3
|
#+OPTIONS: ^:{}
|
3
4
|
#+STARTUP: indent nolineimages
|
4
5
|
#+TITLE: test
|
5
6
|
#+AUTHOR: Kenta Yamamoto
|
6
7
|
#+EMAIL: (concat "doi35077@kwansei.ac.jp")
|
8
|
+
#+qiita_id: yamatoken
|
7
9
|
#+LANGUAGE: jp
|
8
10
|
# +OPTIONS: H:4 toc:t num:2
|
9
11
|
#+OPTIONS: toc:nil
|
10
|
-
#+TAG:
|
12
|
+
#+TAG: test1, test2, test3, test4, test5
|
11
13
|
# +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
|
12
14
|
|
13
15
|
 
|
14
16
|
|
15
|
-
fogefoge
|
17
|
+
| fogefoge | fogefoge |
|
18
|
+
| foge | foge |
|
16
19
|
# +caption: example qiita template command
|
17
20
|
# +name: fig:fig1
|
18
21
|
#+ATTR_LATEX: :width 8cm
|
@@ -24,3 +27,5 @@ fogefoge
|
|
24
27
|
[[file:../figs/fig2.png]]
|
25
28
|
|
26
29
|
https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/a3b2ab02-f903-f5d6-d8b9-5407e8db5a2a.png
|
30
|
+
|
31
|
+
|
data/tests/test2.org
CHANGED
data/tests/test4.org
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#+qiita_private: 92b50b88e7da7aa25a1b
|
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
|
+
# +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
|
12
|
+
|
13
|
+
 
|
14
|
+
|
15
|
+
[[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/d0531ab8-57b7-7289-7e4f-75c9f54a45d3.png][file:../figs/fig1.png]]
|
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.23
|
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-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -957,10 +957,13 @@ files:
|
|
957
957
|
- gems/ruby/2.7.0/specifications/thor-1.0.1.gemspec
|
958
958
|
- lib/qiita_org.rb
|
959
959
|
- lib/qiita_org/.qiita.conf
|
960
|
+
- lib/qiita_org/access_qiita.rb
|
960
961
|
- lib/qiita_org/check_pc_os.rb
|
961
962
|
- lib/qiita_org/config.json
|
962
963
|
- lib/qiita_org/config.rb
|
963
964
|
- lib/qiita_org/decide_option.rb
|
965
|
+
- lib/qiita_org/error_message.rb
|
966
|
+
- lib/qiita_org/file_open.rb
|
964
967
|
- lib/qiita_org/get.rb
|
965
968
|
- lib/qiita_org/get_file_path.rb
|
966
969
|
- lib/qiita_org/get_file_url.rb
|
@@ -971,8 +974,11 @@ files:
|
|
971
974
|
- lib/qiita_org/ox-qmd/ox-qmd.el
|
972
975
|
- lib/qiita_org/post.rb
|
973
976
|
- lib/qiita_org/search_conf_path.rb
|
977
|
+
- lib/qiita_org/select_path.rb
|
978
|
+
- lib/qiita_org/set_config.rb
|
974
979
|
- lib/qiita_org/show_file_and_url.rb
|
975
980
|
- lib/qiita_org/template.org
|
981
|
+
- lib/qiita_org/upload.rb
|
976
982
|
- lib/qiita_org/version.rb
|
977
983
|
- qiita_org.gemspec
|
978
984
|
- tests/hoge.rb
|
@@ -981,6 +987,7 @@ files:
|
|
981
987
|
- tests/test2.md
|
982
988
|
- tests/test2.org
|
983
989
|
- tests/test3.org
|
990
|
+
- tests/test4.org
|
984
991
|
homepage: https://github.com/yamatoken/qiita_org
|
985
992
|
licenses:
|
986
993
|
- MIT
|