module TheCity::API::Utils

Private Instance Methods

collection_from_response(collection_name, klass, request_method, path, request_options) click to toggle source

@param collection_name [Symbol] @param klass [Class] @param request_method [Symbol] @param path [String] @param request_options [Hash] @return [TheCity::Collection]

# File lib/the_city/api/utils.rb, line 51
def collection_from_response(collection_name, klass, request_method, path, request_options)
  response = send(request_method.to_sym, path, request_options)
  TheCity::Collection.from_response(response, collection_name.to_sym, klass, self, request_method, path, request_options)
end
object_from_response(klass, request_method, path, request_options={}, options ={}) click to toggle source

@param klass [Class] @param request_method [Symbol] @param path [String] @param request_options [Hash] @param options [Hash] @return [Object]

# File lib/the_city/api/utils.rb, line 40
def object_from_response(klass, request_method, path, request_options={}, options ={})
  response = send(request_method.to_sym, path, request_options)
  klass.from_response(response, options)
end
objects_from_array(klass, array, options={}) click to toggle source

@param klass [Class] @param array [Array] @return [Array]

# File lib/the_city/api/utils.rb, line 28
def objects_from_array(klass, array, options={})
  array.map do |element|
    klass.new(element, options)
  end
end
objects_from_response(klass, request_method, path, request_options={}, options ={}) click to toggle source

@param klass [Class] @param request_method [Symbol] @param path [String] @param request_options [Hash] @param options [Hash] @return [Array]

# File lib/the_city/api/utils.rb, line 20
def objects_from_response(klass, request_method, path, request_options={}, options ={})
  response = send(request_method.to_sym, path, request_options)[:body]
  objects_from_array(klass, response, options)
end