qiita_org 0.1.19 → 0.1.24

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: 48c7ed2d91e672109554b42ca394d251f6c43e820ecdaecf9954390b891c750e
4
- data.tar.gz: b07304fcad2dab5c3151fabef9ea561a3c0144d1db52dc6aee01a778a7cbd1f6
3
+ metadata.gz: ff5afe51529883ef3f843cc85608ea5eb112c97d9bee65ad71eee130e93ee3d1
4
+ data.tar.gz: b5945826738b2719a6dc861d60c920edc012db5d49e5c55d8cd464e608c9aab5
5
5
  SHA512:
6
- metadata.gz: 03d49d5477a852efb7ad002748fc684ec84373d88c7f10a5a452711b1725c05f2ade168215ad5eec18accfa9617e15600259caab7e56c55f756450336cf4c382
7
- data.tar.gz: 5af068bc255f81b4d0afcda540e998933c0317fbfe537d27f3cf75070b17bce10dc3e9c4aafb2a857c2e8d66690291b2a8197021f30f5dcf0357d03c417ad679
6
+ metadata.gz: 8c7513a96480af4381e23b729a4308265d91721f3d75984cc7d3f28a756f8a386d5aa3d49fffbd00a8f946e2fbc6c77759bb8f61df9544d415315709c1d6dfb3
7
+ data.tar.gz: 96eb5ad3f7334dd0a14fa481fd33864f03fafc6739d2f6b3ae73b60a6c98d0a07c1a7614684cd7747e0216988052a567c96b6268a387d3085fd31e568a9d8417
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_org (0.1.18)
4
+ qiita_org (0.1.24)
5
5
  colorize
6
6
  command_line (> 2.0.0)
7
7
  fileutils
@@ -9,8 +9,11 @@ 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"
15
+ require "qiita_org/decide_option"
16
+ require "qiita_org/get_multiple_files"
14
17
  #require "qiita_org/qiita_org_thor"
15
18
 
16
19
  module QiitaOrg
@@ -36,16 +39,22 @@ module QiitaOrg
36
39
  checkos = CheckPcOs.new
37
40
  os = checkos.return_os()
38
41
 
39
- p ["in qiita_org.rb", argv]
40
- p file = argv[0] || "README.org"
41
- p mode = argv[1] || "private"
42
- qiita = QiitaPost.new(file, mode, os)
43
- begin
44
- qiita.select_option(mode)
45
- rescue RuntimeError => e
46
- puts $!
42
+ if argv.size > 2
43
+ GetMultipleFiles.new(argv, os, "post").run()
44
+ elsif argv[-1].match(/(.+).org/) && argv.size != 1
45
+ GetMultipleFiles.new(argv, os, "post").run()
47
46
  else
48
- qiita.run
47
+ p ["in qiita_org.rb", argv]
48
+ p file = argv[0] || "README.org"
49
+ p mode = argv[1] || DecideOption.new(file).decide_option()
50
+ qiita = QiitaPost.new(file, mode, os)
51
+ begin
52
+ qiita.select_option(mode)
53
+ rescue RuntimeError => e
54
+ puts $!
55
+ else
56
+ qiita.run
57
+ end
49
58
  end
50
59
  end
51
60
 
@@ -55,9 +64,17 @@ module QiitaOrg
55
64
  checkos = CheckPcOs.new
56
65
  os = checkos.return_os()
57
66
 
58
- p file = argv[0] || "README.org"
59
- p mode = argv[1] || "private"
67
+ if argv.size > 2
68
+ GetMultipleFiles.new(argv, os, "upload").run()
69
+ elsif argv[-1].match(/(.+).org/) && argv.size != 1
70
+ GetMultipleFiles.new(argv, os, "upload").run()
71
+ else
72
+ p file = argv[0] || "README.org"
73
+ p mode = argv[1] || DecideOption.new(file).decide_option()
60
74
 
75
+ qiita = UpLoad.new(file, mode, os).upload()
76
+ end
77
+ =begin
61
78
  getpath = GetFilePath.new(file)
62
79
  paths = getpath.get_file_path()
63
80
  unless paths.empty?
@@ -72,6 +89,7 @@ module QiitaOrg
72
89
  showfile.input_url_to_org()
73
90
  end
74
91
  end
92
+ =end
75
93
  end
76
94
 
77
95
  desc "config [global/local] [option] [input]", "set config"
@@ -99,10 +117,10 @@ module QiitaOrg
99
117
  checkos = CheckPcOs.new
100
118
  os = checkos.return_os()
101
119
 
102
- template = QiitaGetTemplate.new(os)
120
+ template = QiitaGetTemplate.new(os).run()
103
121
  end
104
122
 
105
- desc "all", "post all org file in the directory"
123
+ desc "all", "post all org files in the directory"
106
124
 
107
125
  def all(*argv)
108
126
  Dir.glob("*.org").each do |org|
@@ -1,7 +1,7 @@
1
1
  {
2
- "name": "",
3
- "email": "",
4
- "access_token": "",
5
- "teams_url": "",
6
- "ox_qmd_load_path": "~/.emacs.d/site_lisp/ox-qmd"
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
@@ -0,0 +1,26 @@
1
+ class DecideOption
2
+ def initialize(src)
3
+ @src = src
4
+ end
5
+
6
+ def decide_option()
7
+ lines = File.readlines(@src)
8
+
9
+ lines.each do |line|
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
16
+ return option
17
+ end
18
+ end
19
+ option = "private"
20
+ return option
21
+ end
22
+ end
23
+
24
+ if __FILE__ == $0
25
+ DecideOption.new("test.org").decide_option()
26
+ end
@@ -0,0 +1,94 @@
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, file)
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
+ system "rm #{file}"
35
+ exit
36
+ elsif message == "Forbidden"
37
+ puts "#{message}".red
38
+ puts "You are not authorized to access this page. please check qiita_id.".red
39
+ system "rm #{file}"
40
+ exit
41
+ elsif message == "Not Found"
42
+ puts "#{message}".red
43
+ system "rm #{file}"
44
+ exit
45
+ else
46
+ puts "#{message}".red
47
+ system "rm #{file}"
48
+ exit
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def config_set_error(conf_dir)
55
+ conf_path = File.join(conf_dir, ".qiita.conf")
56
+ conf = JSON.load(File.read(conf_path))
57
+ check = true
58
+
59
+ 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
63
+ # system "rm template.org"
64
+ check = false
65
+ end
66
+
67
+ 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
71
+ check = false
72
+ end
73
+ unless check
74
+ exit
75
+ end
76
+ end
77
+
78
+ def md_file_exists?(src, res)
79
+ unless File.exists?(src.gsub(".org", ".md"))
80
+ puts "Can not make #{src.gsub(".org", ".md")}".red
81
+ puts "Please confirm emacs version.".red
82
+ exit
83
+ else
84
+ p res
85
+ end
86
+ end
87
+
88
+ def many_tags_error(tags)
89
+ if tags.count(",") >= 5
90
+ puts "The maximum number of tag is five. Please delete some tags.".red
91
+ exit
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,15 @@
1
+ class FileOpen
2
+ def initialize(os)
3
+ @os = os
4
+ end
5
+
6
+ def file_open(order)
7
+ if @os == "mac"
8
+ system "open #{order}"
9
+ elsif @os == "windows"
10
+ system "explorer.exe #{order}"
11
+ else
12
+ system "xdg-open #{order}"
13
+ end
14
+ end
15
+ end
@@ -3,49 +3,55 @@ require "json"
3
3
  require "open-uri"
4
4
  require "io/console"
5
5
  require "colorize"
6
- require "qiita_org/search_conf_path.rb"
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
- search = SearchConfPath.new(Dir.pwd, Dir.home)
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
- def select_path()
26
- case @mode
19
+ =begin
20
+ def select_path(mode)
21
+ case mode
27
22
  when "teams"
28
- @qiita = @teams_url
29
- @path = "api/v2/items?page=1&per_page=100"
23
+ qiita = @teams_url
24
+ path = "api/v2/items?page=1&per_page=100"
30
25
  else
31
- @qiita = "https://qiita.com/"
32
- @path = "api/v2/authenticated_user/items?page=1&per_page=100"
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
- response = URI.open(
44
- "#{uri}",
45
- "Authorization" => "#{headers["Authorization"]}",
46
- )
47
- @items = JSON.parse(response.read)
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
48
53
  end
54
+ =end
49
55
 
50
56
  # select report
51
57
  def select_report()
@@ -71,7 +77,7 @@ class QiitaGet
71
77
  File.write(filename, item["body"])
72
78
  convert_md_to_org()
73
79
  write_header_on_org()
74
- puts_massage_and_delete_md()
80
+ puts_massage_and_delete_md(item)
75
81
  end
76
82
  end
77
83
  end
@@ -119,9 +125,9 @@ EOS
119
125
  end
120
126
 
121
127
  # see massage and delete id.md
122
- def puts_massage_and_delete_md()
128
+ def puts_massage_and_delete_md(item)
123
129
  puts "created #{@id}.org".green
124
- puts "URL: #{@items["url"]}"
130
+ puts "URL: #{item["url"]}"
125
131
  system "rm -f #{@id}.md"
126
132
  end
127
133
 
@@ -134,7 +140,8 @@ EOS
134
140
  end
135
141
  @path = "api/v2/items/#{@get_id}"
136
142
 
137
- access_qiita()
143
+ @items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
144
+ #access_qiita()
138
145
 
139
146
  @title = @items["title"]
140
147
  @id = @items["id"]
@@ -148,14 +155,18 @@ EOS
148
155
  File.write(filename, @items["body"])
149
156
  convert_md_to_org()
150
157
  write_header_on_org()
151
- puts_massage_and_delete_md()
158
+ puts_massage_and_delete_md(@items)
152
159
  end
153
160
 
154
161
  def run()
155
- 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
+
156
167
  if @get_id == nil
157
- select_path()
158
- access_qiita()
168
+ @qiita, @path = @selectpath.select_path(@mode, @teams_url)
169
+ @items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
159
170
  select_report()
160
171
  else
161
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/search_conf_path.rb"
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
- search = SearchConfPath.new(Dir.pwd, Dir.home)
14
- @conf_dir = search.search_conf_path()
15
- set_config()
16
- end
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 = access_qiita(@access_token, qiita, path)
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
@@ -0,0 +1,38 @@
1
+ require "colorize"
2
+ #require "../qiita_org/qiita_org.rb"
3
+ require "qiita_org/post.rb"
4
+ require "qiita_org/upload.rb"
5
+ require "qiita_org/decide_option.rb"
6
+
7
+ class GetMultipleFiles
8
+ def initialize(files, os, type)
9
+ @files = files
10
+ @option = nil
11
+ @os = os
12
+ @type = type
13
+ unless @files[-1].match(/(.+).org/)
14
+ @option = @files[-1]
15
+ @files = @files[0..-2]
16
+ end
17
+ end
18
+
19
+ def run()
20
+ puts "post files: #{@files}".green
21
+ @files.each do |file|
22
+ mode = @option || DecideOption.new(file).decide_option()
23
+ puts "qiita #{@type} #{file} #{mode}".green
24
+ if @type == "post"
25
+ qiita = QiitaPost.new(file, mode, @os)
26
+ begin
27
+ qiita.select_option(mode)
28
+ rescue RuntimeError => e
29
+ puts $!
30
+ else
31
+ qiita.run
32
+ end
33
+ elsif @type == "upload"
34
+ UpLoad.new(file, mode, @os).upload()
35
+ end
36
+ end
37
+ end
38
+ 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
@@ -2,27 +2,26 @@ require "net/https"
2
2
  require "json"
3
3
  require "open-uri"
4
4
  require "colorize"
5
- require "qiita_org/search_conf_path.rb"
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
- search = SearchConfPath.new(Dir.pwd, Dir.home)
11
- @conf_dir = search.search_conf_path()
12
- set_config()
13
- select_path()
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
- 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"]
18
+ @qiita, @path = SelectPath.new().select_path(@mode, @teams_url)
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(lines)
3
- @lines = lines
2
+ def initialize()
3
+ # @lines = lines
4
4
  end
5
5
 
6
- def convert_for_image()
7
- @lines.each_with_index do |line, i|
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
- @lines[i] = "![#{path}](#{url})\n"
12
+ lines[i] = "![#{path}](#{url})\n"
13
13
  elsif m = line.match(/\[\!\[img\]\((.+)\)\]\((.+)\)/)
14
14
  path = File.basename(m[1])
15
15
  url = m[2]
16
- @lines[i] = "![#{path}](#{url})\n"
16
+ lines[i] = "![#{path}](#{url})\n"
17
17
  else
18
18
  next
19
19
  end
20
20
  end
21
21
 
22
- return @lines
22
+ return lines
23
23
  end
24
24
  end
25
25
 
@@ -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
- @conts = File.read(@src)
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 = @conts.match(/\#\+(TAG|tag|Tag|tags|TAGS|Tags): (.+)/)
26
- if m[2].count(",") >= 5
27
- puts "The maximum number of tag is five. Please delete some tags.".red
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
- end
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
- @patch = false
66
- if m = @conts.match(/\#\+qiita_#{@option}: (.+)/)
67
- @qiita_id = m[1]
68
- @patch = true
57
+ patch = false
58
+ if m = conts.match(/\#\+qiita_#{option}: (.+)/)
59
+ qiita_id = m[1]
60
+ patch = true
69
61
  else
70
- @qiita_id = ""
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
- @res = http_req.patch(uri.path, params.to_json, headers)
108
+ res = http_req.patch(uri.path, params.to_json, headers)
115
109
  else
116
- @res = http_req.post(uri.path, params.to_json, headers)
110
+ res = http_req.post(uri.path, params.to_json, headers)
117
111
  end
112
+
113
+ ErrorMessage.new().qiita_post_error(res, @src.gsub(".org", ".md"))
114
+
115
+ return res
118
116
  end
119
117
 
120
118
  # qiita return
@@ -140,31 +138,42 @@ 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
- get_title_tags()
156
- set_config()
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(@lines).convert_for_image()
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()
175
+
176
+ system "rm #{@src.gsub(".org", ".md")}"
168
177
  end
169
178
  end
170
179
 
@@ -2,7 +2,7 @@ class SearchConfPath
2
2
  def initialize(dir, home)
3
3
  @dir = dir
4
4
  @home = home
5
- search_conf_path()
5
+ #search_conf_path()
6
6
  end
7
7
 
8
8
  def search_conf_path()
@@ -0,0 +1,16 @@
1
+ class SelectPath
2
+ def initialize()
3
+ end
4
+
5
+ def select_path(mode, teams_url)
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
- search = SearchConfPath.new(Dir.pwd, Dir.home)
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
- if @os == "mac"
25
- system "open #{File.join(@paths[0].split("/")[0..-2])}"
26
- elsif @os == "windows"
27
- system "explorer.exe #{File.join(@paths[0].split("/")[0..-2])}"
28
- else
29
- system "open #{File.join(@paths[0].split("/")[0..-2])}"
30
- system "xdg-open #{File.join(@paths[0].split("/")[0..-2])}"
31
- end
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
- 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
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 = access_qiita(@access_token, qiita, path)
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
@@ -1,3 +1,3 @@
1
1
  module QiitaOrg
2
- VERSION = "0.1.19"
2
+ VERSION = "0.1.24"
3
3
  end
@@ -1,18 +1,22 @@
1
- #+qiita_private: 5f8c73e8007e52ef3f40
1
+ #+qiita_private: d786bc76ea7a4ad09fb0
2
+ # +qiita_private: 5f8c73e8007e52ef3f40
3
+ # +qiita_private: 4decbf7a81ef2327643f
2
4
  #+OPTIONS: ^:{}
3
5
  #+STARTUP: indent nolineimages
4
6
  #+TITLE: test
5
7
  #+AUTHOR: Kenta Yamamoto
6
8
  #+EMAIL: (concat "doi35077@kwansei.ac.jp")
9
+ #+qiita_id: yamatoken
7
10
  #+LANGUAGE: jp
8
11
  # +OPTIONS: H:4 toc:t num:2
9
12
  #+OPTIONS: toc:nil
10
- #+TAG: test
13
+ #+TAG: test1, test2, test3, test4, test5
11
14
  # +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
12
15
 
13
16
  ![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)
14
17
 
15
- fogefoge
18
+ | fogefoge | fogefoge |
19
+ | foge | foge |
16
20
  # +caption: example qiita template command
17
21
  # +name: fig:fig1
18
22
  #+ATTR_LATEX: :width 8cm
@@ -24,3 +28,5 @@ fogefoge
24
28
  [[file:../figs/fig2.png]]
25
29
 
26
30
  https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/a3b2ab02-f903-f5d6-d8b9-5407e8db5a2a.png
31
+
32
+
@@ -1,4 +1,3 @@
1
- #+qiita_private: ca3a6b6e1f5e8c0ba743
2
1
  #+OPTIONS: ^:{}
3
2
  #+STARTUP: indent nolineimages
4
3
  #+TITLE: test
@@ -18,4 +17,6 @@ fogefoge
18
17
  #+ATTR_LATEX: :width 8cm
19
18
  [[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png][file:../figs/fig1.png]]
20
19
 
20
+ [[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png][file:../figs/fig1.png]]
21
+
21
22
 
@@ -0,0 +1,15 @@
1
+ # +qiita_teams: bd41ced53b4b18701453
2
+ #+OPTIONS: ^:{}
3
+ #+STARTUP: indent nolineimages
4
+ #+TITLE: test
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: test
11
+ # +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
12
+
13
+ ![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)
14
+
15
+ fogefoge
@@ -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
+ ![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)
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.19
4
+ version: 0.1.24
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-10-27 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -957,12 +957,17 @@ 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
964
+ - lib/qiita_org/decide_option.rb
965
+ - lib/qiita_org/error_message.rb
966
+ - lib/qiita_org/file_open.rb
963
967
  - lib/qiita_org/get.rb
964
968
  - lib/qiita_org/get_file_path.rb
965
969
  - lib/qiita_org/get_file_url.rb
970
+ - lib/qiita_org/get_multiple_files.rb
966
971
  - lib/qiita_org/get_template.rb
967
972
  - lib/qiita_org/hoge.txt
968
973
  - lib/qiita_org/list.rb
@@ -970,16 +975,19 @@ files:
970
975
  - lib/qiita_org/ox-qmd/ox-qmd.el
971
976
  - lib/qiita_org/post.rb
972
977
  - lib/qiita_org/search_conf_path.rb
978
+ - lib/qiita_org/select_path.rb
979
+ - lib/qiita_org/set_config.rb
973
980
  - lib/qiita_org/show_file_and_url.rb
974
981
  - lib/qiita_org/template.org
982
+ - lib/qiita_org/upload.rb
975
983
  - lib/qiita_org/version.rb
976
984
  - qiita_org.gemspec
977
985
  - tests/hoge.rb
978
986
  - tests/test.html
979
- - tests/test.md
980
987
  - tests/test.org
981
- - tests/test2.md
982
988
  - tests/test2.org
989
+ - tests/test3.org
990
+ - tests/test4.org
983
991
  homepage: https://github.com/yamatoken/qiita_org
984
992
  licenses:
985
993
  - MIT
@@ -1,10 +0,0 @@
1
- \![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>)
2
-
3
- fogefoge
4
-
5
- [![img](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/a3b2ab02-f903-f5d6-d8b9-5407e8db5a2a.png)](file:///Users/kentayamamoto/Github/qiita_org/figs/fig1.png)
6
-
7
- ![img](../figs/fig2.png "example qiita template command")
8
-
9
- ![img](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/a3b2ab02-f903-f5d6-d8b9-5407e8db5a2a.png)
10
-
@@ -1,6 +0,0 @@
1
- \![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>)
2
-
3
- fogefoge
4
-
5
- [![img](../figs/fig1.png)](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png)
6
-