Class: ProxyCrawl::ScreenshotsAPI
- Defined in:
- lib/proxycrawl/screenshots_api.rb
Constant Summary collapse
- INVALID_SAVE_TO_PATH_FILENAME =
'Filename must end with .jpg or .jpeg'- SAVE_TO_PATH_FILENAME_PATTERN =
/.+\.(jpg|JPG|jpeg|JPEG)$/.freeze
Constants inherited from API
API::INVALID_TOKEN, API::INVALID_URL
Instance Attribute Summary collapse
-
#remaining_requests ⇒ Object
readonly
Returns the value of attribute remaining_requests.
-
#screenshot_path ⇒ Object
readonly
Returns the value of attribute screenshot_path.
-
#screenshot_url ⇒ Object
readonly
Returns the value of attribute screenshot_url.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Attributes inherited from API
#body, #original_status, #pc_status, #status_code, #storage_url, #timeout, #token, #url
Instance Method Summary collapse
Methods inherited from API
Constructor Details
This class inherits a constructor from ProxyCrawl::API
Instance Attribute Details
#remaining_requests ⇒ Object (readonly)
Returns the value of attribute remaining_requests.
8 9 10 |
# File 'lib/proxycrawl/screenshots_api.rb', line 8 def remaining_requests @remaining_requests end |
#screenshot_path ⇒ Object (readonly)
Returns the value of attribute screenshot_path.
8 9 10 |
# File 'lib/proxycrawl/screenshots_api.rb', line 8 def screenshot_path @screenshot_path end |
#screenshot_url ⇒ Object (readonly)
Returns the value of attribute screenshot_url.
8 9 10 |
# File 'lib/proxycrawl/screenshots_api.rb', line 8 def screenshot_url @screenshot_url end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
8 9 10 |
# File 'lib/proxycrawl/screenshots_api.rb', line 8 def success @success end |
Instance Method Details
#get(url, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/proxycrawl/screenshots_api.rb', line 17 def get(url, = {}) screenshot_path = .delete(:save_to_path) || generate_file_path raise INVALID_SAVE_TO_PATH_FILENAME unless SAVE_TO_PATH_FILENAME_PATTERN =~ screenshot_path response = super(url, ) file = File.open(screenshot_path, 'w+') file.write(response.body&.force_encoding('UTF-8')) @screenshot_path = screenshot_path yield(file) if block_given? response ensure file&.close end |
#post ⇒ Object
13 14 15 |
# File 'lib/proxycrawl/screenshots_api.rb', line 13 def post raise 'Only GET is allowed for the ScreenshotsAPI' end |