-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkpic.rb
51 lines (40 loc) · 1 KB
/
linkpic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# linkpic.rb
require 'rodent'
require 'selenium-webdriver'
class LinkPic
attr_accessor :name, :email
def initialize(options)
@header_id = options['header_id']
@link = options['link']
@screenshot
end
def say_cheese(options)
width = 1920
height = 1080
driver = Selenium::WebDriver.for :firefox
driver.navigate.to options['link']
driver.execute_script %Q{
window.resizeTo(#{width}, #{height});
}
screenshot = driver.save_screenshot()
driver.quit
end
end
class LinkPicAPI < Rodent::Base
listen 'linkpic.create' do
self.status = 201
@linkpic = LinkPic.new(params)
say_cheese(options['link'])
Url.where("link = ? && "data = nil && header_id ?", params['link','header_id'].update(:data => screenshot)
@linkpic.as_json
end
end
class LinkPicServer < Rodent::Server
configure do
set :connection, 'amqp://guest:guest@localhost'
end
run do
Signal.trap('INT') { Rodent::Server.stop }
[LinkPicAPI]
end
end