Sha256: 2c84962828138f1aa2a2e2e040c68a0133f970998ccf17daa718073ac7433a9a

Contents?: true

Size: 896 Bytes

Versions: 14

Compression:

Stored size: 896 Bytes

Contents

require 'tempfile'

module Landable
  class ScreenshotService
    class Error < StandardError; end

    class << self
      def capture url
        if not 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
            raise Error, "Received #{response.code} back from #{screenshots_uri.to_s}"
          end
        end
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
landable-1.13.1 app/services/landable/screenshot_service.rb
landable-1.12.3 app/services/landable/screenshot_service.rb
landable-1.12.2 app/services/landable/screenshot_service.rb
landable-1.12.1 app/services/landable/screenshot_service.rb
landable-1.11.1 app/services/landable/screenshot_service.rb
landable-1.11.0 app/services/landable/screenshot_service.rb
landable-1.10.0.rc2 app/services/landable/screenshot_service.rb
landable-1.10.0.rc1 app/services/landable/screenshot_service.rb
landable-1.9.2 app/services/landable/screenshot_service.rb
landable-1.9.1 app/services/landable/screenshot_service.rb
landable-1.9.0 app/services/landable/screenshot_service.rb
landable-1.9.0.rc2 app/services/landable/screenshot_service.rb
landable-1.9.0.rc1 app/services/landable/screenshot_service.rb
landable-1.8.0 app/services/landable/screenshot_service.rb