class MyBitcasa::List

Constants

DOCUMENTS
EVERYTHING
MUSIC
MUSIC_ALBUMS
MUSIC_ARTISTS
PHOTOS
TYPES
VIDEOS

Attributes

bottom[RW]
seamless[RW]
sort_ascending[RW]
sort_column[RW]
top[RW]
type[RW]

Public Class Methods

new(type: EVERYTHING, search: nil, top: 0, bottom: 500, sort_column: :name, sort_ascending: true, seamless: true) click to toggle source
# File lib/my_bitcasa/list.rb, line 27
def initialize(type: EVERYTHING, search: nil, top: 0, bottom: 500, sort_column: :name, sort_ascending: true, seamless: true)
  raise "type error: #{type}" unless TYPES.include?(type)

  @type = type
  @search = search
  @top = top
  @bottom = bottom
  @sort_column = sort_column
  @sort_ascending = sort_ascending
  @seamless = seamless
end

Public Instance Methods

each() { |create| ... } click to toggle source
# File lib/my_bitcasa/list.rb, line 39
def each
  top = @top

  begin
    res = connection.get {|req|
      req.url "/list/#{@type}"
      req.params = {
        search: @search,
        top: top,
        bottom: @bottom,
        sort_column: @sort_column,
        sort_ascending: @sort_ascending,
      }
    }

    sentinel = res.body["sentinel"]
    length = res.body["length"]
    top = res.body["range"]["top"]
    bottom = res.body["range"]["bottom"]
    name = res.body["name"]
    items = res.body["items"]

    items.each do |item|
      yield BitcasaItem.create(item)
    end

    if length<=bottom
      break
    end
  end while @seamless
end