Class: LivePaper::Image

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

Constant Summary collapse

API_URL =
'https://storage.livepaperapi.com/objects/v1/files'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/live_paper/image.rb', line 7

def url
  @url
end

Class Method Details

.upload(img) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/live_paper/image.rb', line 11

def self.upload(img)
  # return the original img uri if it is LivePaper storage
  if img.include? API_URL
    return img
  end
  begin
    src_image = RestClient.get(img, Accept: 'image/jpg')
    request_access_token unless @access_token
    response = RestClient.post API_URL,
                               src_image.body,
                               Authorization: "Bearer #{@access_token}",
                               content_type: 'image/jpg'
    response.headers[:location]
  rescue Exception => e
    puts "Exception! ******\n#{e}"
    img
  end
end