Module: ClashOfClansApi::Utils

Defined in:
lib/clash_of_clans_api/utils.rb

Class Method Summary collapse

Class Method Details

.call_proc_without_unknown_keywords(proc, *args, **kwargs, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/clash_of_clans_api/utils.rb', line 13

def self.call_proc_without_unknown_keywords(proc, *args, **kwargs, &block)
  params = proc.parameters.group_by(&:first).transform_values! do |m|
    m.map do |s|
      s[1]
    end
  end
  
  proc_keys =
    if params.key?(:keyrest)
      kwargs
    else
      kwargs.slice(*(params.values_at(:key, :keyreq).compact.flatten))
    end
  
  proc.call(*args, **proc_keys, &block)
end

.get_current_ipv4_addressObject



30
31
32
# File 'lib/clash_of_clans_api/utils.rb', line 30

def self.get_current_ipv4_address
  IPAddr.new(URI('https://ipv4.icanhazip.com').open.read.strip).to_s
end

.url_escape(string) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/clash_of_clans_api/utils.rb', line 5

def self.url_escape(string)
  if !string.nil?
    CGI.escape(string.to_s)
  else
    raise TypeError, 'cannot escape nil'
  end
end