Class: LivePaper::Trigger

Inherits:
BaseObject show all
Defined in:
lib/live_paper/trigger.rb

Direct Known Subclasses

QrTrigger, ShortTrigger, WmTrigger

Constant Summary

Constants inherited from BaseObject

BaseObject::AUTH_URL, BaseObject::AUTH_VALIDATION_URL, BaseObject::LP_API_HOST

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#date_created, #date_modified, #id, #link, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObject

#assign_attributes, create, #delete, #errors, get, #initialize, list, #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

#end_dateObject

Returns the value of attribute end_date.



6
7
8
# File 'lib/live_paper/trigger.rb', line 6

def end_date
  @end_date
end

#start_dateObject

Returns the value of attribute start_date.



6
7
8
# File 'lib/live_paper/trigger.rb', line 6

def start_date
  @start_date
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/live_paper/trigger.rb', line 6

def state
  @state
end

Class Method Details

.api_urlObject



8
9
10
# File 'lib/live_paper/trigger.rb', line 8

def self.api_url
  "#{LP_API_HOST}/api/v2/projects/#{$project_id}/triggers"
end

.item_keyObject



12
13
14
# File 'lib/live_paper/trigger.rb', line 12

def self.item_key
  :trigger
end

.list_keyObject



16
17
18
# File 'lib/live_paper/trigger.rb', line 16

def self.list_key
  :triggers
end

.parse(data_in) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/live_paper/trigger.rb', line 20

def self.parse(data_in)
  data = JSON.parse(data_in, symbolize_names: true)[item_key]
  trigger_class = case data[:type]
    when "shorturl"
      ShortTrigger
    when "qrcode"
      QrTrigger
    when "watermark"
      WmTrigger
    else
      raise "UnsupportedTriggerType"
  end
  trigger_class.new.parse(data_in)
end

Instance Method Details

#default_end_dateObject



39
40
41
# File 'lib/live_paper/trigger.rb', line 39

def default_end_date
  Time.now.advance(years: 1).to_s(:live_paper_date_format)
end

#default_start_dateObject



35
36
37
# File 'lib/live_paper/trigger.rb', line 35

def default_start_date
  Time.now.to_s(:live_paper_date_format)
end