Class: JPush::Schedule::Trigger

Inherits:
Object
  • Object
show all
Extended by:
Helper::ArgumentHelper
Defined in:
lib/jpush/schedule/trigger.rb

Constant Summary collapse

TIME_UNIT =
['MONTH', 'WEEK', 'DAY']
WEEK =
['MON','TUE','WED','THU','FRI','SAT','SUN']
MDAY =
('01'..'31').to_a

Constants included from Helper::ArgumentHelper

Helper::ArgumentHelper::MAX_ALIAS_ARRAY_SIZE, Helper::ArgumentHelper::MAX_MSG_IDS_ARRAY_SIZE, Helper::ArgumentHelper::MAX_REGISTRATION_ID_ARRAY_SIZE, Helper::ArgumentHelper::MAX_TAG_ARRAY_MAX_BYTESIZE, Helper::ArgumentHelper::MAX_TAG_ARRAY_SZIE

Constants included from Helper::Argument

Helper::Argument::MAX_ALIAS_BYTESIZE, Helper::Argument::MAX_TAG_BYTESIZE, Helper::Argument::MOBILE_RE

Instance Method Summary collapse

Methods included from Helper::ArgumentHelper

build_alias, build_extras, build_msg_ids, build_platform, build_registration_ids, build_tags, extended

Methods included from Helper::Argument

#check_alias, #check_mobile, #check_platform, #check_registration_id, #check_tag, #ensure_argument_not_blank, #ensure_argument_required, #ensure_not_over_bytesize, #ensure_not_over_size, #ensure_word_valid

Instance Method Details

#set_periodical(start_time, end_time, time, time_unit, frequency, point) ⇒ Object



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

def set_periodical(start_time, end_time, time, time_unit, frequency, point)
  @single = nil
  raise Utils::Exceptions::InvalidElementError.new('time unit', time_unit, TIME_UNIT) unless TIME_UNIT.include?(time_unit.upcase)
  require 'time'
  frequency = 100 if frequency > 100
  @periodical = {
    start: start_time.strftime('%F %T'),
    end: end_time.strftime('%F %T'),
    time: Time.parse(time).strftime('%T'),
    time_unit: time_unit,
    frequency: frequency,
    point: build_point(time_unit, point)
  }
  self
end

#set_single(time) ⇒ Object



13
14
15
16
17
# File 'lib/jpush/schedule/trigger.rb', line 13

def set_single(time)
  @periodical = nil
  @single = { time: time.strftime('%F %T') }
  self
end

#to_hashObject



35
36
37
38
39
40
41
42
# File 'lib/jpush/schedule/trigger.rb', line 35

def to_hash
  @trigger = {
    single: @single,
    periodical: @periodical
  }.compact
  raise Utils::Exceptions::JPushError, 'Trigger can not be empty.' if @trigger.empty?
  @trigger
end