Class: LivePaper::LivePaperSession

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

Instance Method Summary collapse

Constructor Details

#initialize(auth) ⇒ LivePaperSession

Returns a new instance of LivePaperSession.



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

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



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

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



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

def resources
  @remote_resources
end

#shorten(dest) ⇒ Object



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

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


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

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

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

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

#watermark_bytes(dest, image_url) ⇒ Object



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

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