ZMediumToMarkdown 2.4.9 → 2.5.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/lib/Post.rb +1 -13
  3. data/lib/Request.rb +33 -16
  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: 3e2329fa42690e35efea3b0231c03949d460484e821f27b9a3da53fe43908906
4
+ data.tar.gz: 9636ba2e044114cda97780db906014f4bbe7859af23c3236cc79d8928040fffa
5
5
  SHA512:
6
- metadata.gz: 216cf9a121d2411b4b52af7aa5efd0ea2d2a0ad88c6b2ec14875c1b459d74a4c13fed4cfad58362132a7dba0f436fb7deacba642cc3e41eebf9e0cf6412c893d
7
- data.tar.gz: d003a0938e6b40e3a57527f0678e0a2f2c39708d95de5cd7b4b7f0b8a9f1ab7e6ddb80812e1db57120c60794346ece9b8a0eceb7b467351a2a2dda289f889870
6
+ metadata.gz: 1aad74dfa4a903110456dd1fab95ba2b4c2b88e4e355a39312b7dd1924bdf8fb2c9e38581c92ad3651f91ba5ffd0c385ed172fa4834d0aed3d605e89f3b7bc70
7
+ data.tar.gz: 31ba0e2502cc5d10ed64ab69ae15864526dd90b698962ba05054f22f1c20d0d518416e0fce86f61980cdc5f3466db9d7dfa1e4f313cec876ea664a1ca4d1306d
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,40 @@ 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
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);
41
30
 
31
+ cookies = response.get_fields('set-cookie').map { |cookie| cookie.split('; ').first }.each_with_object({}) do |cookie, hash|
32
+ key, value = cookie.split('=', 2) # Split by '=' into key and value
33
+ hash[key] = value
34
+ end;
35
+
36
+ if !cookies['uid'].nil?
37
+ $cookie_uid = cookies['uid'];
38
+ end
39
+
40
+ if !cookies['sid'].nil?
41
+ $cookie_sid = cookies['sid'];
42
+ end
43
+
44
+ puts response
45
+ # 3XX Redirect
46
+ if response.code.to_i == 429
47
+ 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}"
48
+ elsif response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
49
+ if retryCount >= 10
50
+ raise "Error: Retry limit reached. path: #{url}"
51
+ else
52
+ location = response['location']
53
+ if !location.match? /^(http)/
54
+ location = "#{uri.scheme}://#{uri.host}#{location}"
55
+ end
56
+
57
+ response = self.URL(location, method, data, retryCount)
58
+ end
42
59
  end
43
60
 
44
61
  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.0
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