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.



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

def initialize(auth)
  #todo: tdd, verify hash
  $lpp_basic_auth = Base64.strict_encode64("#{auth[:id]}:#{auth[:secret]}")
  BaseObject::request_access_token
  BaseObject::request_project_id if $lpp_access_token

  @remote_resources={}
end

Instance Method Details

#qr_bytes(dest) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/live_paper.rb', line 61

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



33
34
35
# File 'lib/live_paper.rb', line 33

def resources
  @remote_resources
end

#shorten(dest) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/live_paper.rb', line 53

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


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/live_paper.rb', line 37

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_uri) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/live_paper.rb', line 69

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

  t=WmTrigger.create(name: 'watermark')
  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(image)
rescue Exception => e
  puts "Exception!"
  puts e.response
end