qiita_org 0.1.21 → 0.1.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.yardopts +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +40 -1
- data/lib/qiita_org.rb +41 -52
- data/lib/qiita_org/.qiita.conf +7 -6
- data/lib/qiita_org/access_qiita.rb +29 -0
- data/lib/qiita_org/all.rb +50 -0
- data/lib/qiita_org/base.rb +98 -0
- data/lib/qiita_org/config.json +1 -0
- data/lib/qiita_org/config.rb +1 -2
- data/lib/qiita_org/error_message.rb +99 -0
- data/lib/qiita_org/get.rb +15 -53
- data/lib/qiita_org/get_multiple_files.rb +36 -0
- data/lib/qiita_org/get_template.rb +24 -48
- data/lib/qiita_org/list.rb +9 -39
- data/lib/qiita_org/md_converter_for_image.rb +7 -7
- 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} +6 -2
- data/lib/qiita_org/old_programs/file_open.rb +15 -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} +12 -14
- data/lib/qiita_org/{search_conf_path.rb → old_programs/search_conf_path.rb} +1 -1
- data/lib/qiita_org/old_programs/select_path.rb +16 -0
- data/lib/qiita_org/old_programs/set_config.rb +30 -0
- data/lib/qiita_org/{show_file_and_url.rb → old_programs/show_file_and_url.rb} +45 -36
- data/lib/qiita_org/post.rb +68 -50
- data/lib/qiita_org/template.org +1 -0
- data/lib/qiita_org/upload.rb +110 -0
- data/lib/qiita_org/version.rb +1 -1
- data/tests/test.org +10 -3
- data/tests/test2.org +3 -1
- data/tests/test3.org +2 -1
- data/tests/test4.org +16 -0
- data/tests/twitter_test.org +14 -0
- metadata +1614 -10
- data/lib/qiita_org/hoge.txt +0 -3
- data/tests/test2.md +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c72fb0ca25fa98881ffa0e4f000a6d18c0ad742f7771b501d5b8cc8a7d1877f
|
4
|
+
data.tar.gz: 6e131d7a573369378f002f155900851f1b11f7fe522778c9ee637b3098596a1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fab87567e4e52f3f3bb74f3cd32807e7b1ef3bcfd19fbd019891a0218489373d5ec1be694389c5815be11fc5a397287d9203e3bde9e04048a6a2a28f43e3d88a
|
7
|
+
data.tar.gz: 0daa3405f652e9c79d91e02f3b88403dc86f3d6f67012cd0f8e73123b6141d8651ae01c66ed85eb6d40d6bcdd27bea10a5c67e9a1ccd33dc3cef59c77a343cb1
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qiita_org (0.1.
|
4
|
+
qiita_org (0.1.34)
|
5
5
|
colorize
|
6
6
|
command_line (> 2.0.0)
|
7
7
|
fileutils
|
@@ -10,11 +10,42 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
+
coderay (1.1.3)
|
13
14
|
colorize (0.8.1)
|
14
15
|
command_line (2.0.1)
|
15
16
|
diff-lcs (1.4.4)
|
17
|
+
ffi (1.13.1)
|
16
18
|
fileutils (1.4.1)
|
19
|
+
formatador (0.2.5)
|
20
|
+
guard (2.16.2)
|
21
|
+
formatador (>= 0.2.4)
|
22
|
+
listen (>= 2.7, < 4.0)
|
23
|
+
lumberjack (>= 1.0.12, < 2.0)
|
24
|
+
nenv (~> 0.1)
|
25
|
+
notiffany (~> 0.0)
|
26
|
+
pry (>= 0.9.12)
|
27
|
+
shellany (~> 0.0)
|
28
|
+
thor (>= 0.18.1)
|
29
|
+
guard-yard (2.2.1)
|
30
|
+
guard (>= 1.1.0)
|
31
|
+
yard (>= 0.7.0)
|
32
|
+
listen (3.3.1)
|
33
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
34
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
35
|
+
lumberjack (1.2.8)
|
36
|
+
method_source (1.0.0)
|
37
|
+
nenv (0.3.0)
|
38
|
+
notiffany (0.1.3)
|
39
|
+
nenv (~> 0.1)
|
40
|
+
shellany (~> 0.0)
|
41
|
+
pry (0.13.1)
|
42
|
+
coderay (~> 1.1)
|
43
|
+
method_source (~> 1.0)
|
17
44
|
rake (12.3.3)
|
45
|
+
rb-fsevent (0.10.4)
|
46
|
+
rb-inotify (0.10.1)
|
47
|
+
ffi (~> 1.0)
|
48
|
+
redcarpet (3.5.0)
|
18
49
|
rspec (3.9.0)
|
19
50
|
rspec-core (~> 3.9.0)
|
20
51
|
rspec-expectations (~> 3.9.0)
|
@@ -28,16 +59,24 @@ GEM
|
|
28
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
60
|
rspec-support (~> 3.9.0)
|
30
61
|
rspec-support (3.9.3)
|
62
|
+
shellany (0.0.1)
|
31
63
|
thor (1.0.1)
|
64
|
+
yard (0.9.25)
|
65
|
+
yard-activesupport-concern (0.0.1)
|
66
|
+
yard (>= 0.8)
|
32
67
|
|
33
68
|
PLATFORMS
|
34
69
|
ruby
|
35
70
|
|
36
71
|
DEPENDENCIES
|
37
72
|
bundler (> 1.16)
|
73
|
+
guard-yard
|
38
74
|
qiita_org!
|
39
75
|
rake (~> 12.0)
|
76
|
+
redcarpet
|
40
77
|
rspec (~> 3.0)
|
78
|
+
yard
|
79
|
+
yard-activesupport-concern
|
41
80
|
|
42
81
|
BUNDLED WITH
|
43
82
|
2.1.4
|
data/lib/qiita_org.rb
CHANGED
@@ -7,21 +7,17 @@ require "qiita_org/post"
|
|
7
7
|
require "qiita_org/config"
|
8
8
|
require "qiita_org/get"
|
9
9
|
require "qiita_org/list"
|
10
|
+
require "qiita_org/all"
|
10
11
|
require "qiita_org/get_template"
|
11
|
-
require "qiita_org/
|
12
|
-
require "qiita_org/
|
13
|
-
require "qiita_org/
|
14
|
-
require "qiita_org/decide_option"
|
15
|
-
#require "qiita_org/qiita_org_thor"
|
12
|
+
require "qiita_org/upload"
|
13
|
+
require "qiita_org/get_multiple_files"
|
14
|
+
require "qiita_org/base"
|
16
15
|
|
17
16
|
module QiitaOrg
|
18
17
|
class CLI < Thor
|
19
|
-
# def initialize(*argv)
|
20
|
-
# super(*argv)
|
21
|
-
# end
|
22
|
-
#
|
23
18
|
def initialize(*argv)
|
24
19
|
super(*argv)
|
20
|
+
@base = QiitaBase.new()
|
25
21
|
end
|
26
22
|
|
27
23
|
desc "say_hello", "say_hello"
|
@@ -34,43 +30,44 @@ module QiitaOrg
|
|
34
30
|
desc "post [FILE] [private/public/teams]", "post to qiita from org"
|
35
31
|
|
36
32
|
def post(*argv)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
os = @base.check_pc_os()
|
34
|
+
|
35
|
+
if argv.size > 2
|
36
|
+
GetMultipleFiles.new(argv, os, "post").run()
|
37
|
+
else #if argv.size > 1
|
38
|
+
if argv[-1].match(/(.+).org/)
|
39
|
+
GetMultipleFiles.new(argv, os, "post").run()
|
40
|
+
else
|
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
|
52
|
+
end
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
53
56
|
desc "upload [FILE] [teams/public/private]", "upload about image to qiita"
|
54
57
|
|
55
58
|
def upload(*argv)
|
56
|
-
|
57
|
-
os = checkos.return_os()
|
58
|
-
|
59
|
-
p file = argv[0] || "README.org"
|
60
|
-
p mode = argv[1] || "private"
|
61
|
-
|
62
|
-
getpath = GetFilePath.new(file)
|
63
|
-
paths = getpath.get_file_path()
|
64
|
-
unless paths.empty?
|
65
|
-
showfile = ShowFile.new(paths, file, mode, os)
|
66
|
-
showfile.open_file_dir()
|
67
|
-
showfile.open_qiita()
|
59
|
+
os = @base.check_pc_os()
|
68
60
|
|
69
|
-
|
70
|
-
|
61
|
+
if argv.size > 2
|
62
|
+
GetMultipleFiles.new(argv, os, "upload").run()
|
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)
|
71
69
|
|
72
|
-
|
73
|
-
showfile.input_url_to_org()
|
70
|
+
qiita = QiitaFileUpLoad.new(file, mode, os).upload()
|
74
71
|
end
|
75
72
|
end
|
76
73
|
end
|
@@ -97,25 +94,17 @@ module QiitaOrg
|
|
97
94
|
desc "template", "make template.org"
|
98
95
|
|
99
96
|
def template(*argv)
|
100
|
-
|
101
|
-
|
97
|
+
os = @base.check_pc_os()
|
98
|
+
filename = argv[0] || "template.org"
|
99
|
+
filename = (filename.include?(".org"))? filename : "#{filename}.org"
|
102
100
|
|
103
|
-
template = QiitaGetTemplate.new(os)
|
101
|
+
template = QiitaGetTemplate.new(os, filename).run()
|
104
102
|
end
|
105
103
|
|
106
|
-
desc "all", "post all org
|
104
|
+
desc "all [teams/public/private] [options]", "post all org files in the directory"
|
107
105
|
|
108
106
|
def all(*argv)
|
109
|
-
|
110
|
-
puts org.blue
|
111
|
-
if File.read(org).match(/#\+qiita_(.+)/)
|
112
|
-
system ("qiita post #{org} open") if File.read(org).match(/#\+(.+)_public/)
|
113
|
-
system ("qiita post #{org} teams") if File.read(org).match(/#\+(.+)_teams/)
|
114
|
-
system ("qiita post #{org} private") if File.read(org).match(/#\+(.+)_private/)
|
115
|
-
else
|
116
|
-
system ("qiita post #{org}")
|
117
|
-
end
|
118
|
-
end
|
107
|
+
QiitaAll.new(argv).run()
|
119
108
|
end
|
120
109
|
|
121
110
|
desc "list [qiita/teams]", "view qiita report list"
|
data/lib/qiita_org/.qiita.conf
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
"name": "",
|
3
|
+
"email": "",
|
4
|
+
"access_token": "",
|
5
|
+
"teams_url": "",
|
6
|
+
"display": "open",
|
7
|
+
"ox_qmd_load_path": "~/.emacs.d/site_lisp/ox-qmd"
|
8
|
+
}
|
@@ -0,0 +1,29 @@
|
|
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
|
+
ErrorMessage.new().qiita_access_error(e)
|
24
|
+
else
|
25
|
+
items = JSON.parse(response.read)
|
26
|
+
return items
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "colorize"
|
2
|
+
|
3
|
+
class QiitaAll
|
4
|
+
def initialize(argv)
|
5
|
+
check_options(argv)
|
6
|
+
@files = Dir.glob("*.org")
|
7
|
+
p @files
|
8
|
+
end
|
9
|
+
|
10
|
+
def run()
|
11
|
+
@files.each do |file|
|
12
|
+
unless @exclude_files.empty?
|
13
|
+
next if @exclude_files.include?(file)
|
14
|
+
#if @exclude_files.include?(file)
|
15
|
+
# next
|
16
|
+
#end
|
17
|
+
end
|
18
|
+
|
19
|
+
unless @mode
|
20
|
+
puts file.blue
|
21
|
+
if File.read(file).match(/#\+qiita_(.+)/)
|
22
|
+
system ("qiita post #{file} open") if File.read(file).match(/#\+(.+)_public/)
|
23
|
+
system ("qiita post #{file} teams") if File.read(file).match(/#\+(.+)_teams/)
|
24
|
+
system ("qiita post #{file} private") if File.read(file).match(/#\+(.+)_private/)
|
25
|
+
else
|
26
|
+
system ("qiita post #{file}")
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "qiita post #{file} #{@mode}".blue
|
30
|
+
system "qiita post #{file} #{@mode}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_options(string)
|
36
|
+
["teams", "private", "public"].each do |i|
|
37
|
+
if string.include?(i)
|
38
|
+
@mode = i
|
39
|
+
break
|
40
|
+
else
|
41
|
+
@mode = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@exclude_files = []
|
46
|
+
if string.include?("--exclude")
|
47
|
+
@exclude_files = string.grep(/.org/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -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
|