module Restcomm::REST::Utils
Public Instance Methods
derestify(something)
click to toggle source
# File lib/restcomm-ruby/rest/utils.rb 13 def derestify(something) 14 return key_map(something, :derestify) if something.is_a? Hash 15 string = something.to_s 16 string = string[0,1].downcase + string[1..-1] 17 string.gsub(/[A-Z][a-z]*/) { |s| "_#{s.downcase}" } 18 end
restify(something)
click to toggle source
# File lib/restcomm-ruby/rest/utils.rb 5 def restify(something) 6 return key_map(something, :restify) if something.is_a? Hash 7 string = something.to_s 8 string.split('_').map do |string_part| 9 string_part[0,1].capitalize + string_part[1..-1] 10 end.join 11 end
Protected Instance Methods
resource(*resources)
click to toggle source
# File lib/restcomm-ruby/rest/utils.rb 22 def resource(*resources) 23 custom_resource_names = { sms: 'SMS', sip: 'SIP' } 24 resources.each do |r| 25 resource = restify r 26 relative_path = custom_resource_names.fetch(r, resource) 27 path = "#{@path}/#{relative_path}" 28 enclosing_module = if @submodule == nil 29 Restcomm::REST 30 else 31 Restcomm::REST.const_get(@submodule) 32 end 33 resource_class = enclosing_module.const_get resource 34 instance_variable_set("@#{r}", resource_class.new(path, @client)) 35 end 36 self.class.instance_eval { attr_reader *resources } 37 end
Private Instance Methods
key_map(something, method)
click to toggle source
# File lib/restcomm-ruby/rest/utils.rb 41 def key_map(something, method) 42 something = something.to_a.flat_map do |pair| 43 [send(method, pair[0]).to_sym, pair[1]] 44 end 45 Hash[*something] 46 end