Class: Skriptorium::Hashnode::Destination
- Inherits:
-
BaseDestination
- Object
- BaseDestination
- Skriptorium::Hashnode::Destination
- Defined in:
- lib/skriptorium/hashnode/destination.rb
Constant Summary collapse
- HASHNODE_DRAFTS_URL =
'https://hashnode.com/drafts'.freeze
Instance Attribute Summary
Attributes inherited from BaseDestination
Instance Method Summary collapse
- #exists?(article) ⇒ Boolean
-
#initialize(config) ⇒ Destination
constructor
A new instance of Destination.
- #publish(article) ⇒ Object
Methods inherited from BaseDestination
Constructor Details
#initialize(config) ⇒ Destination
Returns a new instance of Destination.
13 14 15 16 17 18 |
# File 'lib/skriptorium/hashnode/destination.rb', line 13 def initialize(config) super @storage_state_path = config['storage_state_path'] @username = config['username'] @playwright_cli_path = config['playwright_cli_executable_path'] end |
Instance Method Details
#exists?(article) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/skriptorium/hashnode/destination.rb', line 20 def exists?(article) url = article_url(article) puts 1111 puts url response = Faraday.head(url, nil, { 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36' }) puts response.body puts response.status puts 2222 response.success? && response.status == 200 rescue StandardError false end |
#publish(article) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/skriptorium/hashnode/destination.rb', line 33 def publish(article) raise 'Article already published!' if exists?(article) with_page do |page| publish_via_browser(page, article) end end |