module Tend::Util::Util::ClassMethods

Public Instance Methods

fill_collection(response, cla) click to toggle source
# File lib/tend/util/util.rb, line 6
def fill_collection response, cla
  collection = Tend::Collection.new
  collection.init response[:paginator]
  response[:data].each { |object| collection << cla.new(object) }
  collection
end

Private Instance Methods

extract_options(options = {}) click to toggle source
# File lib/tend/util/util.rb, line 14
def extract_options options = {}
  o = OpenStruct.new({
    page:           options[:page] || 1,
    user_name:      options[:user_name] || Tend.user_name,
    password:       options[:password] || Tend.password,
    id:             options[:id],
    collection:     options[:collection],
    no_pagination:  options[:no_pagination]
  })
  o.auth ={:username => o.user_name, :password => o.password}
  o
end
uri(options) click to toggle source
# File lib/tend/util/util.rb, line 27
def uri options
  u = "#{Tend::URI}#{self.to_s.gsub("Tend::", "").downcase.pluralize}"
  if options.id
    u += "/#{options.id}"
  end
  if options.collection
    u += "/#{options.collection}" if options.collection
  end
  if !options.no_pagination
    u += "?page=#{options.page}"
  end
  u
end