ZMediumToMarkdown 2.4.9 → 2.5.1

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/lib/Post.rb +1 -13
  3. data/lib/Request.rb +20 -17
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96dbba590eb72c7cad419081c8e4f0e3e133e8184b1d7b9cf5892be41603acf8
4
- data.tar.gz: 68b84e4caccdb71ea1d2e5fba95d18a727effed1a28bed70e2ccd7e106c49a9e
3
+ metadata.gz: 6c16ac0a5062f690cf0d57960b5921599e254c609b249c7e55929f7c925fb89c
4
+ data.tar.gz: d571bfe350ecffc3a9ab79028d81fe76383f97c21dc2a46b81a6ccd194623e5f
5
5
  SHA512:
6
- metadata.gz: 216cf9a121d2411b4b52af7aa5efd0ea2d2a0ad88c6b2ec14875c1b459d74a4c13fed4cfad58362132a7dba0f436fb7deacba642cc3e41eebf9e0cf6412c893d
7
- data.tar.gz: d003a0938e6b40e3a57527f0678e0a2f2c39708d95de5cd7b4b7f0b8a9f1ab7e6ddb80812e1db57120c60794346ece9b8a0eceb7b467351a2a2dda289f889870
6
+ metadata.gz: d0bff21c619bed3182c7142bbf4b8f56cf975314f5d852d0032182715e6ea51a805245e4e490b8d55b21a593c9b983df1b0ec9c975a7e9570e221ccc340df4ef
7
+ data.tar.gz: 94574f5cc07a86bd0897efb99538352a664e01483586f102a5440862bf4a90d9907a3868e122f78883e3eafed56e8a0117664037fd33675c66d3fa9929d1ec20
data/lib/Post.rb CHANGED
@@ -51,19 +51,7 @@ class Post
51
51
  }
52
52
  ]
53
53
 
54
- uri = URI("https://medium.com/_/graphql")
55
- https = Net::HTTP.new(uri.host, uri.port)
56
- https.use_ssl = true
57
- request = Net::HTTP::Post.new(uri)
58
- request['Content-Type'] = 'application/json'
59
- if !$cookie_sid.nil? && !$cookie_uid.nil?
60
- request['Cookie'] = "sid=#{$cookie_sid}; uid=#{$cookie_uid}"
61
- end
62
- request.body = JSON.dump(query)
63
- response = https.request(request)
64
-
65
-
66
- body = Request.body(response)
54
+ body = Request.body(Request.URL("https://medium.com/_/graphql", method = 'POST', data = query));
67
55
  if !body.nil?
68
56
  json = JSON.parse(body)
69
57
  json&.dig(0, "data", "post", "viewerEdge", "fullContent")
data/lib/Request.rb CHANGED
@@ -22,23 +22,26 @@ class Request
22
22
  end
23
23
  end
24
24
 
25
- begin
26
- response = https.request(request)
27
- # 3XX Redirect
28
- if response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
29
- if retryCount >= 10
30
- raise "Error: Retry limit reached. path: #{url}"
31
- else
32
- location = response['location']
33
- if !location.match? /^(http)/
34
- location = "#{uri.scheme}://#{uri.host}#{location}"
35
- end
36
-
37
- response = self.URL(location, method, data, retryCount)
38
- end
39
- end
40
- rescue
41
-
25
+ if !$cookie_sid.nil? && !$cookie_uid.nil?
26
+ request['Cookie'] = "sid=#{$cookie_sid}; uid=#{$cookie_uid}";
27
+ end
28
+
29
+ response = https.request(request);
30
+
31
+ # 3XX Redirect
32
+ if response.code.to_i == 429
33
+ raise "Error: Too Manay Reqeust, blocked by Medium.\n####################\n### Please try again later.\n### Ref: https://zhgchg.li/posts/en-medium-to-jekyll/#paywall-posts-require-a-medium-account-with-access-permissions-and-cookies-author-or-medium-member \n####################\n### ERROR URL: #{url}"
34
+ elsif response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
35
+ if retryCount >= 10
36
+ raise "Error: Retry limit reached. path: #{url}"
37
+ else
38
+ location = response['location']
39
+ if !location.match? /^(http)/
40
+ location = "#{uri.scheme}://#{uri.host}#{location}"
41
+ end
42
+
43
+ response = self.URL(location, method, data, retryCount)
44
+ end
42
45
  end
43
46
 
44
47
  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: 2.4.9
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-14 00:00:00.000000000 Z
11
+ date: 2025-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri