Class: LivePaper::LivePaperSession

Inherits:
Object
  • Object
show all
Defined in:
lib/live_paper.rb

Instance Method Summary collapse

Constructor Details

#initialize(auth) ⇒ LivePaperSession



24
25
26
27
28
# File 'lib/live_paper.rb', line 24

def initialize(auth)
  #todo: tdd, verify hash
  $lpp_basic_auth = Base64.strict_encode64("#{auth[:id]}:#{auth[:secret]}")
  @remote_resources={}
end

Instance Method Details

#qr_bytes(dest) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/live_paper.rb', line 58

def qr_bytes(dest)
  t=QrTrigger.create(name: 'QR code trigger')
  p=Payoff.create(name: 'name', type: Payoff::TYPE[:WEB], url: dest)
  l=Link.create(payoff_id: p.id, trigger_id: t.id, name: "link")
  @remote_resources={link: l, payoff: p, trigger: t}
  t.download_qrcode
end

#resourcesObject



30
31
32
# File 'lib/live_paper.rb', line 30

def resources
  @remote_resources
end

#shorten(dest) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/live_paper.rb', line 50

def shorten(dest)
  t=ShortTrigger.create(name: 'short trigger')
  p=Payoff.create(name: 'name', type: Payoff::TYPE[:WEB], url: dest)
  l=Link.create(payoff_id: p.id, trigger_id: t.id, name: "link")
  @remote_resources={link: l, payoff: p, trigger: t}
  t.short_url
end


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/live_paper.rb', line 34

def smart_link(dest, image=nil)
  uber = {}
  uber[:short] = shorten dest

  qr_data = qr_bytes dest
  File.open("uber-qr.png", "w") { |f| f.write(qr_data) }
  uber[:qr] = "./uber-qr.png"

  if image
    wm_bytes = watermark_bytes(dest, image)
    File.open("uber-wm.jpg", "w") { |f| f.write(wm_bytes) }
    uber[:wm] = 'uber-wm.jpg'
  end
  uber
end

#watermark_bytes(dest, image_url) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/live_paper.rb', line 66

def watermark_bytes(dest, image_url)
  image = Image.upload image_url

  t=WmTrigger.create(name: 'watermark', watermark: {strength: 10, resolution: 75, imageURL: image})
  p=Payoff.create(name: 'name', type: Payoff::TYPE[:WEB], url: dest)
  l=Link.create(payoff_id: p.id, trigger_id: t.id, name: "link")
  @remote_resources={link: l, payoff: p, trigger: t}
  t.download_watermark
rescue Exception => e
  puts "Exception!"
  puts e.response
end