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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2183cbb77e1eb9a58965d80e977b81698d81d5dc48ccb433d286e02dbcfa53e6
4
- data.tar.gz: 30e5a87e074c00f456d67258b2ddbeed332dc6b2670e49915e356729560c0948
3
+ metadata.gz: 4ee86bddc38ccddc190d68aef6b7e29c0aea48d61810efad1e5b9e793dca374d
4
+ data.tar.gz: aebb67cdd1aff8e9156fd616964b54118d5cec0e91762b51422ada379cfd4b76
5
5
  SHA512:
6
- metadata.gz: 66d0679ca3291058214204f6ac251898e7cc9fe348f3aa0ac5bf3167bb07d582180b49602191c6e023e62dfb8cc5395f8db6cdede0433fec289b926e46154e1c
7
- data.tar.gz: 8e30c81de02f1360ab9e143aa21d947a0212c14ac1b0d05554e44c975a9b087d7083ebb13915390848b7530a3072eaf9f7b36747bfc6275f7703ae0a2da5f381
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
- ## Development
196
+ ## Contributing
189
197
 
190
- ### Tests
198
+ ### Environment Variables
199
+
200
+ Set the Cloudflare credentials before running integration or manual checks:
191
201
 
192
202
  ```bash
193
- bundle exec rake test
203
+ export CLOUDFLARE_API_TOKEN="your-token"
204
+ export CLOUDFLARE_ACCOUNT_ID="your-account-id"
194
205
  ```
195
206
 
196
- ### Sorbet
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 srb tc
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
 
@@ -15,9 +15,9 @@ class UrlToMarkdown
15
15
  )
16
16
  end
17
17
 
18
- def convert(url)
18
+ def convert(url, actions: nil)
19
19
  validate_url!(url)
20
- @client.markdown(url: url)
20
+ @client.markdown(url: url, actions: actions)
21
21
  end
22
22
 
23
23
  private
@@ -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!
@@ -7,7 +7,7 @@ class UrlToMarkdown
7
7
  @cache_store = cache_store
8
8
  end
9
9
 
10
- def convert(_url)
10
+ def convert(_url, actions: nil)
11
11
  raise NotImplementedError, "Implement in subclass"
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UrlToMarkdown
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -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.0
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.3
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: []