ZMediumToMarkdown 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ZMediumToMarkdown +13 -7
  3. data/lib/Request.rb +6 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4927555e3c7d6f021e1c989a83e03a095f613d28fc482d3f08599d16229dbc0
4
- data.tar.gz: 77753af16833d4927574a3a170b3d046f35688c1a7146b85a857ca6fcad35851
3
+ metadata.gz: 478b02a8d17067e64ef3c402640961cc75c91a560b0370e598be80ee17b27296
4
+ data.tar.gz: 2b01dcc7f9950271bcb0f4e59f10c2c6a1015cd1d013df796e62a4b2138ba69e
5
5
  SHA512:
6
- metadata.gz: 55d662074d29bae6267a7982f3f03c61264b6a5628f2ca15aa9b06a70d3d8d329505f5c833700b8580743719885afe99fb090e3d50ea7a720c5848d56a557e6f
7
- data.tar.gz: 5a3ac99f7b8ea47bc24f8f2f48b8f5147fa86d2f8bba920be4592be08ae6f2b7434a545ec353fc879f65ca4ac34dc5285273c17f97f58a66d345072db678863b
6
+ metadata.gz: 3dbf24729dae8e94881fa876ef9cb2119ee1370b45160c3aa6974ee84cb6522ae85ff5380c600db2420df32ec5ec50ac00350f7e56cf41177cc56ed186845ac1
7
+ data.tar.gz: c62b15539cd70a2d6523f3d89ded3a88ac5220ca72896d7a163d557cc2d1ccbcfec94b548ed78920b74fbe05ef52d18c0b8f4fe57cf832a7f17e2d7f72dd2224
@@ -12,34 +12,40 @@ class Main
12
12
  def initialize
13
13
  fetcher = ZMediumFetcher.new
14
14
  ARGV << '-h' if ARGV.empty?
15
+
16
+ filePath = File.expand_path File.dirname(__FILE__)
17
+ outputFilePath = PathPolicy.new(filePath, "Output")
18
+
15
19
  OptionParser.new do |opts|
16
20
  opts.banner = "Usage: ZMediumFetcher [options]"
17
21
 
18
22
  opts.on('-uUSERNAME', '--username=USERNAME', 'Downloading all posts from user') do |username|
19
- pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
20
- fetcher.downloadPostsByUsername(username, pathPolicy)
23
+ fetcher.downloadPostsByUsername(username, outputFilePath)
21
24
 
22
25
  Helper.printNewVersionMessageIfExists()
23
26
  end
24
27
 
25
28
  opts.on('-pPOST_URL', '--postURL=POST_URL', 'Downloading single post') do |postURL|
26
- pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
27
- fetcher.downloadPost(postURL, pathPolicy)
29
+ fetcher.downloadPost(postURL, outputFilePath)
28
30
 
29
31
  Helper.printNewVersionMessageIfExists()
30
32
  end
31
33
 
32
- opts.on('-n', '--new', 'Update to latest version') do |postURL|
34
+ opts.on('-n', '--new', 'Update to latest version') do
33
35
  if Helper.compareVersion(Helper.getRemoteVersionFromGithub(), Helper.getLocalVersionFromGemspec())
34
36
  Helper.downloadLatestVersion()
35
37
  else
36
38
  puts "You're using the latest version :)"
37
39
  end
38
40
  end
41
+
42
+ opts.on('-c', '--clean', 'Remove all downloaded posts data') do
43
+ FileUtils.rm_rf(Dir[outputFilePath.getAbsolutePath(nil)])
44
+
45
+ Helper.printNewVersionMessageIfExists()
46
+ end
39
47
 
40
48
  end.parse!
41
-
42
- Helper.logLatestRunVersion()
43
49
  end
44
50
  end
45
51
 
data/lib/Request.rb CHANGED
@@ -23,12 +23,17 @@ class Request
23
23
  end
24
24
 
25
25
  response = https.request(request)
26
+
26
27
  # 3XX Redirect
27
28
  if response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
28
29
  if retryCount >= 10
29
30
  raise "Error: Retry limit reached. path: #{url}"
30
31
  else
31
- response = self.URL(response['location'], method, data)
32
+ location = response['location']
33
+ if !location.match? /^(http)/
34
+ location = "#{uri.scheme}://#{uri.host}#{location}"
35
+ end
36
+ response = self.URL(location, method, data)
32
37
  end
33
38
  end
34
39
  response
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZMediumToMarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-30 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri