Class: IGeTui::Validate

Inherits:
Object
  • Object
show all
Defined in:
lib/igetui/validate.rb

Instance Method Summary collapse

Instance Method Details

#get_payload(args = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/igetui/validate.rb', line 13

def get_payload(args = {})
  apnsMap = Hash.new

  sound = "default" unless validate_length(args, :sound)
  apnsMap["sound"] = args[:sound]

  alertMap = Hash.new
  if validate_length(args, :launch_image)
    alertMap["launch-image"] = args[:launch_image]
  end

  if validate_length(args, :loc_key)
    alertMap["loc-key"] = args[:loc_key]
    if validate_length(args, :loc_args)
      alertMap["loc-args"] = args[:loc_args].split(", ")
    end
  elsif validate_length(nil, message)
    alertMap["body"] = message
  end

  apnsMap["alert"] = alertMap
  if validate_length(args, :action_loc_key)
    apnsMap["action-loc-key"] = args[:action_loc_key]
  end

  apnsMap["badge"] = badge

  h = Hash.new
  h["aps"] = apnsMap
  h["payload"] = payload if validate_length(nil, payload)

  return h
end

#validate(args = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/igetui/validate.rb', line 4

def validate(args = {})
  payload_map = get_payload(args)

  json = JSON.generate payload_map
  if (json.length > 256)
    raise ArgumentError.new("PushInfo length over limit: #{json.length}. Allowed: 256.")
  end
end