Class: LivePaper::Image
- Inherits:
-
Object
- Object
- LivePaper::Image
- Defined in:
- lib/live_paper/image.rb
Constant Summary collapse
- API_URL =
'https://storage.livepaperapi.com/objects/v2/projects/PROJECTID/files'
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Attribute Details
#url ⇒ Object
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(image_uri) ⇒ Object
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 |
# File 'lib/live_paper/image.rb', line 11 def self.upload(image_uri) # return the original img uri if it is LivePaper storage if image_uri.include? API_URL return image_uri end image_bytes = case when image_uri.include?('http://') || image_uri.include?('https://') RestClient.get(image_uri, Accept: 'image/jpg').body else File.binread(image_uri) end BaseObject.request_access_token unless $lpp_access_token BaseObject.request_project_id unless $project_id begin response = RestClient.post API_URL.gsub(/PROJECTID/,$project_id), image_bytes, authorization: "Bearer #{$lpp_access_token}", content_type: 'image/jpeg', accept: '*/*' rescue Exception => e puts e. end response.headers[:location] end |