url_to_markdown 0.1.0 → 0.2.1
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/README.md +19 -5
- data/lib/url_to_markdown/cloudflare/client.rb +6 -3
- data/lib/url_to_markdown/cloudflare/processor.rb +2 -2
- data/lib/url_to_markdown/configuration.rb +2 -1
- data/lib/url_to_markdown/processor.rb +1 -1
- data/lib/url_to_markdown/version.rb +1 -1
- data/lib/url_to_markdown.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ee86bddc38ccddc190d68aef6b7e29c0aea48d61810efad1e5b9e793dca374d
|
|
4
|
+
data.tar.gz: aebb67cdd1aff8e9156fd616964b54118d5cec0e91762b51422ada379cfd4b76
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90f9c1161a277a3d6fa9e92574e8410ade755ba00b0e71867674e5ae5a3f2f8ce3245af4a68c6682d6dd8b4eba3fb734caa5f74f133f2cea5408cc2566de102f
|
|
7
|
+
data.tar.gz: b187a9e3ba8f0e1eb5f6f1007021df9b9c2ecbd800276e6a9b495e358aff131574f64753ed544516796d5fbc449c7c145b0b5d3360cec8b24a5288f95c20aed3
|
data/README.md
CHANGED
|
@@ -16,6 +16,14 @@ Cloudflare Browser Rendering is the default processor, but you can plug in your
|
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
|
+
Add the gem to your Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem 'url_to_markdown'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then install:
|
|
26
|
+
|
|
19
27
|
```bash
|
|
20
28
|
bundle install
|
|
21
29
|
```
|
|
@@ -185,18 +193,24 @@ result.on_error do |error|
|
|
|
185
193
|
end
|
|
186
194
|
```
|
|
187
195
|
|
|
188
|
-
##
|
|
196
|
+
## Contributing
|
|
189
197
|
|
|
190
|
-
###
|
|
198
|
+
### Environment Variables
|
|
199
|
+
|
|
200
|
+
Set the Cloudflare credentials before running integration or manual checks:
|
|
191
201
|
|
|
192
202
|
```bash
|
|
193
|
-
|
|
203
|
+
export CLOUDFLARE_API_TOKEN="your-token"
|
|
204
|
+
export CLOUDFLARE_ACCOUNT_ID="your-account-id"
|
|
194
205
|
```
|
|
195
206
|
|
|
196
|
-
|
|
207
|
+
Check the Cloudflare Developers documentation about [finding account and zone id](https://developers.cloudflare.com/fundamentals/account/find-account-and-zone-ids/#copy-your-account-id) to get your account it.
|
|
208
|
+
Generate an API TOKEN by following [the documentation about Browser Rendering](https://developers.cloudflare.com/browser-rendering/rest-api/#before-you-begin) where you will also find the permission needed for the token.
|
|
209
|
+
|
|
210
|
+
### Tests
|
|
197
211
|
|
|
198
212
|
```bash
|
|
199
|
-
bundle exec
|
|
213
|
+
bundle exec rake test
|
|
200
214
|
```
|
|
201
215
|
|
|
202
216
|
### RuboCop
|
|
@@ -17,7 +17,8 @@ class UrlToMarkdown
|
|
|
17
17
|
validate_credentials!
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def markdown(url: nil, html: nil, wait_for_selector: nil, wait_for_timeout_in_milliseconds: nil, cache_ttl: nil
|
|
20
|
+
def markdown(url: nil, html: nil, wait_for_selector: nil, wait_for_timeout_in_milliseconds: nil, cache_ttl: nil,
|
|
21
|
+
actions: nil)
|
|
21
22
|
validate_payload!(url: url, html: html)
|
|
22
23
|
|
|
23
24
|
response = connection.post("accounts/#{@account_id}/browser-rendering/markdown") do |request|
|
|
@@ -29,7 +30,8 @@ class UrlToMarkdown
|
|
|
29
30
|
html: html,
|
|
30
31
|
wait_for_selector: wait_for_selector,
|
|
31
32
|
wait_for_timeout_in_milliseconds: wait_for_timeout_in_milliseconds,
|
|
32
|
-
cache_ttl: cache_ttl
|
|
33
|
+
cache_ttl: cache_ttl,
|
|
34
|
+
actions: actions
|
|
33
35
|
))
|
|
34
36
|
end
|
|
35
37
|
|
|
@@ -56,7 +58,7 @@ class UrlToMarkdown
|
|
|
56
58
|
raise UrlToMarkdown::ValidationError.new(nil, "Provide a URL or HTML")
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
def build_payload(url:, html:, wait_for_selector:, wait_for_timeout_in_milliseconds:, cache_ttl:)
|
|
61
|
+
def build_payload(url:, html:, wait_for_selector:, wait_for_timeout_in_milliseconds:, cache_ttl:, actions: nil)
|
|
60
62
|
payload = {}
|
|
61
63
|
payload[:url] = url if url
|
|
62
64
|
payload[:html] = html if html
|
|
@@ -66,6 +68,7 @@ class UrlToMarkdown
|
|
|
66
68
|
wait_for_timeout_in_milliseconds
|
|
67
69
|
end
|
|
68
70
|
payload[:cache_ttl] = cache_ttl if cache_ttl
|
|
71
|
+
payload[:actions] = actions if actions&.any?
|
|
69
72
|
payload
|
|
70
73
|
end
|
|
71
74
|
|
|
@@ -5,7 +5,7 @@ require "logger"
|
|
|
5
5
|
class UrlToMarkdown
|
|
6
6
|
class Configuration
|
|
7
7
|
attr_accessor :cloudflare_api_token, :cloudflare_account_id, :cloudflare_timeout_ms, :cloudflare_cache_ttl,
|
|
8
|
-
:logger, :default_processor
|
|
8
|
+
:logger, :default_processor, :default_actions
|
|
9
9
|
|
|
10
10
|
def initialize
|
|
11
11
|
@cloudflare_api_token = ENV.fetch("CLOUDFLARE_API_TOKEN", nil)
|
|
@@ -14,6 +14,7 @@ class UrlToMarkdown
|
|
|
14
14
|
@cloudflare_cache_ttl = 5
|
|
15
15
|
@logger = Logger.new($stdout)
|
|
16
16
|
@default_processor = UrlToMarkdown::Cloudflare::Processor
|
|
17
|
+
@default_actions = nil
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def cloudflare_api_token!
|
data/lib/url_to_markdown.rb
CHANGED
|
@@ -8,11 +8,12 @@ loader.inflector.inflect("errors" => "Error", "pstore" => "PStore")
|
|
|
8
8
|
loader.setup
|
|
9
9
|
|
|
10
10
|
class UrlToMarkdown
|
|
11
|
-
def initialize(url:, processor: nil, logger: nil, cache_store: nil)
|
|
11
|
+
def initialize(url:, processor: nil, logger: nil, cache_store: nil, actions: nil)
|
|
12
12
|
@url = url
|
|
13
13
|
@processor_class = processor || self.class.configuration.default_processor
|
|
14
14
|
@logger = logger || self.class.configuration.logger
|
|
15
15
|
@cache_store = cache_store
|
|
16
|
+
@actions = actions || self.class.configuration.default_actions
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def convert
|
|
@@ -27,7 +28,7 @@ class UrlToMarkdown
|
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
processor = @processor_class.new(logger: @logger, cache_store: @cache_store)
|
|
30
|
-
result = processor.convert(@url)
|
|
31
|
+
result = processor.convert(@url, actions: @actions)
|
|
31
32
|
|
|
32
33
|
@cache_store.store!(@url, result.payload) if @cache_store && result.respond_to?(:success?) && result.success?
|
|
33
34
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: url_to_markdown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lucian Ghinda
|
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
103
103
|
- !ruby/object:Gem::Version
|
|
104
104
|
version: '0'
|
|
105
105
|
requirements: []
|
|
106
|
-
rubygems_version: 4.0.
|
|
106
|
+
rubygems_version: 4.0.6
|
|
107
107
|
specification_version: 4
|
|
108
108
|
summary: Convert URLs to Markdown via Cloudflare Browser Rendering
|
|
109
109
|
test_files: []
|