module Urbanairship::Common

Features mixed in to all classes

Constants

CONTENT_TYPE

Public Instance Methods

apid_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 9
def apid_path(path='')
  "/apids/#{path}"
end
channel_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 13
def channel_path(path='')
  "/channels/#{path}"
end
compact_helper(a_hash) click to toggle source

Helper method that deletes every key-value pair from a hash for which the value is nil @example

compact_helper({"a" => 1, "b" => nil})

>> {"a" => 1}
# File lib/urbanairship/common.rb, line 101
def compact_helper(a_hash)
  a_hash.keep_if {|_, value| !value.nil?}
end
create_and_send_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 17
def create_and_send_path(path='')
  "/create-and-send/#{path}"
end
custom_events_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 21
def custom_events_path(path='')
  "/custom-events/#{path}"
end
device_token_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 25
def device_token_path(path='')
  "/device_tokens/#{path}"
end
experiments_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 29
def experiments_path(path='')
  "/experiments/#{path}"
end
lists_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 33
def lists_path(path='')
  "/lists/#{path}"
end
location_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 37
def location_path(path='')
  "/location/#{path}"
end
named_users_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 41
def named_users_path(path='')
  "/named_users/#{path}"
end
open_channel_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 45
def open_channel_path(path='')
  "/open/#{path}"
end
pipelines_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 49
def pipelines_path(path='')
  "/pipelines/#{path}"
end
push_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 53
def push_path(path='')
  "/push/#{path}"
end
reports_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 57
def reports_path(path='')
  "/reports/#{path}"
end
required(arg=nil) click to toggle source

Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+ @example

def say(greeting: required('greeting'))
  puts greeting
end

>> say
>> test.rb:3:in `required': required parameter :greeting not passed to method say (ArgumentError)
>>       from test.rb:6:in `say'
>>       from test.rb:18:in `<main>'

@param [Object] arg optional argument name

# File lib/urbanairship/common.rb, line 80
def required(arg=nil)
  method = caller_locations(1,1)[0].label
  raise ArgumentError.new("required parameter #{arg.to_sym.inspect + ' ' if arg}not passed to method #{method}")
end
schedules_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 61
def schedules_path(path='')
  "/schedules/#{path}"
end
segments_path(path='') click to toggle source
# File lib/urbanairship/common.rb, line 65
def segments_path(path='')
  "/segments/#{path}"
end
try_helper(method, obj) click to toggle source

Helper method that sends the indicated method to the indicated object, if the object responds to the method @example

try_helper(:first, [1,2,3])

>> 1
# File lib/urbanairship/common.rb, line 90
def try_helper(method, obj)
  if obj.respond_to?(method)
    obj.send(method)
  end
end