reddit_post_to_markdown 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/reddit_post_to_markdown/post_renderer.rb +9 -1
- data/lib/reddit_post_to_markdown/reddit_client.rb +2 -2
- data/lib/reddit_post_to_markdown/url_validator.rb +5 -7
- data/lib/reddit_post_to_markdown/version.rb +1 -1
- data/lib/reddit_post_to_markdown.rb +3 -0
- data/reddit_post_to_markdown.gemspec +14 -2
- metadata +17 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37b7ab66e1f79d44320d9e0faa596663be2849e1118c495a5ae58930a3fd3d9b
|
|
4
|
+
data.tar.gz: ffda7283ff6597b0a9b6098674fd76e617c1b9d0e8666605d816e743ea914f86
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 781345b4d59eb26e7118149590f116a1e69c2be3a77bbc64a4234793ace76b26318c634db722c5bf4a13b4db45485bdce61c2d68160cc7145e0ef5eccaee24ba
|
|
7
|
+
data.tar.gz: 31de8a980cd49b874dfed294515a1807dd52e349b478f6c608129c476cb6e6e33f9c37f0361d95b7e522a1a014ac8d1440ce386f658eef0b59f041161b095afd
|
|
@@ -114,7 +114,8 @@ module RedditPostToMarkdown
|
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
def post_url
|
|
117
|
-
@post_data.fetch("
|
|
117
|
+
permalink = @post_data.fetch("permalink", "")
|
|
118
|
+
permalink.empty? ? @post_data.fetch("url", "") : "https://www.reddit.com#{permalink}"
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
def post_created_utc
|
|
@@ -123,6 +124,13 @@ module RedditPostToMarkdown
|
|
|
123
124
|
|
|
124
125
|
def post_image_urls
|
|
125
126
|
image_urls = []
|
|
127
|
+
|
|
128
|
+
if @post_data["post_hint"] == "image"
|
|
129
|
+
url = @post_data["url"]
|
|
130
|
+
image_urls << url if url && !url.empty?
|
|
131
|
+
return image_urls
|
|
132
|
+
end
|
|
133
|
+
|
|
126
134
|
media_metadata = @post_data["media_metadata"]
|
|
127
135
|
# a hash of hashes with some sort of hashed keys we don't care about
|
|
128
136
|
return image_urls unless media_metadata
|
|
@@ -23,10 +23,10 @@ module RedditPostToMarkdown
|
|
|
23
23
|
# @raise [FetchError] if the server returns a non-2xx HTTP status
|
|
24
24
|
# @raise [InvalidResponseError] if the parsed response is not a two-element
|
|
25
25
|
# Array
|
|
26
|
-
def fetch_post(url)
|
|
26
|
+
def fetch_post(url, user_agent: USER_AGENT)
|
|
27
27
|
json_url = url.end_with?(".json") ? url : "#{url}.json"
|
|
28
28
|
|
|
29
|
-
response = self.class.get(json_url, headers: { "User-Agent" =>
|
|
29
|
+
response = self.class.get(json_url, headers: { "User-Agent" => user_agent })
|
|
30
30
|
|
|
31
31
|
raise FetchError, "HTTP #{response.code} fetching #{url}" unless response.success?
|
|
32
32
|
|
|
@@ -28,19 +28,17 @@ module RedditPostToMarkdown
|
|
|
28
28
|
PATTERNS.any? { |pattern| url.match?(pattern) }
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# Strips
|
|
31
|
+
# Strips the query string and trailing slash from a Reddit URL.
|
|
32
32
|
#
|
|
33
|
-
# Removes
|
|
34
|
-
#
|
|
35
|
-
# whitespace is also removed.
|
|
33
|
+
# Removes everything from the first +?+ onward (tracking params, share IDs,
|
|
34
|
+
# etc. are never needed to fetch the post JSON), then strips any trailing
|
|
35
|
+
# slash. Leading and trailing whitespace is also removed.
|
|
36
36
|
#
|
|
37
37
|
# @param url [String] the URL to clean
|
|
38
38
|
# @return [String] the cleaned URL
|
|
39
39
|
def self.clean_url(url)
|
|
40
40
|
url = url.to_s.strip
|
|
41
|
-
url = url.split("?
|
|
42
|
-
url = url.split("?ref=").first
|
|
43
|
-
url = url.split("?context=").first
|
|
41
|
+
url = url.split("?").first
|
|
44
42
|
url.chomp("/")
|
|
45
43
|
end
|
|
46
44
|
end
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
warn "[DEPRECATION] reddit_post_to_markdown is deprecated and no longer maintained. " \
|
|
2
|
+
"Reddit is shutting down unauthenticated access to post JSON, so this gem no longer works."
|
|
3
|
+
|
|
1
4
|
require_relative "reddit_post_to_markdown/version"
|
|
2
5
|
require_relative "reddit_post_to_markdown/errors"
|
|
3
6
|
require_relative "reddit_post_to_markdown/url_validator"
|
|
@@ -4,12 +4,24 @@ Gem::Specification.new do |spec|
|
|
|
4
4
|
spec.name = "reddit_post_to_markdown"
|
|
5
5
|
spec.version = RedditPostToMarkdown::VERSION
|
|
6
6
|
spec.authors = ["masukomi"]
|
|
7
|
-
spec.
|
|
8
|
-
spec.
|
|
7
|
+
spec.email = ["masukomi@masukomi.org"]
|
|
8
|
+
spec.homepage = "https://github.com/masukomi/reddit_post_to_markdown"
|
|
9
|
+
spec.summary = "DEPRECATED: Download a public Reddit post and convert it to Markdown"
|
|
10
|
+
spec.description = "DEPRECATED and no longer maintained. Reddit is shutting down unauthenticated access to post JSON, so this gem no longer works. Originally: takes the URL of a public Reddit post, downloads the post and its comments via the Reddit JSON API, and returns the content as a Markdown string."
|
|
9
11
|
spec.license = "MIT"
|
|
10
12
|
|
|
13
|
+
spec.post_install_message = <<~MSG
|
|
14
|
+
WARNING: reddit_post_to_markdown is DEPRECATED and no longer maintained.
|
|
15
|
+
Reddit is shutting down unauthenticated access to post JSON, so this gem
|
|
16
|
+
no longer works. See #{spec.homepage} for details.
|
|
17
|
+
MSG
|
|
18
|
+
|
|
11
19
|
spec.required_ruby_version = ">= 2.7"
|
|
12
20
|
|
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
22
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
23
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.org"
|
|
24
|
+
|
|
13
25
|
spec.files = Dir["lib/**/*.rb", "reddit_post_to_markdown.gemspec"]
|
|
14
26
|
|
|
15
27
|
spec.add_dependency "httparty", "~> 0.22"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reddit_post_to_markdown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- masukomi
|
|
@@ -51,8 +51,12 @@ dependencies:
|
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '3.26'
|
|
54
|
-
description:
|
|
55
|
-
|
|
54
|
+
description: 'DEPRECATED and no longer maintained. Reddit is shutting down unauthenticated
|
|
55
|
+
access to post JSON, so this gem no longer works. Originally: takes the URL of a
|
|
56
|
+
public Reddit post, downloads the post and its comments via the Reddit JSON API,
|
|
57
|
+
and returns the content as a Markdown string.'
|
|
58
|
+
email:
|
|
59
|
+
- masukomi@masukomi.org
|
|
56
60
|
executables: []
|
|
57
61
|
extensions: []
|
|
58
62
|
extra_rdoc_files: []
|
|
@@ -64,9 +68,17 @@ files:
|
|
|
64
68
|
- lib/reddit_post_to_markdown/url_validator.rb
|
|
65
69
|
- lib/reddit_post_to_markdown/version.rb
|
|
66
70
|
- reddit_post_to_markdown.gemspec
|
|
71
|
+
homepage: https://github.com/masukomi/reddit_post_to_markdown
|
|
67
72
|
licenses:
|
|
68
73
|
- MIT
|
|
69
|
-
metadata:
|
|
74
|
+
metadata:
|
|
75
|
+
homepage_uri: https://github.com/masukomi/reddit_post_to_markdown
|
|
76
|
+
source_code_uri: https://github.com/masukomi/reddit_post_to_markdown
|
|
77
|
+
changelog_uri: https://github.com/masukomi/reddit_post_to_markdown/CHANGELOG.org
|
|
78
|
+
post_install_message: |
|
|
79
|
+
WARNING: reddit_post_to_markdown is DEPRECATED and no longer maintained.
|
|
80
|
+
Reddit is shutting down unauthenticated access to post JSON, so this gem
|
|
81
|
+
no longer works. See https://github.com/masukomi/reddit_post_to_markdown for details.
|
|
70
82
|
rdoc_options: []
|
|
71
83
|
require_paths:
|
|
72
84
|
- lib
|
|
@@ -83,5 +95,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
83
95
|
requirements: []
|
|
84
96
|
rubygems_version: 4.0.7
|
|
85
97
|
specification_version: 4
|
|
86
|
-
summary: Download a public Reddit post and convert it to Markdown
|
|
98
|
+
summary: 'DEPRECATED: Download a public Reddit post and convert it to Markdown'
|
|
87
99
|
test_files: []
|