Sha256: 2f2ff118fd18adbf25ecb04d18aa0010adeb0a6fc317de922b95d257500e1489
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 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) # 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pupil-0.6.2 | lib/pupil/general.rb |
pupil-0.6.1 | lib/pupil/general.rb |
pupil-0.6 | lib/pupil/general.rb |