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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbcefef7bcf13e1fc6d417be5e2a5adf397f69931fbacae27855c0fc0d34e66e
4
- data.tar.gz: 4cecd3cb2af8878a4766a12b7b33fc6eb7a47bcb957681f4ce7f83248c76a384
3
+ metadata.gz: 37b7ab66e1f79d44320d9e0faa596663be2849e1118c495a5ae58930a3fd3d9b
4
+ data.tar.gz: ffda7283ff6597b0a9b6098674fd76e617c1b9d0e8666605d816e743ea914f86
5
5
  SHA512:
6
- metadata.gz: 3e5e54ea2bf6f039f889ee2d19020b7e9d7621f993722b0d1850969d48f67adcfe3ae1bcd26c15548e0512a6d40a3c56a342b9e206e368327925e9c60380ee61
7
- data.tar.gz: fbfa20da94b37b834cfbcf88b6ae4f625aba540a0abe9ec0738e2fde074f0d9230545c9889ab93ddd7e555de2ac88457e6689f0c0f12189ab369b07353b69220
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("url", "")
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" => 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 common tracking parameters and the trailing slash from a Reddit URL.
31
+ # Strips the query string and trailing slash from a Reddit URL.
32
32
  #
33
- # Removes query strings beginning with +?utm_source+, +?ref=+, or
34
- # +?context=+, then strips any trailing slash. Leading and trailing
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("?utm_source").first
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,3 @@
1
1
  module RedditPostToMarkdown
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  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.summary = "Download a public Reddit post and convert it to Markdown"
8
- spec.description = "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."
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.1.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: Takes the URL of a public Reddit post, downloads the post and its comments
55
- via the Reddit JSON API, and returns the content as a Markdown string.
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: []