Sha256: 06b0b00497086614ee7dee96406b6064c8b63a0b217d2990e28655ea955c2e47

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

class Pupil
  def lookup(opts, option={})
    target, source = opts.to_a.first
    case target
    when :users
      users = Array.new
      source.each_slice(100) do |sliced|
        response = self.get("/1/users/lookup.json", {guess_parameter(sliced[0]) => sliced.join(",")}.update(option))
        return false unless response
        response.each do |element|
          user = User.new(element, @access_token)
          users << user
        end
      end
      
      return users
    when :friendships
      fs = Array.new
      source.each_slice(100) do |sliced|
        response = self.get("/1/friendships/lookup.json", {guess_parameter(sliced[0]) => sliced.join(",")}.update(option))
        return false unless response

        response.each do |element|
          fs << element
        end
      end
      
      return fs
    else
      raise ArgumentError, "#{target} is invalid parameter"
    end
  end
  
  def method_missing(action, *args)
    puts "miss"
    # e.g. pupil.users_search("username", :method => :post)
    url = "/1/#{action.to_s.split('_').join('/')}.json"
    response = self.get(url, args)
    return response
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupil-0.5 lib/pupil/general.rb