Sha256: fb159d40a2488a551a26efc7c27bb079347a353cc97b0fa74e7dd2d88c47e4ae

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

require 'sinatra/base'
require 'sinatra/json'

module Photograph
  class Service < ::Sinatra::Base
    helpers Sinatra::JSON

    # Reuse the same browser instance between requests.
    def browser
      @browser ||= Artist.create_browser
    end

    get '/' do
      json :version => Photograph::VERSION
    end

    get '/shoot' do
      artist = Artist.new :url => params["url"],
                          :x   => params["x"].to_i,
                          :y   => params["y"].to_i,
                          :w   => params["w"].to_i,
                          :h   => params["h"].to_i,
                          :wait => params["wait"].to_f,
                          :selector => params["selector"],
                          :browser => browser

      artist.shoot! do |image|
        send_file image.path,
          :type => :png
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
photograph-0.0.4 lib/photograph/service.rb