Created
March 19, 2019 17:59
-
-
Save almaron/cab161f9e17f3cbb5e5deae8582551b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project::ScreenCaster | |
attr_reader :project | |
PATH_TO_PHANTOM_SCRIPT = Rails.root.join('app','services','project','screen_grab.js') | |
def initialize(project) | |
@project = project | |
end | |
def capture | |
screen_data | |
end | |
def update | |
project.update screen_data: capture | |
end | |
def self.capture(project) | |
new(project).capture | |
end | |
private | |
def screen_data | |
raise StandardError, 'No screen captured' unless phantom_data.present? | |
"data:image/png;,#{phantom_data}" | |
end | |
def phantom_data | |
`#{`which node`.strip} #{PATH_TO_PHANTOM_SCRIPT} #{project.url}`.split("\n")[0] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment