Sha256: 39c38249b515a70f10b80c90d6a7403ad5f48170f62c362112c5fd30a870a98b

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

require 'tempfile'

module Landable
  class ScreenshotService
    class Error < StandardError; end

    class << self
      def capture(url)
        if !Landable.configuration.publicist_url
          Rails.logger.warn "Couldn't generate screenshot for #{url}; no Landable.configuration.publicist_url configured"
        else
          screenshots_uri = URI(Landable.configuration.publicist_url)
          screenshots_uri.path = '/api/services/screenshots'

          response = Net::HTTP.post_form screenshots_uri, 'screenshot[url]' => url

          if response.code == '200'
            file = Tempfile.new ['screenshot-', '.png']
            file.binmode
            file.write response.body
            file.rewind

            file
          else
            fail Error, "Received #{response.code} back from #{screenshots_uri}"
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
landable-1.14.0 app/services/landable/screenshot_service.rb
landable-1.13.2 app/services/landable/screenshot_service.rb