Class: LivePaper::WmTrigger
- Inherits:
-
Trigger
- Object
- BaseObject
- Trigger
- LivePaper::WmTrigger
- Defined in:
- lib/live_paper/wm_trigger.rb
Constant Summary collapse
- WATERMARK_RESOLUTION =
75
- WATERMARK_STRENGTH =
10
- DEFAULT_IMAGE_RESOLUTION =
72
Constants inherited from BaseObject
BaseObject::AUTH_URL, BaseObject::AUTH_VALIDATION_URL, BaseObject::LP_API_HOST
Instance Attribute Summary collapse
-
#wm_url ⇒ Object
Returns the value of attribute wm_url.
Attributes inherited from Trigger
#end_date, #start_date, #state
Attributes inherited from BaseObject
#date_created, #date_modified, #id, #link, #name
Instance Method Summary collapse
Methods inherited from Trigger
api_url, #default_end_date, #default_start_date, item_key, list_key, parse
Methods inherited from BaseObject
api_url, #assign_attributes, create, #delete, #errors, get, #initialize, item_key, list, list_key, parse, #rel, request_access_token, request_project_id, rest_request, #save, #update
Constructor Details
This class inherits a constructor from LivePaper::BaseObject
Instance Attribute Details
#wm_url ⇒ Object
Returns the value of attribute wm_url.
6 7 8 |
# File 'lib/live_paper/wm_trigger.rb', line 6 def wm_url @wm_url end |
Instance Method Details
#download_watermark(image_url, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/live_paper/wm_trigger.rb', line 18 def download_watermark(image_url, = {}) wpi = [:wpi] || WATERMARK_RESOLUTION strength = [:strength] || WATERMARK_STRENGTH ppi = [:ppi] if ppi.blank? image = MiniMagick::Image.open(image_url + "?access_token=" + $lpp_access_token) ppiArray = image.resolution("PixelsPerInch") #This returns the [xResolution, yResolution] ppi = ppiArray[0] if (ppiArray.present? && ppiArray.length > 0) end if ppi.blank? ppi = DEFAULT_IMAGE_RESOLUTION end url = "#{self.wm_url}?imageURL=#{CGI.escape(image_url)}&wpi=#{wpi}&ppi=#{ppi}&strength=#{strength}" begin response = WmTrigger.rest_request( url, :get, accept: "image/jpg" ) response.body.empty? ? nil : response.body rescue Exception => e puts "Exception : #{e.to_s}\n" end end |
#parse(data) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/live_paper/wm_trigger.rb', line 11 def parse(data) data = JSON.parse(data, symbolize_names: true)[:trigger] assign_attributes data self.wm_url=data[:link].select { |item| item[:rel] == "download" }.first[:href] self end |