Sha256: 2fbef6faa9da220d450012af593a1a7955fb5f77dd678679d0c3a6bd9e481809
Contents?: true
Size: 1.08 KB
Versions: 16
Compression:
Stored size: 1.08 KB
Contents
module VkontakteApi # An API method. It is responsible for generating it's full name and determining it's type. class Method include Resolvable # A pattern for names of methods with a boolean result. PREDICATE_NAMES = /^is.*\?$/ # Calling the API method. # It delegates the network request to `API.call` and result processing to `Result.process`. # @param [Hash] args Arguments for the API method. def call(args = {}, &block) response = API.call(full_name, args, token) Result.process(response, type, block) end private def full_name parts = [@previous_resolver.name, @name].compact.map { |part| camelize(part) } parts.join('.').gsub(/[^A-Za-z.]/, '') end def type @name =~ PREDICATE_NAMES ? :boolean : :anything end # camelize('get_profiles') # => 'getProfiles' def camelize(name) words = name.split('_') first_word = words.shift words.each do |word| word.sub!(/^[a-z]/, &:upcase) end words.unshift(first_word).join end end end
Version data entries
16 entries across 16 versions & 1 rubygems